Skip to content

Commit

Permalink
refactor(lint/noFocusedTests): report fdescribe and fit
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasweng committed Feb 18, 2024
1 parent fb381f8 commit 0df094f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ declare_rule! {
}
}

const FUNCTION_NAMES: [&str; 3] = ["only", "fdescribe", "fit"];

impl Rule for NoFocusedTests {
type Query = Ast<JsCallExpression>;
type State = TextRange;
Expand All @@ -45,7 +47,7 @@ impl Rule for NoFocusedTests {
if callee.contains_a_test_pattern().ok()? {
let function_name = get_function_name(&callee)?;

if function_name.text_trimmed() == "only" {
if FUNCTION_NAMES.contains(&function_name.text_trimmed()) {
return Some(function_name.text_trimmed_range());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,41 @@ invalid.js:3:6 lint/nursery/noFocusedTests ━━━━━━━━━━━━
```

```
invalid.js:4:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
2 │ it.only("test", () => {});
3 │ test.only("test", () => {});
> 4 │ fdescribe('foo', () => {});
│ ^^^^^^^^^
5 │ fit('foo', () => {});
6 │
i This is likely a change done during debugging or implementation phases, but it's unlikely what you want in production.
i Remove it.
```

```
invalid.js:5:1 lint/nursery/noFocusedTests ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
3 │ test.only("test", () => {});
4 │ fdescribe('foo', () => {});
> 5 │ fit('foo', () => {});
│ ^^^
6 │
i This is likely a change done during debugging or implementation phases, but it's unlikely what you want in production.
i Remove it.
```


Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe.skip("test", () => {});
it.skip("test", () => {});
test.skip("test", () => {});
fdescribe('foo', () => {});
fit('foo', () => {});
xdescribe('foo', () => {});
xit('foo', () => {});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ expression: valid.js
describe.skip("test", () => {});
it.skip("test", () => {});
test.skip("test", () => {});
fdescribe('foo', () => {});
fit('foo', () => {});
xdescribe('foo', () => {});
xit('foo', () => {});

```

Expand Down

0 comments on commit 0df094f

Please sign in to comment.