Skip to content

run rustfmt on the repository #398(Updated) #438

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

Merged
merged 42 commits into from
Oct 3, 2017
Merged

Conversation

prertik
Copy link
Contributor

@prertik prertik commented Sep 13, 2017

Repository was formatted using rustfmt-nightly. The max_width needed to be increased to remove errors of width being more than the default 120. Some error still persist like:
error: left behind trailing whitespace
---> /mdBook/src/utils/mod.rs:178

and with the fix of code snippets being destroyed from doc comments.

@prertik
Copy link
Contributor Author

prertik commented Sep 13, 2017

@budziq @azerupi how about this one?

@azerupi
Copy link
Contributor

azerupi commented Sep 13, 2017

The tests passed, I will take a look at the output to see if everything is good 👍

@azerupi
Copy link
Contributor

azerupi commented Sep 13, 2017

@prertik I think we should remove the rustfmt.toml file altogether. It was meant for an old version of rustfmt, but it has changed significantly since then and most of the options are probably irrelevant now.

Could I ask you to remove the config file and run rustfmt again? :)

@prertik
Copy link
Contributor Author

prertik commented Sep 14, 2017

Yeah about rustfmt.toml, I had to configure it to pass the test as you can see certain changes. If we remove rustfmt.toml, the rustfmt would operate in default condition which is having max_width:120 which would fail to format mdBook/src/preprocess/links.rs as it has codes with max_width more than 120 and secondly, the problem in previous pull request would again arise i.e. rustfmt by default would again format code snippets in the doc comments. I opened an issue on rustfmt about this, a collaborator told me make changes in the rustfmt.toml file.

@Michael-F-Bryan
Copy link
Contributor

Wouldn't it make more sense to just shorten the overly long lines instead of increasing the max width above 120 characters? If you have a really long string literal, you can break it over a newline by adding a \ to the very end.

Like this:

let some_really_long_string: &'static str = "this is a very long and uninteresting string \ 
  which I've wrapped over multiple lines.";

Also, in doc comments you typically want to wrap them at 80 characters anyway. I know there are one or two examples with really long overhanging lines, but it'd probably be better to either move the comments above or delete them outright if they don't add anything extra to the example... I think uncle bob is quoted as saying, "comments are apologies for badly written code [or poor naming]".

@azerupi
Copy link
Contributor

azerupi commented Sep 15, 2017

Yes, I think it would be better to drop the config file. Resolve the issues with lines being too long and see if the output is acceptable. If the default style works for us, we should embrace it.

@prertik
Copy link
Contributor Author

prertik commented Sep 15, 2017

Thanks @Michael-F-Bryan for the feedback. Alright @azerupi, I will do that. I will send a new pull request and will close this one.

@prertik prertik closed this Sep 15, 2017
@budziq
Copy link
Contributor

budziq commented Sep 15, 2017

@prertik For future reference you can use git rebase and git push --force to completely rewrite the PR without need to close and open another one. Actually, I would suggest to reopen this PR and try this way yourself. If you'll have any problems with git I'll help you 👍 .

@prertik prertik reopened this Sep 15, 2017
@prertik
Copy link
Contributor Author

prertik commented Sep 15, 2017

Thanks @budziq. Actually, i used to do git rebase before. But, in one repo, I ran into some problems due to some merge conflicts which i couldn't solve. So, i ignored it. But, i will definitely try it again. Surely, will ask you for any git help. 👍

@budziq
Copy link
Contributor

budziq commented Sep 20, 2017

The only way to stop rustfmt doing this

And how about setting fn_call_style to visual?
@prertik

@prertik
Copy link
Contributor Author

prertik commented Sep 20, 2017

Yeah, I guess it takes care of the extra line from block(default). But, I think the block has been made default for a reason i.e. being community standard.

@prertik
Copy link
Contributor Author

prertik commented Sep 20, 2017

Shouldn't we follow community standard? In Ruby, community standard is held at highest order.

@budziq
Copy link
Contributor

budziq commented Sep 20, 2017

But, I think the block has been made default for a reason i.e. being community standard.

Be that as it may, but rustftmt.toml facility was also made for a reason ;).

Please note that the rust community standard is in constant flux (4months ago its output on our repo was different and arguably/subjectively nicer).

Ruby, community standard is held at highest order.

It had a little more time to coalesce. Ours is stil wip.

Imho additional 2lines per invocation is just adding noise.
Just my 0.02$ :)

@prertik
Copy link
Contributor Author

prertik commented Sep 20, 2017

So, what should I do @budziq? Should I add rustfmt.toml and redo everything? :(

@budziq
Copy link
Contributor

budziq commented Sep 20, 2017

Should I add rustfmt.toml and redo everything?

If there would be some changes it would not be redoing everything a single run of

find ./src  -iname "*.rs"  | xargs rustfmt

should do the trick (if you're on a nix'y environment)

But anyhow I would wait on a decision from owner 👍

@azerupi
Copy link
Contributor

azerupi commented Sep 20, 2017

and redo everything

Redoing everything should be relatively easy, no? rustfmt comes with a cargo sub-command to run it on the whole crate: cargo fmt.

I agree with everyone that some lines that are expanded would be better left as one line.If we can play with the configuration file and find some options that work better, great! Otherwise, I would be inclined to merge with the options that result in the best formatting and open an issue on rustfmt to give feedback.

@prertik
Copy link
Contributor Author

prertik commented Sep 20, 2017

So, just to be clear, I have to change the fn_call_style to visual by adding rustfmt.toml and then run rustfmt. Is that all?

@Michael-F-Bryan
Copy link
Contributor

See what everything looks like when you tweak fn_call_style and run cargo fmt to reformat the entire project again. Then look at what changed with git diff HEAD and see if the changes seem alright to you.

Personally I don't mind what style we use, the biggest thing for me, and most probably the others, is that hitting save in my editor (I have format-on-save turned on) or running cargo fmt to format the entire project won't pollute PRs with unnecessary code churn.

@prertik
Copy link
Contributor Author

prertik commented Sep 20, 2017

How about I change every indentation to visual rather than block. Looks like everyone prefers visual?
Like here Configurations.md as you can see in chain_indent and others.

@prertik
Copy link
Contributor Author

prertik commented Sep 20, 2017

This looks fine to me. How about you @budziq, @azerupi, @Michael-F-Bryan?

@Michael-F-Bryan
Copy link
Contributor

looks good to me 👍

@prertik
Copy link
Contributor Author

prertik commented Sep 20, 2017

This line format_strings = true is for future. When new lines of code are pushed containing long strings. The strings would be formatted automatically using format_strings otherwise manual formatting needs to be done for the long strings because of max_width error.

@budziq
Copy link
Contributor

budziq commented Sep 20, 2017

👍

(theme_dir.join("ayu-highlight.css"), &mut theme.ayu_highlight_css),
(theme_dir.join("jquery.js"), &mut theme.jquery),
];
let files = vec![(theme_dir.join("index.hbs"), &mut theme.index),
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a little strange.

Copy link
Contributor Author

@prertik prertik Sep 20, 2017

Choose a reason for hiding this comment

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

Oh yeah, about this I made a array_layout = "Visual" in the rustfmt.toml because everyone here seemed to prefer the visual layout rather than the block. I think it looks OK. If you follow the codes from lines 67 to down, it looks structured and having uniform "Visual" layout, I think would be better in this repo as I think it creates a linear structure of codes.

That's my 2 cents on this.

@azerupi
Copy link
Contributor

azerupi commented Sep 20, 2017

I think it's pretty good. There are still a couple of weird edge cases, but we can refine the config later if we find better defaults.

@Michael-F-Bryan Michael-F-Bryan mentioned this pull request Oct 1, 2017
6 tasks
@Michael-F-Bryan
Copy link
Contributor

I think it's pretty good. There are still a couple of weird edge cases, but we can refine the config later if we find better defaults.

@azerupi, does that mean this is good to merge?

@azerupi
Copy link
Contributor

azerupi commented Oct 1, 2017

Yes, I think we can merge this PR. We can still tweak the settings when we discover better defaults.

I wonder if we can find a way to force or encourage the use of rustfmt for PRs. Maybe a pass in Travis? The only problem is that I don't want to block PRs on style, but I do want to make it obvious for us and the author of the PR that rustfmt was not run.

@Michael-F-Bryan
Copy link
Contributor

Hmm... that's hard. Usually I have my editor set up so every time I hit save it'll format the document. Then every now and again you run cargo fmt and cargo clippy to clean things up.

I guess we could periodically make a cargo fmt PR, but that's not exactly ideal...

@prertik
Copy link
Contributor Author

prertik commented Oct 1, 2017

Yeah, I totally agree with @Michael-F-Bryan. Periodically running cargo fmt and using the configuration file present as rustfmt.toml in this repo would be ideal.

@Michael-F-Bryan
Copy link
Contributor

Yes, I think we can merge this PR. We can still tweak the settings when we discover better defaults.

@azerupi, awesome! I'll let you or @budziq hit the big green "merge" button then because I don't have collaborator/owner status.

@budziq budziq merged commit 382fc41 into rust-lang:master Oct 3, 2017
@budziq
Copy link
Contributor

budziq commented Oct 3, 2017

done. Thanks @prertik !

Michael-F-Bryan added a commit to Michael-F-Bryan/mdBook that referenced this pull request Nov 12, 2017
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants