Skip to content

Commit

Permalink
refactor(linter): pass Rc by value (#3587)
Browse files Browse the repository at this point in the history
Same as #3586.
  • Loading branch information
overlookmotel committed Jun 8, 2024
1 parent 7d61832 commit fa11644
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_language_server/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl IsolatedLintHandler {

let lint_ctx = LintContext::new(
path.to_path_buf().into_boxed_path(),
&Rc::new(semantic_ret.semantic),
Rc::new(semantic_ret.semantic),
);

let result = linter.run(lint_ctx);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pub struct LintContext<'a> {
}

impl<'a> LintContext<'a> {
pub fn new(file_path: Box<Path>, semantic: &Rc<Semantic<'a>>) -> Self {
pub fn new(file_path: Box<Path>, semantic: Rc<Semantic<'a>>) -> Self {
let disable_directives =
DisableDirectivesBuilder::new(semantic.source_text(), semantic.trivias()).build();
Self {
semantic: Rc::clone(semantic),
semantic,
diagnostics: RefCell::new(vec![]),
disable_directives: Rc::new(disable_directives),
fix: false,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl Runtime {
};

let lint_ctx =
LintContext::new(path.to_path_buf().into_boxed_path(), &Rc::new(semantic_ret.semantic));
LintContext::new(path.to_path_buf().into_boxed_path(), Rc::new(semantic_ret.semantic));
self.linter.run(lint_ctx)
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/utils/jest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ mod test {
let semantic_ret = Rc::new(semantic_ret);

let path = Path::new("foo.js");
let ctx = LintContext::new(Box::from(path), &semantic_ret);
let ctx = LintContext::new(Box::from(path), Rc::clone(&semantic_ret));
assert!(!super::is_jest_file(&ctx));

let path = Path::new("foo.test.js");
let ctx = LintContext::new(Box::from(path), &semantic_ret);
let ctx = LintContext::new(Box::from(path), Rc::clone(&semantic_ret));
assert!(super::is_jest_file(&ctx));

let path = Path::new("__tests__/foo/test.spec.js");
let ctx = LintContext::new(Box::from(path), &semantic_ret);
let ctx = LintContext::new(Box::from(path), semantic_ret);
assert!(super::is_jest_file(&ctx));
}
}
2 changes: 1 addition & 1 deletion crates/oxc_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl Oxc {
let semantic = Rc::new(semantic_ret.semantic);
// Only lint if there are not syntax errors
if run_options.lint() && self.diagnostics.borrow().is_empty() {
let lint_ctx = LintContext::new(path.clone().into_boxed_path(), &semantic);
let lint_ctx = LintContext::new(path.clone().into_boxed_path(), Rc::clone(&semantic));
let linter_ret = Linter::default().run(lint_ctx);
let diagnostics = linter_ret.into_iter().map(|e| Error::from(e.error)).collect();
self.save_diagnostics(diagnostics);
Expand Down
5 changes: 4 additions & 1 deletion tasks/benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ fn bench_linter(criterion: &mut Criterion) {
let linter = Linter::from_options(lint_options).unwrap();
let semantic = Rc::new(semantic_ret.semantic);
b.iter(|| {
linter.run(LintContext::new(PathBuf::from("").into_boxed_path(), &semantic))
linter.run(LintContext::new(
PathBuf::from("").into_boxed_path(),
Rc::clone(&semantic),
))
});
},
);
Expand Down

0 comments on commit fa11644

Please sign in to comment.