Skip to content

Commit 56fe5f8

Browse files
authored
docs(linter): update rule documentation (#7680)
part of #6050
1 parent 00fea92 commit 56fe5f8

8 files changed

Lines changed: 83 additions & 23 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ declare_oxc_lint!(
2525
///
2626
/// Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements
2727
///
28+
/// ### Why is this bad?
29+
///
30+
/// Unreachable code after a `return`, `throw`, `continue`, or `break` statement can never be run.
31+
///
32+
/// ### Examples
33+
///
34+
/// Examples of **incorrect** code for this rule:
35+
/// ```ts
36+
/// function foo() {
37+
/// return 2;
38+
/// console.log("this will never be executed");
39+
/// }
40+
/// ```
41+
///
42+
/// Examples of **correct** code for this rule:
43+
/// ```ts
44+
/// function foo() {
45+
/// console.log("this will be executed");
46+
/// return 2;
47+
/// }
48+
/// ```
2849
NoUnreachable,
2950
nursery
3051
);

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ declare_oxc_lint!(
2222
///
2323
/// Disallow `void` operators.
2424
///
25-
/// ### Example
25+
/// Why is this bad
2626
///
27-
/// ```javascript
28-
/// // error
27+
/// The `void` operator is often used to obtain the `undefined` primitive value, but it is unnecessary. You can use `undefined` directly instead.
28+
///
29+
/// ### Examples
30+
///
31+
/// Examples of **incorrect** code for this rule:
32+
/// ```ts
2933
/// void 0;
3034
/// var foo = void 0;
35+
/// ```
3136
///
32-
/// // success
37+
/// Examples of **correct** code for this rule:
38+
/// ```ts
3339
/// "var foo = bar()";
3440
/// "foo.void()";
3541
/// "foo.void = bar";

crates/oxc_linter/src/rules/jest/consistent_test_it.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ declare_oxc_lint!(
101101
/// - **it:** `it`, `xit`, `fit`, `it.only`, `it.skip`.
102102
/// - **test:** `test`, `xtest`, `test.only`, `test.skip`.
103103
///
104+
/// ### Why is this bad?
105+
///
106+
/// It's a good practice to be consistent in your test suite, so that all tests are written in the same way.
107+
///
104108
/// ### Example
105109
///
106110
/// ```javascript

crates/oxc_linter/src/rules/jest/max_nested_describe.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ impl Default for MaxNestedDescribe {
3333
declare_oxc_lint!(
3434
/// ### What it does
3535
///
36-
/// This rule enforces a maximum depth to nested `describe()` calls to improve code
37-
/// clarity in your tests.
36+
/// This rule enforces a maximum depth to nested `describe()` calls.
37+
///
38+
/// ### Why is this bad?
39+
///
40+
/// Nesting `describe()` blocks too deeply can make the test suite hard to read and understand.
3841
///
39-
/// The following patterns are considered warnings (with the default option of
40-
/// `{ "max": 5 } `):
4142
///
4243
/// ### Example
4344
///
44-
/// ```javascript
45+
/// The following patterns are considered warnings (with the default option of
46+
/// `{ "max": 5 } `):
4547
///
46-
/// // invalid
48+
/// /// /// Examples of **incorrect** code for this rule:
49+
/// ```javascript
4750
/// describe('foo', () => {
4851
/// describe('bar', () => {
4952
/// describe('baz', () => {
@@ -75,8 +78,10 @@ declare_oxc_lint!(
7578
/// });
7679
/// });
7780
/// });
81+
/// ```
7882
///
79-
/// // valid
83+
/// Examples of **correct** code for this rule:
84+
/// ```ts
8085
/// describe('foo', () => {
8186
/// describe('bar', () => {
8287
/// it('should get something', () => {

crates/oxc_linter/src/rules/jest/no_conditional_in_test.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ pub struct NoConditionalInTest;
1818

1919
declare_oxc_lint!(
2020
/// ### What it does
21-
/// This rule reports on any use of a conditional statement such as if, switch, and ternary expressions.
21+
///
22+
/// Disallow conditional statements in tests.
23+
///
24+
/// ### Why is this bad?
25+
///
26+
/// Conditional statements in tests can make the test harder to read and understand. It is better to have a single test case per test function.
2227
///
2328
/// ### Examples
2429
///

crates/oxc_linter/src/rules/jest/no_duplicate_hooks.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ pub struct NoDuplicateHooks;
2626
declare_oxc_lint!(
2727
/// ### What it does
2828
///
29-
/// A `describe` block should not contain duplicate hooks.
29+
/// Disallows duplicate hooks in describe blocks.
30+
///
31+
/// ### Why is this bad?
32+
///
33+
/// Having duplicate hooks in a describe block can lead to confusion and unexpected behavior.
3034
///
3135
/// ### Example
32-
/// ```javascript
3336
///
34-
/// // invalid
37+
/// Examples of **incorrect** code for this rule:
38+
/// ```javascript
3539
/// describe('foo', () => {
3640
/// beforeEach(() => {
3741
/// // some setup
@@ -65,9 +69,8 @@ declare_oxc_lint!(
6569
/// });
6670
/// ```
6771
///
72+
/// Examples of **correct** code for this rule:
6873
/// ```javascript
69-
///
70-
/// // valid
7174
/// describe('foo', () => {
7275
/// beforeEach(() => {
7376
/// // some setup

crates/oxc_linter/src/rules/jest/no_large_snapshots.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ impl Deref for NoLargeSnapshots {
5252
declare_oxc_lint!(
5353
/// ### What it does
5454
///
55+
/// Disallow large snapshots.
56+
///
57+
/// ### Why is this bad?
58+
///
5559
/// When using Jest's snapshot capability one should be mindful of the size of
5660
/// created snapshots. As a general best practice snapshots should be limited in
5761
/// size in order to be more manageable and reviewable. A stored snapshot is only as
@@ -60,9 +64,9 @@ declare_oxc_lint!(
6064
///
6165
/// ### Example
6266
///
63-
/// ```javascript
6467
///
65-
/// // invalid
68+
/// Examples of **incorrect** code for this rule:
69+
/// ```javascript
6670
/// exports[`a large snapshot 1`] = `
6771
/// line 1
6872
/// line 2
@@ -116,8 +120,9 @@ declare_oxc_lint!(
116120
/// line 50
117121
/// line 51
118122
/// `;
119-
///
120-
/// // valid
123+
/// ```
124+
/// Examples of **incorrect** code for this rule:
125+
/// ```js
121126
/// exports[`a more manageable and readable snapshot 1`] = `
122127
/// line 1
123128
/// line 2

crates/oxc_linter/src/rules/jest/no_mocks_import.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,22 @@ declare_oxc_lint!(
2222
///
2323
/// This rule reports imports from a path containing a __mocks__ component.
2424
///
25+
/// ### Why is this bad?
26+
///
27+
/// Manually importing mocks from a `__mocks__` directory can lead to unexpected behavior.
28+
///
2529
/// ### Example
26-
/// ```javascript
30+
///
31+
/// Examples of **incorrect** code for this rule:
32+
/// ```ts
2733
/// import thing from './__mocks__/index';
2834
/// require('./__mocks__/index');
29-
/// require('__mocks__');
35+
/// ```
36+
///
37+
/// Examples of **correct** code for this rule:
38+
/// ```ts
39+
/// import thing from 'thing';
40+
/// require('thing');
3041
/// ```
3142
NoMocksImport,
3243
style

0 commit comments

Comments
 (0)