Skip to content

Format our code with rustfmt #8553

Closed
Closed

Description

@tetsuharuohzeki

I think we should do this.

Activity

  1. tetsuharuohzeki commented on Nov 16, 2015

    @tetsuharuohzeki
    ContributorAuthor
  2. jdm commented on Nov 16, 2015

    @jdm
    Member

    Ms2ger and I have filed a lot of issues each time we've tried rustfmt on Servo. We could certainly start running it on particular files that don't end up with terrible output.

  3. Manishearth commented on Nov 16, 2015

    @Manishearth
    Member

    It's not ready yet. I periodically try running it on Servo.

  4. frewsxcv commented on Nov 18, 2015

    @frewsxcv
    Contributor

    Anyone know how Go projects incorporate gofmt (or Rust w/ rustfmt) into project workflows? Require that it get used pre-commit and checked via CI? Have the build system automatically format upon check-in (which sounds scary)? Something else?

  5. added
    B-RFC
    I-cleanup
    on Nov 18, 2015
  6. tetsuharuohzeki commented on Nov 18, 2015

    @tetsuharuohzeki
    ContributorAuthor

    I think it would be better to check in CI the commited files as tidy which we're running. It's not enough?

  7. Manishearth commented on Nov 18, 2015

    @Manishearth
    Member

    Checked via CI I think. Similar to how clippy checks update_lints or how servo checks lockfile_changed.

    I'd rather not gate CI on rustfmt though. I'm slightly more okay with it if we use circleci or something for tidy+fmt to get separate and immediate status icons from the long build.

  8. Manishearth commented on Jan 2, 2017

    @Manishearth
    Member

    So I've been poking around, and rustfmt seems to be much more stable now.

    The following toml config is pretty nice for servo

    reorder_imports = true
    reorder_imported_names = true
    max_width = 120
    ideal_width = 80
    normalize_comments = false

    normalize_comments prevents the license comment from being reformatted to use line comments instead of block comments. We might want to do that anyway, but it's nice to reduce the impact of the first run.

    rustfmt currently doesn't reorder extern crates. Furthermore, it reformats #[attr] extern crate foo; into two lines, which breaks tidy (tidy only asks for the sorting of extern crate lines which do not have attributes, since the ones with attributes usually have special requirements for ordering). We'll need to change this a bit and/or add extern crate sorting to rustfmt.

    I would like to reformat everything and slowly make rustfmt part of CI checks. Perhaps removing the corresponding tidy checks.

    Thoughts? @jdm @Ms2ger @Wafflespeanut

  9. jdm commented on Jan 2, 2017

    @jdm
    Member

    I'm open to that plan. I think adding extern crate reordering to rustfmt makes the most sense.

  10. added a commit that references this issue on Jan 3, 2017
  11. added a commit that references this issue on Jan 4, 2018
  12. pyfisch commented on Jan 20, 2018

    @pyfisch
    Contributor

    🎉 rustfmt now works well on servo with this config:

    match_block_trailing_comma = true
    binop_separator = "Back"
    error_on_line_overflow = false
    

    It can be installed with rustup install rustfmt-preview for servo and run with cargo fmt --package layout for individual packages like layout.

    The formatting works with ./mach test-tidy but the long (>100 character) imports need to be formatted by hand.

  13. atouchet commented on Nov 7, 2018

    @atouchet
    Contributor

    Is this done now?

  14. CYBAI commented on Nov 7, 2018

    @CYBAI
    Member

    Done by #22126 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-RFCI-cleanup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions