Skip to content

Commit e975e3a

Browse files
committed
refactor: simplify the return value of should_run
1 parent a6c5dcd commit e975e3a

File tree

101 files changed

+114
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+114
-129
lines changed

crates/oxc_linter/src/rule.rs

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,29 @@ bitflags::bitflags! {
2626
}
2727

2828
impl ShouldRunMeta {
29+
#[inline]
2930
pub fn new() -> Self {
3031
ShouldRunMeta::empty()
3132
}
3233

33-
pub fn with_run(self, yes: bool) -> Self {
34-
let other = ShouldRunMeta::IS_RUN;
35-
if yes {
36-
self.union(other)
37-
} else {
38-
self.difference(other)
39-
}
34+
pub fn with_run(mut self, yes: bool) -> Self {
35+
self.set(ShouldRunMeta::IS_RUN, yes);
36+
self
4037
}
4138

42-
pub fn with_run_once(self, yes: bool) -> Self {
43-
let other = ShouldRunMeta::IS_RUN_ONCE;
44-
if yes {
45-
self.union(other)
46-
} else {
47-
self.difference(other)
48-
}
39+
pub fn with_run_once(mut self, yes: bool) -> Self {
40+
self.set(ShouldRunMeta::IS_RUN_ONCE, yes);
41+
self
4942
}
5043

51-
pub fn with_run_on_symbol(self, yes: bool) -> Self {
52-
let other = ShouldRunMeta::IS_RUN_ON_SYMBOL;
53-
if yes {
54-
self.union(other)
55-
} else {
56-
self.difference(other)
57-
}
44+
pub fn with_run_on_symbol(mut self, yes: bool) -> Self {
45+
self.set(ShouldRunMeta::IS_RUN_ON_SYMBOL, yes);
46+
self
5847
}
5948

60-
pub fn with_run_on_jest_node(self, yes: bool) -> Self {
61-
let other = ShouldRunMeta::IS_RUN_ON_JEST_NODE;
62-
if yes {
63-
self.union(other)
64-
} else {
65-
self.difference(other)
66-
}
49+
pub fn with_run_on_jest_node(mut self, yes: bool) -> Self {
50+
self.set(ShouldRunMeta::IS_RUN_ON_JEST_NODE, yes);
51+
self
6752
}
6853
}
6954

@@ -110,7 +95,7 @@ pub trait Rule: Sized + Default + fmt::Debug {
11095
#[expect(unused_variables)]
11196
#[inline]
11297
fn should_run(&self, ctx: &ContextHost) -> ShouldRunMeta {
113-
ShouldRunMeta::new().with_run(true)
98+
ShouldRunMeta::IS_RUN
11499
}
115100
}
116101

crates/oxc_linter/src/rules/eslint/func_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl Rule for FuncNames {
371371
}
372372

373373
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
374-
crate::rule::ShouldRunMeta::new().with_run_once(true)
374+
crate::rule::ShouldRunMeta::IS_RUN_ONCE
375375
}
376376

377377
fn run_once(&self, ctx: &LintContext<'_>) {

crates/oxc_linter/src/rules/eslint/max_classes_per_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Rule for MaxClassesPerFile {
8383
}
8484

8585
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
86-
crate::rule::ShouldRunMeta::new().with_run_once(true)
86+
crate::rule::ShouldRunMeta::IS_RUN_ONCE
8787
}
8888

8989
fn run_once(&self, ctx: &LintContext<'_>) {

crates/oxc_linter/src/rules/eslint/max_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Rule for MaxLines {
8080
}
8181

8282
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
83-
crate::rule::ShouldRunMeta::new().with_run_once(true)
83+
crate::rule::ShouldRunMeta::IS_RUN_ONCE
8484
}
8585

8686
#[allow(clippy::cast_possible_truncation)]

crates/oxc_linter/src/rules/eslint/no_class_assign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare_oxc_lint!(
3636

3737
impl Rule for NoClassAssign {
3838
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
39-
crate::rule::ShouldRunMeta::new().with_run_on_symbol(true)
39+
crate::rule::ShouldRunMeta::IS_RUN_ON_SYMBOL
4040
}
4141

4242
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {

crates/oxc_linter/src/rules/eslint/no_const_assign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ declare_oxc_lint!(
5252

5353
impl Rule for NoConstAssign {
5454
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
55-
crate::rule::ShouldRunMeta::new().with_run_on_symbol(true)
55+
crate::rule::ShouldRunMeta::IS_RUN_ON_SYMBOL
5656
}
5757

5858
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {

crates/oxc_linter/src/rules/eslint/no_dupe_class_members.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ declare_oxc_lint!(
4545

4646
impl Rule for NoDupeClassMembers {
4747
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
48-
crate::rule::ShouldRunMeta::new().with_run_once(true)
48+
crate::rule::ShouldRunMeta::IS_RUN_ONCE
4949
}
5050

5151
fn run_once(&self, ctx: &LintContext) {

crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Rule for NoDuplicateImports {
8686
}
8787

8888
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
89-
crate::rule::ShouldRunMeta::new().with_run_once(true)
89+
crate::rule::ShouldRunMeta::IS_RUN_ONCE
9090
}
9191

9292
fn run_once(&self, ctx: &LintContext) {

crates/oxc_linter/src/rules/eslint/no_ex_assign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare_oxc_lint!(
3838

3939
impl Rule for NoExAssign {
4040
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
41-
crate::rule::ShouldRunMeta::new().with_run_on_symbol(true)
41+
crate::rule::ShouldRunMeta::IS_RUN_ON_SYMBOL
4242
}
4343

4444
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {

crates/oxc_linter/src/rules/eslint/no_extend_native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Rule for NoExtendNative {
8787
}
8888

8989
fn should_run(&self, _: &crate::ContextHost) -> crate::rule::ShouldRunMeta {
90-
crate::rule::ShouldRunMeta::new().with_run_once(true)
90+
crate::rule::ShouldRunMeta::IS_RUN_ONCE
9191
}
9292

9393
fn run_once(&self, ctx: &LintContext) {

0 commit comments

Comments
 (0)