mirror of
https://github.com/servo/servo.git
synced 2025-08-29 00:58:20 +01:00
tidy: Add a rule ensuring that //
comments are followed by a space in Rust (#38698)
This shows up sometimes in code reviews, so it makes sense that tidy enforces it. `rustfmt` supports this via comment normalization, but it does many other things and is still an unstable feature (with bugs). Testing: There are new tidy tests for this change. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
8ca00a3b0c
commit
8743a11ba4
68 changed files with 169 additions and 152 deletions
|
@ -117,8 +117,11 @@ class CheckTidiness(unittest.TestCase):
|
||||||
|
|
||||||
def test_rust(self):
|
def test_rust(self):
|
||||||
errors = tidy.collect_errors_for_files(iterFile("rust_tidy.rs"), [], [tidy.check_rust], print_text=False)
|
errors = tidy.collect_errors_for_files(iterFile("rust_tidy.rs"), [], [tidy.check_rust], print_text=False)
|
||||||
|
self.assertEqual("Comments starting with `//` should also include a space", next(errors)[2])
|
||||||
self.assertEqual("use &T instead of &Root<T>", next(errors)[2])
|
self.assertEqual("use &T instead of &Root<T>", next(errors)[2])
|
||||||
self.assertEqual("use &T instead of &DomRoot<T>", next(errors)[2])
|
self.assertEqual("use &T instead of &DomRoot<T>", next(errors)[2])
|
||||||
|
self.assertEqual("Comments starting with `//` should also include a space", next(errors)[2])
|
||||||
|
self.assertEqual("Comments starting with `//` should also include a space", next(errors)[2])
|
||||||
self.assertNoMoreErrors(errors)
|
self.assertNoMoreErrors(errors)
|
||||||
|
|
||||||
feature_errors = tidy.collect_errors_for_files(iterFile("lib.rs"), [], [tidy.check_rust], print_text=False)
|
feature_errors = tidy.collect_errors_for_files(iterFile("lib.rs"), [], [tidy.check_rust], print_text=False)
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! This is a module, but this comment shouldn't trigger an error.
|
||||||
|
//* This is also a module doc comment *//
|
||||||
|
//This comment should trigger an error, because of missing space.
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use raqote::{GradientStop, Source, SolidSource};
|
use raqote::{GradientStop, Source, SolidSource};
|
||||||
use raqote::{Source, SolidSource},
|
use raqote::{Source, SolidSource},
|
||||||
|
@ -78,4 +82,11 @@ impl test {
|
||||||
} else {
|
} else {
|
||||||
let xif = 42 in { xif } // Should not trigger
|
let xif = 42 in { xif } // Should not trigger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Comment with no space following it, should trigger an error.
|
||||||
|
let a = 3;//This should cause a problem.
|
||||||
|
//~^ This is a compile-test comment and shouldn't cause a problem.
|
||||||
|
// This comment has a URL, but it shouldn't trigger an error http://servo.org.
|
||||||
|
// This comment has a URL, but it shouldn't trigger an error http://servo.org.
|
||||||
|
/* This is another style of comment, but shouldn't trigger an error. */
|
||||||
}
|
}
|
||||||
|
|
|
@ -555,6 +555,9 @@ def check_rust(file_name: str, lines: list[bytes]) -> Iterator[tuple[int, str]]:
|
||||||
return
|
return
|
||||||
|
|
||||||
for idx, line in enumerate(map(lambda line: line.decode("utf-8"), lines)):
|
for idx, line in enumerate(map(lambda line: line.decode("utf-8"), lines)):
|
||||||
|
for match in re.finditer(r"(;|\s|^)//\w", line):
|
||||||
|
yield (idx + 1, "Comments starting with `//` should also include a space")
|
||||||
|
|
||||||
line = re.sub(r"//.*?$|/\*.*?$|^\*.*?$", "//", line)
|
line = re.sub(r"//.*?$|/\*.*?$|^\*.*?$", "//", line)
|
||||||
rules = [
|
rules = [
|
||||||
# There should be any use of banned types:
|
# There should be any use of banned types:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue