mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add the option in servo-tidy to not check for alphabetical ordering.
This commit is contained in:
parent
226d9a5b0e
commit
29a1617e27
2 changed files with 9 additions and 6 deletions
|
@ -40,6 +40,7 @@ WPT_MANIFEST_PATH = wpt_path("include.ini")
|
||||||
config = {
|
config = {
|
||||||
"skip-check-length": False,
|
"skip-check-length": False,
|
||||||
"skip-check-licenses": False,
|
"skip-check-licenses": False,
|
||||||
|
"check-alphabetical-order": True,
|
||||||
"check-ordered-json-keys": [],
|
"check-ordered-json-keys": [],
|
||||||
"lint-scripts": [],
|
"lint-scripts": [],
|
||||||
"blocked-packages": {},
|
"blocked-packages": {},
|
||||||
|
@ -506,6 +507,7 @@ def check_rust(file_name, lines):
|
||||||
indent = 0
|
indent = 0
|
||||||
prev_indent = 0
|
prev_indent = 0
|
||||||
|
|
||||||
|
check_alphabetical_order = config["check-alphabetical-order"]
|
||||||
decl_message = "{} is not in alphabetical order"
|
decl_message = "{} is not in alphabetical order"
|
||||||
decl_expected = "\n\t\033[93mexpected: {}\033[0m"
|
decl_expected = "\n\t\033[93mexpected: {}\033[0m"
|
||||||
decl_found = "\n\t\033[91mfound: {}\033[0m"
|
decl_found = "\n\t\033[91mfound: {}\033[0m"
|
||||||
|
@ -670,7 +672,7 @@ def check_rust(file_name, lines):
|
||||||
crate_name = line[13:-1]
|
crate_name = line[13:-1]
|
||||||
if indent not in prev_crate:
|
if indent not in prev_crate:
|
||||||
prev_crate[indent] = ""
|
prev_crate[indent] = ""
|
||||||
if prev_crate[indent] > crate_name:
|
if prev_crate[indent] > crate_name and check_alphabetical_order:
|
||||||
yield(idx + 1, decl_message.format("extern crate declaration")
|
yield(idx + 1, decl_message.format("extern crate declaration")
|
||||||
+ decl_expected.format(prev_crate[indent])
|
+ decl_expected.format(prev_crate[indent])
|
||||||
+ decl_found.format(crate_name))
|
+ decl_found.format(crate_name))
|
||||||
|
@ -687,12 +689,12 @@ def check_rust(file_name, lines):
|
||||||
if match:
|
if match:
|
||||||
features = map(lambda w: w.strip(), match.group(1).split(','))
|
features = map(lambda w: w.strip(), match.group(1).split(','))
|
||||||
sorted_features = sorted(features)
|
sorted_features = sorted(features)
|
||||||
if sorted_features != features:
|
if sorted_features != features and check_alphabetical_order:
|
||||||
yield(idx + 1, decl_message.format("feature attribute")
|
yield(idx + 1, decl_message.format("feature attribute")
|
||||||
+ decl_expected.format(tuple(sorted_features))
|
+ decl_expected.format(tuple(sorted_features))
|
||||||
+ decl_found.format(tuple(features)))
|
+ decl_found.format(tuple(features)))
|
||||||
|
|
||||||
if prev_feature_name > sorted_features[0]:
|
if prev_feature_name > sorted_features[0] and check_alphabetical_order:
|
||||||
yield(idx + 1, decl_message.format("feature attribute")
|
yield(idx + 1, decl_message.format("feature attribute")
|
||||||
+ decl_expected.format(prev_feature_name + " after " + sorted_features[0])
|
+ decl_expected.format(prev_feature_name + " after " + sorted_features[0])
|
||||||
+ decl_found.format(prev_feature_name + " before " + sorted_features[0]))
|
+ decl_found.format(prev_feature_name + " before " + sorted_features[0]))
|
||||||
|
@ -717,7 +719,7 @@ def check_rust(file_name, lines):
|
||||||
if prev_use:
|
if prev_use:
|
||||||
current_use_cut = current_use.replace("{self,", ".").replace("{", ".")
|
current_use_cut = current_use.replace("{self,", ".").replace("{", ".")
|
||||||
prev_use_cut = prev_use.replace("{self,", ".").replace("{", ".")
|
prev_use_cut = prev_use.replace("{self,", ".").replace("{", ".")
|
||||||
if indent == current_indent and current_use_cut < prev_use_cut:
|
if indent == current_indent and current_use_cut < prev_use_cut and check_alphabetical_order:
|
||||||
yield(idx + 1, decl_message.format("use statement")
|
yield(idx + 1, decl_message.format("use statement")
|
||||||
+ decl_expected.format(prev_use)
|
+ decl_expected.format(prev_use)
|
||||||
+ decl_found.format(current_use))
|
+ decl_found.format(current_use))
|
||||||
|
@ -743,7 +745,7 @@ def check_rust(file_name, lines):
|
||||||
prev_mod[indent] = ""
|
prev_mod[indent] = ""
|
||||||
if match == -1 and not line.endswith(";"):
|
if match == -1 and not line.endswith(";"):
|
||||||
yield (idx + 1, "mod declaration spans multiple lines")
|
yield (idx + 1, "mod declaration spans multiple lines")
|
||||||
if prev_mod[indent] and mod < prev_mod[indent]:
|
if prev_mod[indent] and mod < prev_mod[indent] and check_alphabetical_order:
|
||||||
yield(idx + 1, decl_message.format("mod declaration")
|
yield(idx + 1, decl_message.format("mod declaration")
|
||||||
+ decl_expected.format(prev_mod[indent])
|
+ decl_expected.format(prev_mod[indent])
|
||||||
+ decl_found.format(mod))
|
+ decl_found.format(mod))
|
||||||
|
@ -760,7 +762,7 @@ def check_rust(file_name, lines):
|
||||||
derives = map(lambda w: w.strip(), match.group(1).split(','))
|
derives = map(lambda w: w.strip(), match.group(1).split(','))
|
||||||
# sort, compare and report
|
# sort, compare and report
|
||||||
sorted_derives = sorted(derives)
|
sorted_derives = sorted(derives)
|
||||||
if sorted_derives != derives:
|
if sorted_derives != derives and check_alphabetical_order:
|
||||||
yield(idx + 1, decl_message.format("derivable traits list")
|
yield(idx + 1, decl_message.format("derivable traits list")
|
||||||
+ decl_expected.format(", ".join(sorted_derives))
|
+ decl_expected.format(", ".join(sorted_derives))
|
||||||
+ decl_found.format(", ".join(derives)))
|
+ decl_found.format(", ".join(derives)))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[configs]
|
[configs]
|
||||||
skip-check-length = false
|
skip-check-length = false
|
||||||
skip-check-licenses = false
|
skip-check-licenses = false
|
||||||
|
check-alphabetical-order = true
|
||||||
check-ordered-json-keys = [
|
check-ordered-json-keys = [
|
||||||
"./resources/prefs.json",
|
"./resources/prefs.json",
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue