mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Add a tidy check for problematic match cases in script_thread.rs
This commit is contained in:
parent
a74cbbeb1a
commit
14d8ae2478
4 changed files with 41 additions and 14 deletions
|
@ -542,6 +542,9 @@ def check_rust(file_name, lines):
|
|||
lambda match, line: line.startswith('use ')),
|
||||
(r"^\s*else {", "else braces should be on the same line", no_filter),
|
||||
(r"[^$ ]\([ \t]", "extra space after (", no_filter),
|
||||
# This particular pattern is not reentrant-safe in script_thread.rs
|
||||
(r"match self.documents.borrow", "use a separate variable for the match expression",
|
||||
lambda match, line: file_name.endswith('script_thread.rs')),
|
||||
]
|
||||
|
||||
for pattern, message, filter_func in regex_rules:
|
||||
|
|
18
python/tidy/servo_tidy_tests/script_thread.rs
Normal file
18
python/tidy/servo_tidy_tests/script_thread.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
fn main() {
|
||||
// This should trigger an error.
|
||||
match self.documents.borrow_mut() {
|
||||
_ => {}
|
||||
}
|
||||
// This should trigger an error.
|
||||
match self.documents.borrow() {
|
||||
_ => {}
|
||||
}
|
||||
// This should not trigger an error.
|
||||
match { self.documents.borrow().find_window(id) } {
|
||||
=> {}
|
||||
}
|
||||
// This should not trigger an error.
|
||||
match self.documents_status.borrow() {
|
||||
=> {}
|
||||
}
|
||||
}
|
|
@ -141,6 +141,12 @@ class CheckTidiness(unittest.TestCase):
|
|||
self.assertEqual('method declared in webidl is missing a comment with a specification link', errors.next()[2])
|
||||
self.assertNoMoreErrors(errors)
|
||||
|
||||
def test_script_thread(self):
|
||||
errors = tidy.collect_errors_for_files(iterFile('script_thread.rs'), [], [tidy.check_rust], print_text=False)
|
||||
self.assertEqual('use a separate variable for the match expression', errors.next()[2])
|
||||
self.assertEqual('use a separate variable for the match expression', errors.next()[2])
|
||||
self.assertNoMoreErrors(errors)
|
||||
|
||||
def test_webidl(self):
|
||||
errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], [], print_text=False)
|
||||
self.assertEqual('No specification link found.', errors.next()[2])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue