-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import formatting rules from
eslint-plugin-jest-formatting
(#…
…1563) * feat: naively copy and paste `eslint-plugin-jest-formatting` rules * refactor: remove unneeded exports * refactor: give each rule a dedicated file * refactor: rename and convert test files to typescript * refactor: use `import` instead of `require` and clean up other imports * refactor: use `createRule` * fix: pass in the correct `name` for each padding rule * refactor: use `@typescript-eslint` types and constants * fix: address some initial typescript errors * refactor: use `messageId` instead of `message` * test: use flat compat `RuleTester` * test: specify full errors instead of counts * test: add basic file for `padding-around-all` * docs: add entries for new padding rules * refactor: address remaining TypeScript issues * refactor: address deprecated `context` method usage * test: remove comments * test: cleanup cases * test: add more cases for coverage * refactor: remove unneeded checks
- Loading branch information
Showing
30 changed files
with
2,204 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Enforce padding around `afterAll` blocks (`padding-around-after-all-blocks`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This rule enforces a line of padding before _and_ after 1 or more `afterAll` | ||
statements. | ||
|
||
Note that it doesn't add/enforce a padding line if it's the last statement in | ||
its scope. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
const someText = 'abc'; | ||
afterAll(() => {}); | ||
describe('someText', () => {}); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
const someText = 'abc'; | ||
|
||
afterAll(() => {}); | ||
|
||
describe('someText', () => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Enforce padding around `afterEach` blocks (`padding-around-after-each-blocks`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This rule enforces a line of padding before _and_ after 1 or more `afterEach` | ||
statements. | ||
|
||
Note that it doesn't add/enforce a padding line if it's the last statement in | ||
its scope. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
const something = 123; | ||
afterEach(() => { | ||
// more stuff | ||
}); | ||
describe('foo', () => {}); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
const something = 123; | ||
|
||
afterEach(() => { | ||
// more stuff | ||
}); | ||
|
||
describe('foo', () => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Enforce padding around Jest functions (`padding-around-all`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This is a meta rule that simply enables all of the following rules: | ||
|
||
- [padding-around-after-all-blocks](padding-around-after-all-blocks.md) | ||
- [padding-around-after-each-blocks](padding-around-after-each-blocks.md) | ||
- [padding-around-before-all-blocks](padding-around-before-all-blocks.md) | ||
- [padding-around-before-each-blocks](padding-around-before-each-blocks.md) | ||
- [padding-around-expect-groups](padding-around-expect-groups.md) | ||
- [padding-around-describe-blocks](padding-around-describe-blocks.md) | ||
- [padding-around-test-blocks](padding-around-test-blocks.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Enforce padding around `beforeAll` blocks (`padding-around-before-all-blocks`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This rule enforces a line of padding before _and_ after `beforeAll` statements. | ||
|
||
Note that it doesn't add/enforce a padding line if it's the last statement in | ||
its scope. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
const something = 123; | ||
beforeAll(() => { | ||
// more stuff | ||
}); | ||
describe('foo', () => {}); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
const something = 123; | ||
|
||
beforeAll(() => { | ||
// more stuff | ||
}); | ||
|
||
describe('foo', () => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Enforce padding around `beforeEach` blocks (`padding-around-before-each-blocks`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This rule enforces a line of padding before _and_ after 1 or more `beforeEach` | ||
statements | ||
|
||
Note that it doesn't add/enforce a padding line if it's the last statement in | ||
its scope | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
const something = 123; | ||
beforeEach(() => { | ||
// more stuff | ||
}); | ||
describe('foo', () => {}); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
const something = 123; | ||
|
||
beforeEach(() => { | ||
// more stuff | ||
}); | ||
|
||
describe('foo', () => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Enforce padding around `describe` blocks (`padding-around-describe-blocks`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This rule enforces a line of padding before _and_ after 1 or more `describe` | ||
statements | ||
|
||
Note that it doesn't add/enforce a padding line if it's the last statement in | ||
its scope | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
const thing = 123; | ||
describe('foo', () => { | ||
// stuff | ||
}); | ||
describe('bar', () => { | ||
// more stuff | ||
}); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
const thing = 123; | ||
|
||
describe('foo', () => { | ||
// stuff | ||
}); | ||
|
||
describe('bar', () => { | ||
// more stuff | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Enforce padding around `expect` groups (`padding-around-expect-groups`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This rule enforces a line of padding before _and_ after 1 or more `expect` | ||
statements | ||
|
||
Note that it doesn't add/enforce a padding line if it's the last statement in | ||
its scope and it doesn't add/enforce padding between two or more adjacent | ||
`expect` statements. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
test('thing one', () => { | ||
let abc = 123; | ||
expect(abc).toEqual(123); | ||
expect(123).toEqual(abc); | ||
abc = 456; | ||
expect(abc).toEqual(456); | ||
}); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
test('thing one', () => { | ||
let abc = 123; | ||
|
||
expect(abc).toEqual(123); | ||
expect(123).toEqual(abc); | ||
|
||
abc = 456; | ||
|
||
expect(abc).toEqual(456); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Enforce padding around afterAll blocks (`padding-around-test-blocks`) | ||
|
||
🔧 This rule is automatically fixable by the | ||
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## Rule Details | ||
|
||
This rule enforces a line of padding before _and_ after 1 or more `test`/`it` | ||
statements | ||
|
||
Note that it doesn't add/enforce a padding line if it's the last statement in | ||
its scope | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
const thing = 123; | ||
test('foo', () => {}); | ||
test('bar', () => {}); | ||
``` | ||
|
||
```js | ||
const thing = 123; | ||
it('foo', () => {}); | ||
it('bar', () => {}); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
const thing = 123; | ||
|
||
test('foo', () => {}); | ||
|
||
test('bar', () => {}); | ||
``` | ||
|
||
```js | ||
const thing = 123; | ||
|
||
it('foo', () => {}); | ||
|
||
it('bar', () => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.