Skip to content

Commit

Permalink
refactor: change jest rule's category (oxc-project#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryven authored Nov 5, 2023
1 parent 4e9260e commit 3b88f74
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 38 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/expect_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare_oxc_lint!(
/// test('should assert something', () => {});
/// ```
ExpectExpect,
restriction
correctness
);

impl Rule for ExpectExpect {
Expand Down Expand Up @@ -424,5 +424,5 @@ fn test() {
),
];

Tester::new(ExpectExpect::NAME, pass, fail).test_and_snapshot();
Tester::new(ExpectExpect::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
7 changes: 5 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_alias_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare_oxc_lint!(
/// expect(a).toThrowError();
/// ```
NoAliasMethods,
restriction
style
);

impl Rule for NoAliasMethods {
Expand Down Expand Up @@ -171,5 +171,8 @@ fn test() {
("expect(a).not[`toThrowError`]()", "expect(a).not[`toThrow`]()", None),
];

Tester::new(NoAliasMethods::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
Tester::new(NoAliasMethods::NAME, pass, fail)
.with_jest_plugin(true)
.expect_fix(fix)
.test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_commented_out_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare_oxc_lint!(
/// // test.skip('foo', () => {});
/// ```
NoCommentedOutTests,
restriction
suspicious
);

impl Rule for NoCommentedOutTests {
Expand Down Expand Up @@ -171,5 +171,5 @@ fn test() {
),
];

Tester::new(NoCommentedOutTests::NAME, pass, fail).test_and_snapshot();
Tester::new(NoCommentedOutTests::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_conditional_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ declare_oxc_lint!(
// });
/// ```
NoConditionalExpect,
restriction
correctness
);

impl Rule for NoConditionalExpect {
Expand Down Expand Up @@ -807,5 +807,5 @@ fn test() {
),
];

Tester::new(NoConditionalExpect::NAME, pass, fail).test_and_snapshot();
Tester::new(NoConditionalExpect::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ declare_oxc_lint!(
/// });
/// ```
NoConfusingSetTimeout,
restriction
style
);

impl Rule for NoConfusingSetTimeout {
Expand Down Expand Up @@ -481,5 +481,5 @@ fn test() {
),
];

Tester::new(NoConfusingSetTimeout::NAME, pass, fail).test_and_snapshot();
Tester::new(NoConfusingSetTimeout::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_disabled_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare_oxc_lint!(
/// });
/// ```
NoDisabledTests,
restriction
correctness
);

#[derive(Debug, Error, Diagnostic)]
Expand Down Expand Up @@ -206,5 +206,5 @@ fn test() {
("import { test } from '@jest/globals';test('something');", None),
];

Tester::new(NoDisabledTests::NAME, pass, fail).test_and_snapshot();
Tester::new(NoDisabledTests::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_done_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ declare_oxc_lint!(
/// ```
NoDoneCallback,
// TODO: add suggestion (see jest-community/eslint-plugin-jest#586)
restriction
style
);

impl Rule for NoDoneCallback {
Expand Down Expand Up @@ -303,5 +303,5 @@ fn test() {
("it.each``('something', ({ a, b }, done) => { done(); })", None),
];

Tester::new(NoDoneCallback::NAME, pass, fail).test_and_snapshot();
Tester::new(NoDoneCallback::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare_oxc_lint!(
/// });
/// ```
NoExport,
restriction
correctness
);

impl Rule for NoExport {
Expand Down Expand Up @@ -112,5 +112,5 @@ fn test() {
// ("module.export.invalid = function() {}; ; test('a test', () => { expect(1).toBe(1);});", None)
];

Tester::new(NoExport::NAME, pass, fail).test_and_snapshot();
Tester::new(NoExport::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
7 changes: 5 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_focused_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ declare_oxc_lint!(
/// `();
/// ```
NoFocusedTests,
restriction
correctness
);

impl Rule for NoFocusedTests {
Expand Down Expand Up @@ -143,5 +143,8 @@ fn test() {
("fdescribe('foo', () => {})", "describe('foo', () => {})", None),
];

Tester::new(NoFocusedTests::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
Tester::new(NoFocusedTests::NAME, pass, fail)
.with_jest_plugin(true)
.expect_fix(fix)
.test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_identical_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare_oxc_lint!(
/// });
/// ```
NoIdenticalTitle,
restriction
style
);

impl Rule for NoIdenticalTitle {
Expand Down Expand Up @@ -488,5 +488,5 @@ fn test() {
// ),
];

Tester::new(NoIdenticalTitle::NAME, pass, fail).test_and_snapshot();
Tester::new(NoIdenticalTitle::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ declare_oxc_lint!(
/// );
/// ```
NoInterpolationInSnapshots,
restriction
style
);

impl Rule for NoInterpolationInSnapshots {
Expand Down Expand Up @@ -110,5 +110,7 @@ fn test() {
("expect(something).not.toThrowErrorMatchingInlineSnapshot(`${interpolated}`);", None),
];

Tester::new(NoInterpolationInSnapshots::NAME, pass, fail).test_and_snapshot();
Tester::new(NoInterpolationInSnapshots::NAME, pass, fail)
.with_jest_plugin(true)
.test_and_snapshot();
}
7 changes: 5 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare_oxc_lint!(
/// });
/// ```
NoJasmineGlobals,
restriction
style
);

const NON_JASMINE_PROPERTY_NAMES: [&str; 4] = ["spyOn", "spyOnProperty", "fail", "pending"];
Expand Down Expand Up @@ -293,5 +293,8 @@ fn test() {
),
];

Tester::new(NoJasmineGlobals::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
Tester::new(NoJasmineGlobals::NAME, pass, fail)
.with_jest_plugin(true)
.expect_fix(fix)
.test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_mocks_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare_oxc_lint!(
/// require('__mocks__');
///
NoMocksImport,
restriction
style
);

impl Rule for NoMocksImport {
Expand Down Expand Up @@ -112,5 +112,5 @@ fn test() {
("import thing from './__mocks__/index'", None),
];

Tester::new(NoMocksImport::NAME, pass, fail).test_and_snapshot();
Tester::new(NoMocksImport::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_standalone_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare_oxc_lint!(
/// });
/// ```
NoStandaloneExpect,
restriction
correctness
);

impl Rule for NoStandaloneExpect {
Expand Down Expand Up @@ -315,5 +315,5 @@ fn test() {
)
];

Tester::new(NoStandaloneExpect::NAME, pass, fail).test_and_snapshot();
Tester::new(NoStandaloneExpect::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/no_test_prefixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare_oxc_lint!(
/// xdescribe('foo'); // invalid
/// ```
NoTestPrefixes,
restriction
style
);

fn get_preferred_node_names(jest_fn_call: &ParsedGeneralJestFnCall) -> Atom {
Expand Down Expand Up @@ -159,5 +159,5 @@ fn test() {
),
];

Tester::new(NoTestPrefixes::NAME, pass, fail).test_and_snapshot();
Tester::new(NoTestPrefixes::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/valid_describe_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ declare_oxc_lint!(
/// }));
/// ```
ValidDescribeCallback,
restriction
correctness
);

impl Rule for ValidDescribeCallback {
Expand Down Expand Up @@ -326,5 +326,5 @@ fn test() {
("describe('foo', async function (done) {})", None),
];

Tester::new(ValidDescribeCallback::NAME, pass, fail).test_and_snapshot();
Tester::new(ValidDescribeCallback::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/rules/jest/valid_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ declare_oxc_lint!(
/// expect(Promise.resolve('Hi!')).resolves.toBe('Hi!');
/// ```
ValidExpect,
restriction
correctness
);

impl Rule for ValidExpect {
Expand Down Expand Up @@ -369,7 +369,7 @@ fn test_1() {
];
let fail = vec![];

Tester::new(ValidExpect::NAME, pass, fail).test_and_snapshot();
Tester::new(ValidExpect::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}

#[test]
Expand Down Expand Up @@ -739,5 +739,5 @@ fn test() {
)
];

Tester::new(ValidExpect::NAME, pass, fail).test_and_snapshot();
Tester::new(ValidExpect::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/jest/valid_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare_oxc_lint!(
/// xtest('', () => {});
/// ```
ValidTitle,
restriction
correctness
);

impl Rule for ValidTitle {
Expand Down Expand Up @@ -860,5 +860,5 @@ fn test() {
),
];

Tester::new(ValidTitle::NAME, pass, fail).test_and_snapshot();
Tester::new(ValidTitle::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
}
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/jsx_a11y/alt_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,5 +542,5 @@ fn test() {
(r#"<Input type="image" />"#, None),
];

Tester::new(AltText::NAME, pass, fail).test_and_snapshot();
Tester::new(AltText::NAME, pass, fail).with_jsx_a11y_plugin(true).test_and_snapshot();
}
10 changes: 10 additions & 0 deletions crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ impl Tester {
self
}

pub fn with_jest_plugin(mut self, yes: bool) -> Self {
self.jest_plugin = yes;
self
}

pub fn with_jsx_a11y_plugin(mut self, yes: bool) -> Self {
self.jsx_a11y_plugin = yes;
self
}

pub fn expect_fix<S: Into<String>>(mut self, expect_fix: Vec<(S, S, Option<Value>)>) -> Self {
self.expect_fix =
expect_fix.into_iter().map(|(s1, s2, r)| (s1.into(), s2.into(), r)).collect::<Vec<_>>();
Expand Down

0 comments on commit 3b88f74

Please sign in to comment.