Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upLint to check alphabetical order of uses, mods & crates #7546
Conversation
|
@Manishearth There are two things left. For now, this only gets the names of |
|
This has the exact same problem as the Python lint, in which import lists aren't checked for sortedness, right? I mean things like: use mod::{foo, bar, qux}; |
|
@nox No, only the individual declarations. I think checking for sortedness in import lists is probably a bad idea, since some of the giant files have a lot of lists and arranging them would be painful :) |
|
If the lint outputs a sorted list to be used, it wouldn't be so bad. But this PR is fine too, we can discuss whether or not to augment the functionality. |
|
Reviewed 3 of 3 files at r1. components/plugins/lints/sorter.rs, line 37 [r1] (raw file): Comments from the review on Reviewable.io |
|
Oh yeah, right. I now remember that we'll be actually suggesting how the stuff should be sorted :) |
2d6109f
to
73a233b
73a233b
to
f4f19e8
|
Now, there's a |
|
You don't need to put r=Manishearth in your commits. Homu will do that in the merge commit |
5d8b319
to
dda0804
|
@Manishearth I'm not sure whether it's pretty, but we have a working lint! ^_^ Here's how crates are checked (same goes for mods)... Here's how use lists are checked (cc @nox)... |
|
This still needs more polishing... |
|
Calling the lint sorted_declarations means that |
|
Yeah, right. That should be |
|
Reviewed 1 of 1 files at r2, 1 of 1 files at r3. components/plugins/lints/sorter.rs, line 34 [r2] (raw file): components/plugins/lints/sorter.rs, line 55 [r2] (raw file): components/plugins/lints/sorter.rs, line 87 [r3] (raw file): Also, components/plugins/lints/sorter.rs, line 93 [r2] (raw file): Something like {} should be in alphabetical order\n\texpected: {}\n\tfound: {} where the first {} is either "use statements", "module declarations", or "crate declarations" Comments from the review on Reviewable.io |
dda0804
to
4ee0c6a
|
Now, all that's left is to sort the declarations in the existing files (which is gonna be a pain!) |
| use syntax::codemap::{Pos, BytePos, Span}; | ||
| use syntax::print::pprust::path_to_string; | ||
|
|
||
| declare_lint!(UNSORTED_DECLARATIONS, Deny, |
This comment has been minimized.
This comment has been minimized.
Manishearth
Sep 17, 2015
Member
This should be Warn. Deny is going to be very annoying when you're fiddling with imports temporarily before checking in.
| let suggestion = format!("use lists should be in alphabetical order!\ | ||
| \n\texpected order of list: {{{}}}\ | ||
| \n\tlist found: {{{}}}", | ||
| new_list.join(", "), old_list.join(", ")); |
This comment has been minimized.
This comment has been minimized.
Manishearth
Sep 17, 2015
Member
Not like this.
Use lists should be in alphabetical order.
try:
use foo::bar::baz::{a,b,c,d};
print out a fully copyable use statement
| if name != new_slice[i] { | ||
| let suggestion = format!("{} should be in alphabetical order!\n\t\ | ||
| expected: {}\n\tfound: {}", | ||
| kind, new_slice[i], name); |
This comment has been minimized.
This comment has been minimized.
4ee0c6a
to
6e18618
|
This is still incomplete. Firstly, I gotta cripple the lint, so that it doesn't walk into Sidenote: I'm still not sure whether this is efficient (I've tried my best), and so, I welcome suggestions :) |
|
Alternatively, we could fix the generated bindings. |
ad3cbbe
to
f417d56
|
This just keeps getting better and better! Now, we gotta filter the additional attributes that come clinging with the mod declarations (for instance, this shows Also, the lint doesn't care about renamed declarations (for now). extern crate foobar as foo // this is interpreted as `extern crate foo`... which should also be fixed as well. |
|
|
ed2e797
to
03a3999
03a3999
to
b064189
|
Alright, tidy doesn't give up. It expects |
|
It seems to me that the main downside of doing this check in a lint vs. in the python script is that we lose the immediate feedback that travis provides, so we won't notice that a PR needs amending until it fails to merge. |
|
@jdm Agreed. Also, since the lint only throws warnings, we can't know whether a PR has merged with warnings. (sigh) after all that work... :/ @Manishearth maybe we should go back to throwing errors! :) |
|
No. No errors. Go does this with unused imports, and it's extremely annoying when this happens while you're developing. So much that a myriad of solutions, ranging from auto-import-fixers to modified compilers have come out. Style lints should not be errors. |
|
Okay, since this lint doesn't fit very well here (nor rustfmt), I've planned to move this elsewhere. I'll just submit a PR for the files (well, I can't just abandon all the work, it's consumed a lot of my time! :P) |
sorted the declarations in various files... This is a direct extract from my abandoned PR for a lint (#7546), along with some rather clumsy modifications (only on `components/script/dom/mod.rs` and `components/style/lib.rs`), because I had to sort some of the files again to make peace with tidy, which hasn't been educated about sorting yet! <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7698) <!-- Reviewable:end -->



wafflespeanut commentedSep 4, 2015
fixes #7451