mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 16:55:40 +00:00
servo: Merge #9055 - Issue #9042: Report incorrect number of spaces around => in the style checker (from simartin:issue_9042); r=Wafflespeanut
Fixes https://github.com/servo/servo/issues/9042 Source-Repo: https://github.com/servo/servo Source-Revision: f77c7928868469ef4f326a269147ae2aee6151ee
This commit is contained in:
parent
2d152878a2
commit
6f8d33fe11
@ -314,6 +314,16 @@ def check_rust(file_name, contents):
|
|||||||
if match:
|
if match:
|
||||||
yield (idx + 1, "missing space after ->")
|
yield (idx + 1, "missing space after ->")
|
||||||
|
|
||||||
|
line_len = len(line)
|
||||||
|
arrow_pos = line.find("=>")
|
||||||
|
if arrow_pos != -1:
|
||||||
|
if arrow_pos and line[arrow_pos - 1] != ' ':
|
||||||
|
yield (idx + 1, "missing space before =>")
|
||||||
|
if arrow_pos + 2 < line_len and line[arrow_pos + 2] != ' ':
|
||||||
|
yield (idx + 1, "missing space after =>")
|
||||||
|
elif arrow_pos + 3 < line_len and line[arrow_pos + 3] == ' ':
|
||||||
|
yield (idx + 1, "extra space after =>")
|
||||||
|
|
||||||
# Avoid flagging ::crate::mod and `trait Foo : Bar`
|
# Avoid flagging ::crate::mod and `trait Foo : Bar`
|
||||||
match = line.find(" :")
|
match = line.find(" :")
|
||||||
if match != -1:
|
if match != -1:
|
||||||
@ -344,7 +354,7 @@ def check_rust(file_name, contents):
|
|||||||
# check extern crates
|
# check extern crates
|
||||||
if line.startswith("extern crate "):
|
if line.startswith("extern crate "):
|
||||||
crate_name = line[len("extern crate "):-1]
|
crate_name = line[len("extern crate "):-1]
|
||||||
indent = len(original_line) - len(line)
|
indent = len(original_line) - line_len
|
||||||
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:
|
||||||
@ -358,7 +368,7 @@ def check_rust(file_name, contents):
|
|||||||
elif 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)
|
indent = len(original_line) - line_len
|
||||||
if not use.endswith(";"):
|
if not use.endswith(";"):
|
||||||
yield (idx + 1, "use statement spans multiple lines")
|
yield (idx + 1, "use statement spans multiple lines")
|
||||||
current_use = use[:len(use) - 1]
|
current_use = use[:len(use) - 1]
|
||||||
@ -378,7 +388,7 @@ 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 "):
|
||||||
indent = len(original_line) - len(line)
|
indent = len(original_line) - line_len
|
||||||
mod = line[4:] if line.startswith("mod ") else line[8:]
|
mod = line[4:] if line.startswith("mod ") else line[8:]
|
||||||
|
|
||||||
if idx < 0 or "#[macro_use]" not in contents[idx - 1]:
|
if idx < 0 or "#[macro_use]" not in contents[idx - 1]:
|
||||||
|
Loading…
Reference in New Issue
Block a user