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

[DRAFT] Format the rust-lang/rust repository #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Centril
Copy link
Owner

@Centril Centril commented May 5, 2019

Rendered

This is a draft version of an RFC for you to review, before a formal proposal is made for consideration.


We add a command `install-fmt-hook` to rustbuild.
This command will install a pre-commit git-hook.
This git-hook will check that the formatting in the commit is good.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, I think it should format the code before committing, not just check that it's good, right?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure; @matklad requested it so they know best what they wanted. =P

is perfectly good aside from formatting. For these situations, a
`@rustbot fmt` command is provided with which the author, a reviewer,
or a T-release member can simply ask `@rustbot` to run `./x.py fmt`
on their PR and add a commit for that.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know when we'll have the time to implement this, but it seems reasonable.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mark-Simulacrum The one thing I'm wondering is if @rustbot fmt can add commits to the branch of a PR author or not.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely possible, at least in general -- the PR author can untick the relevant checkbox but there's no real reason we need to worry about that. The feature is enabled by default.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Mark.

The command formats the repository according to the style.

4. Add a command `@rustbot fmt` on GitHub which will add a commit to a
pull request (PR) such that the applied to PR will pass CI in terms of the style.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally prefer for this to instead rebase and amend each commit, running rustfmt on the individual commits. I'm not sure if that'll potentially cause conflicts (that we would need to manually resolve); if so then I guess the additional commit is our best bet.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a modifier @rustbot fmt fixup which does that upon request?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force-pushing the branch also means if the user wants to update their local copy they can't do git pull (or equivalents) anymore, which will be confusing for contributors with less git experience.


To facilitate incremental enforcement of the style and to disrupt development
minimally inside the repository, the `tidy` tool will only enforce the style
in folders with an `.enforcefmt` file. In such folders, the style will be

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally prefer a list in tidy itself rather than dozens of these files strewn around the repository, but I don't care too much.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementors prerogative? I was thinking .enforcefmt would be easier for the transition since you can incrementally just "move up" the .enforcefmt file instead of having to fiddle with tidy.

is perfectly good aside from formatting. For these situations, a
`@rustbot fmt` command is provided with which the author, a reviewer,
or a T-release member can simply ask `@rustbot` to run `./x.py fmt`
on their PR and add a commit for that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know when we'll have the time to implement this, but it seems reasonable.


We add a command `install-fmt-hook` to rustbuild.
This command will install a pre-commit git-hook.
This git-hook will check that the formatting in the commit is good.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, I think it should format the code before committing, not just check that it's good, right?


2. Enforce the style with `src/tools/tidy` in the repository's continuous integration (CI).

3. Add a command `fmt` to rustbuild (`./x.py`).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this run as a pre-./x.py build hook (or allow configuring this to be the case)? I'd hate to have to wait for everything to rebuild just because a fmt ran and messed something up really low down.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An opt-in flag to config.toml sound good? I wouldn't make it the default as it may throw around code I'm working on and throw me off when developing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

This style is adopted to make the repository feel idiomatic in terms of style.

However, we make a small modification to the style guide.
In particular, we enable [`use_small_heuristics = "Max"`][small].
Copy link

@cramertj cramertj May 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

FWIW this, newline_style = "Unix", and edition = "2018" are the only rustfmt.toml sections modifications that Fuchsia uses as well.

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

Successfully merging this pull request may close these issues.

4 participants