Skip to content

Commit

Permalink
Auto merge of #15649 - zimio:issue-15591-rewrite-ban-type-lint, r=Waf…
Browse files Browse the repository at this point in the history
…flespeanut

Rewrite the ban-type lint in Python

<!-- Please describe your changes on the following line: -->
Rewrite the ban-type lint in Python.

Question: Should the old ban-type lint written in rust be deleted?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x ] `./mach build -d` does not report any errors
- [x ] `./mach test-tidy` does not report any errors
- [x ] These changes fix #15591

<!-- Either: -->
- [ x] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15649)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Feb 26, 2017
2 parents 6318c4b + ebcb15d commit 261df34
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 261df34

Please sign in to comment.