mirror of
https://github.com/servo/servo.git
synced 2025-07-25 08:10:21 +01:00
Improve checking algorithms
This commit is contained in:
parent
db0a0ac9f6
commit
db3457e498
2 changed files with 53 additions and 49 deletions
|
@ -57,12 +57,12 @@ pub use constellation::Constellation;
|
||||||
|
|
||||||
mod compositor;
|
mod compositor;
|
||||||
mod compositor_layer;
|
mod compositor_layer;
|
||||||
|
pub mod compositor_task;
|
||||||
|
pub mod constellation;
|
||||||
mod headless;
|
mod headless;
|
||||||
|
pub mod pipeline;
|
||||||
|
pub mod sandboxing;
|
||||||
mod scrolling;
|
mod scrolling;
|
||||||
mod surface_map;
|
mod surface_map;
|
||||||
mod timer_scheduler;
|
mod timer_scheduler;
|
||||||
pub mod compositor_task;
|
|
||||||
pub mod constellation;
|
|
||||||
pub mod pipeline;
|
|
||||||
pub mod sandboxing;
|
|
||||||
pub mod windowing;
|
pub mod windowing;
|
||||||
|
|
|
@ -229,27 +229,19 @@ def check_rust(file_name, contents):
|
||||||
import_block = False
|
import_block = False
|
||||||
whitespace = False
|
whitespace = False
|
||||||
|
|
||||||
uses = []
|
prev_use = None
|
||||||
|
current_indent = 0
|
||||||
prev_crate = {}
|
prev_crate = {}
|
||||||
mods = []
|
prev_mod = {}
|
||||||
|
|
||||||
|
decl_message = "{} is not in alphabetical order"
|
||||||
|
decl_expected = "\n\t\033[93mexpected: {}\033[0m"
|
||||||
|
decl_found = "\n\t\033[91mfound: {}\033[0m"
|
||||||
|
|
||||||
for idx, original_line in enumerate(contents):
|
for idx, original_line in enumerate(contents):
|
||||||
# simplify the analysis
|
# simplify the analysis
|
||||||
line = original_line.strip()
|
line = original_line.strip()
|
||||||
|
|
||||||
# check extern crates
|
|
||||||
if line.startswith("extern crate"):
|
|
||||||
crate_name = line.replace("extern crate ", "").replace(";", "")
|
|
||||||
indent = len(original_line) - len(line)
|
|
||||||
if indent not in prev_crate:
|
|
||||||
prev_crate[indent] = ""
|
|
||||||
if prev_crate[indent] > crate_name:
|
|
||||||
message = "extern crate statement is not in alphabetical order"
|
|
||||||
expected = "\n\t\033[93mexpected: {}\033[0m".format(prev_crate[indent])
|
|
||||||
found = "\n\t\033[91mfound: {}\033[0m".format(crate_name)
|
|
||||||
yield(idx + 1, message + expected + found)
|
|
||||||
prev_crate[indent] = crate_name
|
|
||||||
|
|
||||||
# Simple heuristic to avoid common case of no comments.
|
# Simple heuristic to avoid common case of no comments.
|
||||||
if '/' in line:
|
if '/' in line:
|
||||||
comment_depth += line.count('/*')
|
comment_depth += line.count('/*')
|
||||||
|
@ -342,23 +334,36 @@ def check_rust(file_name, contents):
|
||||||
if match and not (line.startswith("use") or line.startswith("pub use")):
|
if match and not (line.startswith("use") or line.startswith("pub use")):
|
||||||
yield (idx + 1, "missing space after {")
|
yield (idx + 1, "missing space after {")
|
||||||
|
|
||||||
|
# check extern crates
|
||||||
|
if line.startswith("extern crate "):
|
||||||
|
crate_name = line[len("extern crate "):-1]
|
||||||
|
indent = len(original_line) - len(line)
|
||||||
|
if indent not in prev_crate:
|
||||||
|
prev_crate[indent] = ""
|
||||||
|
if prev_crate[indent] > crate_name:
|
||||||
|
yield(idx + 1, decl_message.format("extern crate declaration")
|
||||||
|
+ decl_expected.format(prev_crate[indent])
|
||||||
|
+ decl_found.format(crate_name))
|
||||||
|
prev_crate[indent] = crate_name
|
||||||
|
|
||||||
# imports must be in the same line, alphabetically sorted, and merged
|
# imports must be in the same line, alphabetically sorted, and merged
|
||||||
# into a single import block
|
# into a single import block
|
||||||
if line.startswith("use "):
|
elif line.startswith("use "):
|
||||||
import_block = True
|
import_block = True
|
||||||
use = line[4:]
|
use = line[4:]
|
||||||
|
indent = len(original_line) - len(line)
|
||||||
if not use.endswith(";"):
|
if not use.endswith(";"):
|
||||||
yield (idx + 1, "use statement spans multiple lines")
|
yield (idx + 1, "use statement spans multiple lines")
|
||||||
uses.append((use[:len(use) - 1], idx + 1))
|
current_use = use[:len(use) - 1]
|
||||||
elif len(uses) > 0 and whitespace or not import_block:
|
if indent == current_indent and prev_use and current_use < prev_use:
|
||||||
sorted_uses = sorted(uses)
|
yield(idx + 1, decl_message.format("use statement")
|
||||||
for i in range(len(uses)):
|
+ decl_expected.format(prev_use)
|
||||||
if sorted_uses[i][0] != uses[i][0]:
|
+ decl_found.format(current_use))
|
||||||
message = "use statement is not in alphabetical order"
|
prev_use = current_use
|
||||||
expected = "\n\t\033[93mexpected: {}\033[0m".format(sorted_uses[i][0])
|
current_indent = indent
|
||||||
found = "\n\t\033[91mfound: {}\033[0m".format(uses[i][0])
|
|
||||||
yield(uses[i][1], message + expected + found)
|
if whitespace or not import_block:
|
||||||
uses = []
|
current_indent = 0
|
||||||
|
|
||||||
if import_block and whitespace and line.startswith("use "):
|
if import_block and whitespace and line.startswith("use "):
|
||||||
whitespace = False
|
whitespace = False
|
||||||
|
@ -366,26 +371,24 @@ def check_rust(file_name, contents):
|
||||||
|
|
||||||
# modules must be in the same line and alphabetically sorted
|
# modules must be in the same line and alphabetically sorted
|
||||||
if line.startswith("mod ") or line.startswith("pub mod "):
|
if line.startswith("mod ") or line.startswith("pub mod "):
|
||||||
mod = ""
|
indent = len(original_line) - len(line)
|
||||||
if line.startswith("mod "):
|
mod = line[4:] if line.startswith("mod ") else line[8:]
|
||||||
mod = line[4:]
|
|
||||||
else:
|
|
||||||
mod = line[8:]
|
|
||||||
|
|
||||||
match = line.find(" {")
|
if idx < 0 or "#[macro_use]" not in contents[idx - 1]:
|
||||||
if match == -1:
|
match = line.find(" {")
|
||||||
if not mod.endswith(";"):
|
if indent not in prev_mod:
|
||||||
yield (idx + 1, "mod statement spans multiple lines")
|
prev_mod[indent] = ""
|
||||||
mods.append(mod[:len(mod) - 1])
|
if match == -1 and not mod.endswith(";"):
|
||||||
elif len(mods) > 0:
|
yield (idx + 1, "mod declaration spans multiple lines")
|
||||||
sorted_mods = sorted(mods)
|
mod = mod[:len(mod) - 1]
|
||||||
for i in range(len(mods)):
|
if len(prev_mod[indent]) > 0 and mod < prev_mod[indent]:
|
||||||
if sorted_mods[i] != mods[i]:
|
yield(idx + 1, decl_message.format("mod declaration")
|
||||||
message = "mod statement is not in alphabetical order"
|
+ decl_expected.format(prev_mod[indent])
|
||||||
expected = "\n\t\033[93mexpected: {}\033[0m".format(sorted_mods[i])
|
+ decl_found.format(mod))
|
||||||
found = "\n\t\033[91mfound: {}\033[0m".format(mods[i])
|
prev_mod[indent] = mod
|
||||||
yield (idx + 1 - len(mods) + i, message + expected + found)
|
else:
|
||||||
mods = []
|
# we now erase previous entries
|
||||||
|
prev_mod = {}
|
||||||
|
|
||||||
# There should not be any extra pointer dereferencing
|
# There should not be any extra pointer dereferencing
|
||||||
if ": &Vec<" in line:
|
if ": &Vec<" in line:
|
||||||
|
@ -578,6 +581,7 @@ def scan():
|
||||||
wpt_lint_errors = check_wpt_lint_errors()
|
wpt_lint_errors = check_wpt_lint_errors()
|
||||||
|
|
||||||
errors = list(itertools.chain(errors, r_errors, not_found_in_basic_list_errors, wpt_lint_errors))
|
errors = list(itertools.chain(errors, r_errors, not_found_in_basic_list_errors, wpt_lint_errors))
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
for error in errors:
|
for error in errors:
|
||||||
print "\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)
|
print "\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue