Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format placeholder code when generating a crate #7827

Commits on Jan 21, 2020

  1. Log entry 1

    Today I learned that `rustfmt` is now a part of `rustup`. So I need
    to actually look it up in PATH instead of using `cargo-fmt`.
    
    I also learned that `mk` is the file that does the main work and is
    shared by `cargo-new` and `cargo-init`, as expected.
    
    Printing inside `mk` produces output as expected.
    Kinrany committed Jan 21, 2020
    Configuration menu
    Copy the full SHA
    6057c93 View commit details
    Browse the repository at this point in the history

Commits on Jan 25, 2020

  1. Log entry 2: first implementation

    I think I found the correct place in the algorithm where rustfmt should
    be called.
    
    I'm not sure if using `std::process::Command` and converting errors into
    warnings is the correct way here.
    
    Also the warning should only be printed once. Unless
    `config.shell().warn()` deduplicates warnings, right now there will be
    one warning per source file.
    
    So I should probably check that `rustfmt` exists only once and disable
    formatting if it doesn't.
    Kinrany committed Jan 25, 2020
    Configuration menu
    Copy the full SHA
    aa7fe99 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f8edf75 View commit details
    Browse the repository at this point in the history

Commits on Jan 26, 2020

  1. Deduplicate warnings about missing rustfmt

    There's now exactly one warning per new crate instead of one per
    source file.
    
    Also warnings are being logged now, not printed to console.
    Kinrany committed Jan 26, 2020
    Configuration menu
    Copy the full SHA
    63cb62d View commit details
    Browse the repository at this point in the history

Commits on Jan 27, 2020

  1. Add tests

    Test 1: init a library crate with a `rustfmt.toml` config file in it.
    Expect the generated source files to be formatted according to the
    config file.
    
    Test 2: same as test 1, but with missing `rustfmt`. Expect `cargo init`
    to ignore the absence of `rustfmt` and generate source files
    with default formatting.
    Kinrany committed Jan 27, 2020
    Configuration menu
    Copy the full SHA
    6baf6bc View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5ab0be0 View commit details
    Browse the repository at this point in the history
  3. Fix tests on Linux/MacOS

    The tests were failing with error:
    "could not determine the current user, please set $USER"
    Kinrany committed Jan 27, 2020
    Configuration menu
    Copy the full SHA
    ea4f53c View commit details
    Browse the repository at this point in the history

Commits on Jan 30, 2020

  1. Log rustfmt output if it fails; also do not check that rustfmt exists

    Worst case is that the logs will have multiple errors caused by missing
    rustfmt, so checking separately that rustfmt exists is unnecessary.
    Kinrany committed Jan 30, 2020
    Configuration menu
    Copy the full SHA
    768b60a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1695b89 View commit details
    Browse the repository at this point in the history

Commits on Feb 4, 2020

  1. Configuration menu
    Copy the full SHA
    a70ac57 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    68a1c78 View commit details
    Browse the repository at this point in the history

Commits on Feb 5, 2020

  1. Do not run formats_source if rustfmt is not available

    Generalized `clippy_is_available` and renamed as `command_is_available`.
    
    No checks in `ignores_failure_to_format_source`, it's not supposed to
    use `rustfmt` even if it's available
    Kinrany committed Feb 5, 2020
    Configuration menu
    Copy the full SHA
    bc4c65c View commit details
    Browse the repository at this point in the history