Skip to content

Commit

Permalink
Rewrite the ban-type lint in Python
Browse files Browse the repository at this point in the history
Delete old rust ban lint and move tests to python tidy

Fix ban lint regex and fix test
  • Loading branch information
zimio committed Feb 25, 2017
1 parent 26de7c6 commit ebcb15d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 56 deletions.
53 changes: 0 additions & 53 deletions components/script_plugins/ban.rs

This file was deleted.

2 changes: 0 additions & 2 deletions components/script_plugins/lib.rs
Expand Up @@ -25,15 +25,13 @@ extern crate syntax;
use rustc_plugin::Registry;
use syntax::feature_gate::AttributeType::Whitelisted;

mod ban;
mod unrooted_must_root;
/// Utilities for writing plugins
mod utils;

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_late_lint_pass(box unrooted_must_root::UnrootedPass::new());
reg.register_early_lint_pass(box ban::BanPass);
reg.register_attribute("allow_unrooted_interior".to_string(), Whitelisted);
reg.register_attribute("must_root".to_string(), Whitelisted);
}
6 changes: 6 additions & 0 deletions python/tidy/servo_tidy/tidy.py
Expand Up @@ -549,6 +549,12 @@ def check_rust(file_name, lines):
(r": &Vec<", "use &[T] instead of &Vec<T>", no_filter),
# No benefit over using &str
(r": &String", "use &str instead of &String", no_filter),
# There should be any use of banned types:
# Cell<JSVal>, Cell<JS<T>>, DOMRefCell<JS<T>>, DOMRefCell<HEAP<T>>
(r"(\s|:)+Cell<JSVal>", "Banned type Cell<JSVal> detected. Use MutJS<JSVal> instead", no_filter),
(r"(\s|:)+Cell<JS<.+>>", "Banned type Cell<JS<T>> detected. Use MutJS<JS<T>> instead", no_filter),
(r"DOMRefCell<JS<.+>>", "Banned type DOMRefCell<JS<T>> detected. Use MutJS<JS<T>> instead", no_filter),
(r"DOMRefCell<Heap<.+>>", "Banned type DOMRefCell<Heap<T>> detected. Use MutJS<JS<T>> instead", no_filter),
# No benefit to using &Root<T>
(r": &Root<", "use &T instead of &Root<T>", no_filter),
(r"^&&", "operators should go at the end of the first line", no_filter),
Expand Down
Expand Up @@ -9,10 +9,13 @@ extern crate js;

use js::jsval::JSVal;
use std::cell::Cell;
use std::cell::UnsafeCell;

struct Foo {
bar: Cell<JSVal>
bar: Cell<JSVal>,
//~^ ERROR Banned type Cell<JSVal> detected. Use MutJS<JSVal> instead
foo: UnsafeCell<JSVal>
//~^ NOT AN ERROR
}

fn main() {}
8 changes: 8 additions & 0 deletions python/tidy/servo_tidy_tests/test_tidy.py
Expand Up @@ -140,6 +140,14 @@ def test_rust(self):
self.assertTrue('feature attribute is not in alphabetical order' in feature_errors.next()[2])
self.assertNoMoreErrors(feature_errors)

ban_errors = tidy.collect_errors_for_files(iterFile('ban.rs'), [], [tidy.check_rust], print_text=False)
self.assertEqual('Banned type Cell<JSVal> detected. Use MutJS<JSVal> instead', ban_errors.next()[2])
self.assertNoMoreErrors(ban_errors)

ban_errors = tidy.collect_errors_for_files(iterFile('ban-domrefcell.rs'), [], [tidy.check_rust], print_text=False)
self.assertEqual('Banned type DOMRefCell<JS<T>> detected. Use MutJS<JS<T>> instead', ban_errors.next()[2])
self.assertNoMoreErrors(ban_errors)

def test_spec_link(self):
tidy.SPEC_BASE_PATH = base_path
errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec], print_text=False)
Expand Down

0 comments on commit ebcb15d

Please sign in to comment.