Skip to content

Commit

Permalink
test(linter): use plugin name instead of category for finding rule (#…
Browse files Browse the repository at this point in the history
…8353)

needed for #8329

I wanted to use `proc_macro::Span::SourceFile` to auto detect the plugin
name. But this feature is unstable :/
  • Loading branch information
Sysix authored Jan 9, 2025
1 parent 78d7c97 commit b6c1546
Show file tree
Hide file tree
Showing 487 changed files with 1,061 additions and 606 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/disable_directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ semi*/
),
];

Tester::new(EslintNoDebugger::NAME, EslintNoDebugger::CATEGORY, pass, fail)
Tester::new(EslintNoDebugger::NAME, EslintNoDebugger::PLUGIN, pass, fail)
.intentionally_allow_no_fix_tests()
.test();
}
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub trait Rule: Sized + Default + fmt::Debug {
pub trait RuleMeta {
const NAME: &'static str;

const PLUGIN: &'static str;

const CATEGORY: RuleCategory;

/// What kind of auto-fixing can this rule do?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare_oxc_lint!(
/// });
/// ```
ArrayCallbackReturn,
eslint,
pedantic
);

Expand Down Expand Up @@ -580,6 +581,6 @@ fn test() {
("foo?.filter((function() { return () => { console.log('hello') } })?.())", None),
];

Tester::new(ArrayCallbackReturn::NAME, ArrayCallbackReturn::CATEGORY, pass, fail)
Tester::new(ArrayCallbackReturn::NAME, ArrayCallbackReturn::PLUGIN, pass, fail)
.test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/constructor_super.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ declare_oxc_lint!(
/// }
/// ```
ConstructorSuper,
eslint,
nursery // This rule should be implemented with CFG, the current implementation has a lot of
// false positives.
);
Expand Down Expand Up @@ -71,5 +72,5 @@ fn test() {
// ("class A extends 'test' { constructor() { super(); } }", None),
];

Tester::new(ConstructorSuper::NAME, ConstructorSuper::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(ConstructorSuper::NAME, ConstructorSuper::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/default_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare_oxc_lint!(
/// }
/// ```
DefaultCase,
eslint,
restriction,
);

Expand Down Expand Up @@ -255,5 +256,5 @@ fn test() {
),
];

Tester::new(DefaultCase::NAME, DefaultCase::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(DefaultCase::NAME, DefaultCase::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/default_case_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare_oxc_lint!(
/// }
/// ```
DefaultCaseLast,
eslint,
style
);

Expand Down Expand Up @@ -117,5 +118,5 @@ fn test() {
r"switch (foo) { case 1: default: case 2: }",
];

Tester::new(DefaultCaseLast::NAME, DefaultCaseLast::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(DefaultCaseLast::NAME, DefaultCaseLast::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/default_param_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare_oxc_lint!(
/// createUser(undefined, "tabby")
/// ```
DefaultParamLast,
eslint,
style
);

Expand Down Expand Up @@ -97,5 +98,5 @@ fn test() {
"const f = ([a, b] = [1, 2], c) => {}",
];

Tester::new(DefaultParamLast::NAME, DefaultParamLast::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(DefaultParamLast::NAME, DefaultParamLast::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/eqeqeq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare_oxc_lint!(
/// a == b
/// ```
Eqeqeq,
eslint,
pedantic,
conditional_fix
);
Expand Down Expand Up @@ -253,5 +254,5 @@ fn test() {
("a == b", "a == b", None),
];

Tester::new(Eqeqeq::NAME, Eqeqeq::CATEGORY, pass, fail).expect_fix(fix).test_and_snapshot();
Tester::new(Eqeqeq::NAME, Eqeqeq::PLUGIN, pass, fail).expect_fix(fix).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/for_direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ declare_oxc_lint!(
/// }
/// ```
ForDirection,
eslint,
correctness,
fix_dangerous
);
Expand Down Expand Up @@ -320,7 +321,7 @@ fn test() {
("for(var ii = 10; ii > 0; ii+=1){}", "for(var ii = 10; ii > 0; ii-=1){}", None),
];

Tester::new(ForDirection::NAME, ForDirection::CATEGORY, pass, fail)
Tester::new(ForDirection::NAME, ForDirection::PLUGIN, pass, fail)
.expect_fix(fix)
.test_and_snapshot();
}
5 changes: 2 additions & 3 deletions crates/oxc_linter/src/rules/eslint/func_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ declare_oxc_lint!(
/// Foo.prototype.bar = function() {};
/// ```
FuncNames,
eslint,
style,
conditional_fix_suggestion
);
Expand Down Expand Up @@ -798,7 +799,5 @@ fn test() {
),
];

Tester::new(FuncNames::NAME, FuncNames::CATEGORY, pass, fail)
.expect_fix(fix)
.test_and_snapshot();
Tester::new(FuncNames::NAME, FuncNames::PLUGIN, pass, fail).expect_fix(fix).test_and_snapshot();
}
5 changes: 3 additions & 2 deletions crates/oxc_linter/src/rules/eslint/getter_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ declare_oxc_lint!(
/// }
/// ```
GetterReturn,
eslint,
nursery
);

Expand Down Expand Up @@ -519,7 +520,7 @@ fn test() {
),
];

Tester::new(GetterReturn::NAME, GetterReturn::CATEGORY, pass, fail)
Tester::new(GetterReturn::NAME, GetterReturn::PLUGIN, pass, fail)
.change_rule_path_extension("js")
.test_and_snapshot();

Expand All @@ -537,5 +538,5 @@ fn test() {

let fail = vec![];

Tester::new(GetterReturn::NAME, GetterReturn::CATEGORY, pass, fail).test();
Tester::new(GetterReturn::NAME, GetterReturn::PLUGIN, pass, fail).test();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/guard_for_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare_oxc_lint!(
/// }
/// ```
GuardForIn,
eslint,
style
);

Expand Down Expand Up @@ -93,5 +94,5 @@ fn test() {
"for (var x in o) foo();",
];

Tester::new(GuardForIn::NAME, GuardForIn::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(GuardForIn::NAME, GuardForIn::PLUGIN, pass, fail).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/eslint/max_classes_per_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ declare_oxc_lint!(
/// class Bar {}
/// ```
MaxClassesPerFile,
eslint,
pedantic,
);

Expand Down Expand Up @@ -188,6 +189,5 @@ fn test() {
),
];

Tester::new(MaxClassesPerFile::NAME, MaxClassesPerFile::CATEGORY, pass, fail)
.test_and_snapshot();
Tester::new(MaxClassesPerFile::NAME, MaxClassesPerFile::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/max_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare_oxc_lint!(
/// file, most people would agree it should not be in the thousands.
/// Recommendations usually range from 100 to 500 lines.
MaxLines,
eslint,
pedantic
);

Expand Down Expand Up @@ -420,5 +421,5 @@ fn test() {
),
];

Tester::new(MaxLines::NAME, MaxLines::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(MaxLines::NAME, MaxLines::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/max_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ declare_oxc_lint!(
/// }
/// ```
MaxParams,
eslint,
style
);

Expand Down Expand Up @@ -157,5 +158,5 @@ fn test() {
),
];

Tester::new(MaxParams::NAME, MaxParams::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(MaxParams::NAME, MaxParams::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/new_cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ declare_oxc_lint!(
/// var friend = new person.acquaintance();
/// ```
NewCap,
eslint,
style,
pending // TODO: maybe?
);
Expand Down Expand Up @@ -785,5 +786,5 @@ fn test() {
("(foo?.Bar)();", None), // { "ecmaVersion": 2020 }
];

Tester::new(NewCap::NAME, NewCap::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(NewCap::NAME, NewCap::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ declare_oxc_lint!(
/// }
/// ```
NoAlert,
eslint,
restriction,
);

Expand Down Expand Up @@ -175,5 +176,5 @@ fn test() {
"(window?.alert)(foo)", // { "ecmaVersion": 2020 }
];

Tester::new(NoAlert::NAME, NoAlert::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(NoAlert::NAME, NoAlert::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_array_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare_oxc_lint!(
/// let arr3 = new Array(9);
/// ```
NoArrayConstructor,
eslint,
pedantic,
pending
);
Expand Down Expand Up @@ -124,6 +125,6 @@ fn test() {
("Array(0, 1, 2)", None),
];

Tester::new(NoArrayConstructor::NAME, NoArrayConstructor::CATEGORY, pass, fail)
Tester::new(NoArrayConstructor::NAME, NoArrayConstructor::PLUGIN, pass, fail)
.test_and_snapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare_oxc_lint!(
/// - If an async executor function throws an error, the error will be lost and won’t cause the newly-constructed `Promise` to reject.This could make it difficult to debug and handle some errors.
/// - If a Promise executor function is using `await`, this is usually a sign that it is not actually necessary to use the `new Promise` constructor, or the scope of the `new Promise` constructor can be reduced.
NoAsyncPromiseExecutor,
eslint,
correctness
);

Expand Down Expand Up @@ -85,6 +86,6 @@ fn test() {
("new Promise(((((async () => {})))))", None),
];

Tester::new(NoAsyncPromiseExecutor::NAME, NoAsyncPromiseExecutor::CATEGORY, pass, fail)
Tester::new(NoAsyncPromiseExecutor::NAME, NoAsyncPromiseExecutor::PLUGIN, pass, fail)
.test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_await_in_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare_oxc_lint!(
/// }
/// ```
NoAwaitInLoop,
eslint,
perf
);

Expand Down Expand Up @@ -232,5 +233,5 @@ fn test() {
"async function foo() { for await (var x of xs) { while (1) await f(x) } }",
];

Tester::new(NoAwaitInLoop::NAME, NoAwaitInLoop::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(NoAwaitInLoop::NAME, NoAwaitInLoop::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ declare_oxc_lint!(
/// var x = y | z;
/// ```
NoBitwise,
eslint,
restriction
);

Expand Down Expand Up @@ -158,5 +159,5 @@ fn test() {
("a >>>= b", None),
];

Tester::new(NoBitwise::NAME, NoBitwise::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(NoBitwise::NAME, NoBitwise::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ declare_oxc_lint!(
/// });
/// ```
NoCaller,
eslint,
correctness
);

Expand Down Expand Up @@ -98,5 +99,5 @@ fn test() {

let fail = vec![("var x = arguments.callee", None), ("var x = arguments.caller", None)];

Tester::new(NoCaller::NAME, NoCaller::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(NoCaller::NAME, NoCaller::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_case_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare_oxc_lint!(
/// }
/// ```
NoCaseDeclarations,
eslint,
pedantic
);

Expand Down Expand Up @@ -103,6 +104,6 @@ fn test() {
("switch (a) { default: class C {} break; }", None),
];

Tester::new(NoCaseDeclarations::NAME, NoCaseDeclarations::CATEGORY, pass, fail)
Tester::new(NoCaseDeclarations::NAME, NoCaseDeclarations::PLUGIN, pass, fail)
.test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_class_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare_oxc_lint!(
/// let a = new A() // Error
/// ```
NoClassAssign,
eslint,
correctness
);

Expand Down Expand Up @@ -84,5 +85,5 @@ fn test() {
("if (foo) { class A {} A = 1; }", None),
];

Tester::new(NoClassAssign::NAME, NoClassAssign::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(NoClassAssign::NAME, NoClassAssign::PLUGIN, pass, fail).test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_compare_neg_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declare_oxc_lint!(
/// if (x === -0) {}
/// ```
NoCompareNegZero,
eslint,
correctness,
conditional_fix_suggestion
);
Expand Down Expand Up @@ -167,7 +168,7 @@ fn test() {
("-0n <= x", "0n <= x", None),
];

Tester::new(NoCompareNegZero::NAME, NoCompareNegZero::CATEGORY, pass, fail)
Tester::new(NoCompareNegZero::NAME, NoCompareNegZero::PLUGIN, pass, fail)
.expect_fix(fix)
.test_and_snapshot();
}
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_cond_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ declare_oxc_lint!(
/// }
/// ```
NoCondAssign,
eslint,
correctness
);

Expand Down Expand Up @@ -250,5 +251,5 @@ fn test() {
("(((3496.29)).bkufyydt = 2e308) ? foo : bar;", None),
];

Tester::new(NoCondAssign::NAME, NoCondAssign::CATEGORY, pass, fail).test_and_snapshot();
Tester::new(NoCondAssign::NAME, NoCondAssign::PLUGIN, pass, fail).test_and_snapshot();
}
Loading

0 comments on commit b6c1546

Please sign in to comment.