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

Import ordering tidy check confused by multiple use statements from same module #7412

Closed
nox opened this issue Aug 27, 2015 · 14 comments
Closed

Import ordering tidy check confused by multiple use statements from same module #7412

nox opened this issue Aug 27, 2015 · 14 comments
Labels

Comments

@nox
Copy link
Member

@nox nox commented Aug 27, 2015

use url::{Url, UrlParser, SchemeData};
use url::urlutils::{UrlUtils, UrlUtilsWrapper};
./components/script/dom/urlhelper.rs:7: use statement is not in alphabetical order
./components/script/dom/urlhelper.rs:8: use statement is not in alphabetical order

use url::{Url, UrlParser};
use url::SchemeData;
./components/script/dom/urlhelper.rs:9: use statement is not in alphabetical order
./components/script/dom/urlhelper.rs:10: use statement is not in alphabetical order
@jdm
Copy link
Member

@jdm jdm commented Aug 27, 2015

Can this be fixed by reordering the url::{ entries after the others? That would imply that { comes after a-z in alphabetical order.

@nox
Copy link
Member Author

@nox nox commented Aug 27, 2015

Well, that's why I opened the issue, I don't want to reorder it like this.

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Aug 29, 2015

We could have a different sorting function, but I’m not sure that it’s worth it.

@nox
Copy link
Member Author

@nox nox commented Aug 30, 2015

Whether or not it's worth it, I'm not sure a tidy check that is wrong is a good idea.

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Aug 30, 2015

Is it wrong?

@nox
Copy link
Member Author

@nox nox commented Aug 30, 2015

use mod::{foo, bar};
use mod::qux;

I don't see why qux should come before {foo, bar}, it makes no sense.

@tafia
Copy link
Contributor

@tafia tafia commented Sep 2, 2015

I don't see why qux should come before {foo, bar}, it makes no sense.

It doesn't look that wrong to me.
I'd say simpler first for readability. And a {...} does look less simple than one element.
But I don't have any strong opinion on that matter.

@nox
Copy link
Member Author

@nox nox commented Sep 2, 2015

use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, DocumentTypeCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLScriptElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLFormElementDerived, NodeCast};

ProcessingInstructionCast is at an unexpected place.

@nox
Copy link
Member Author

@nox nox commented Sep 2, 2015

@tafia The lint is about alphabetic order of imports, not about simplicity first or whatever.

@nox
Copy link
Member Author

@nox nox commented Sep 2, 2015

qux is after foo and bar in alphabetic order, and thus should come after them, whether there are braces or not.

@nox
Copy link
Member Author

@nox nox commented Sep 2, 2015

Mmmmh… I can't order foo and bar apparently, good thing I found a real-world example.

@bholley
Copy link
Contributor

@bholley bholley commented Oct 20, 2015

Yeah, this is super confusing.

@jdm
Copy link
Member

@jdm jdm commented Jun 7, 2016

One idea from IRC: lowercase the lines before comparing them so use something::a vs use something::A isn't so confusing.

diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index fcf51db..057910e 100644
--- a/python/tidy/servo_tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -430,7 +430,7 @@ def check_rust(file_name, lines):
                 yield (idx + 1, "use statement spans multiple lines")
             # strip "use" from the begin and ";" from the end
             current_use = line[4:-1]
-            if indent == current_indent and prev_use and current_use < prev_use:
+            if indent == current_indent and prev_use and current_use.lower() < prev_use.lower():
                 yield(idx + 1, decl_message.format("use statement")
                       + decl_expected.format(prev_use)
                       + decl_found.format(current_use))

This generates a bunch of tidy warnings that need to be addressed.

@nox
Copy link
Member Author

@nox nox commented Jun 7, 2016

@jdm First time I hear someone complain about this specific part. I'm more annoyed by how braces should come after not-braces.

bors-servo added a commit that referenced this issue Sep 9, 2016
Tidy: Fix ordering use statements with braces

This hack fixes #7412 and matches behavior with rustfmt.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13205)
<!-- Reviewable:end -->
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 1, 2019
…from UK992:tidy-sort); r=Wafflespeanut

This hack fixes servo/servo#7412 and matches behavior with rustfmt.

Source-Repo: https://github.com/servo/servo
Source-Revision: 3117787fd2a8b7748cfde1e9b8c5be3c00f2c599

UltraBlame original commit: 89bfec936a22ef359e7b65a2deae11ff8f16d7c0
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 1, 2019
…from UK992:tidy-sort); r=Wafflespeanut

This hack fixes servo/servo#7412 and matches behavior with rustfmt.

Source-Repo: https://github.com/servo/servo
Source-Revision: 3117787fd2a8b7748cfde1e9b8c5be3c00f2c599

UltraBlame original commit: 89bfec936a22ef359e7b65a2deae11ff8f16d7c0
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 1, 2019
…from UK992:tidy-sort); r=Wafflespeanut

This hack fixes servo/servo#7412 and matches behavior with rustfmt.

Source-Repo: https://github.com/servo/servo
Source-Revision: 3117787fd2a8b7748cfde1e9b8c5be3c00f2c599

UltraBlame original commit: 89bfec936a22ef359e7b65a2deae11ff8f16d7c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.