Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: import formatting rules from eslint-plugin-jest-formatting #1563

Merged
merged 20 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 63 additions & 55 deletions README.md

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions docs/rules/padding-around-after-all-blocks.md
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', () => {});
```
36 changes: 36 additions & 0 deletions docs/rules/padding-around-after-each-blocks.md
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', () => {});
```
18 changes: 18 additions & 0 deletions docs/rules/padding-around-all.md
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)
35 changes: 35 additions & 0 deletions docs/rules/padding-around-before-all-blocks.md
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', () => {});
```
36 changes: 36 additions & 0 deletions docs/rules/padding-around-before-each-blocks.md
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', () => {});
```
40 changes: 40 additions & 0 deletions docs/rules/padding-around-describe-blocks.md
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
});
```
42 changes: 42 additions & 0 deletions docs/rules/padding-around-expect-groups.md
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);
});
```
46 changes: 46 additions & 0 deletions docs/rules/padding-around-test-blocks.md
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', () => {});
```
16 changes: 16 additions & 0 deletions src/__tests__/__snapshots__/rules.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest/no-test-prefixes": "error",
"jest/no-test-return-statement": "error",
"jest/no-untyped-mock-factory": "error",
"jest/padding-around-after-all-blocks": "error",
"jest/padding-around-after-each-blocks": "error",
"jest/padding-around-all": "error",
"jest/padding-around-before-all-blocks": "error",
"jest/padding-around-before-each-blocks": "error",
"jest/padding-around-describe-blocks": "error",
"jest/padding-around-expect-groups": "error",
"jest/padding-around-test-blocks": "error",
"jest/prefer-called-with": "error",
"jest/prefer-comparison-matcher": "error",
"jest/prefer-each": "error",
Expand Down Expand Up @@ -120,6 +128,14 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest/no-test-prefixes": "error",
"jest/no-test-return-statement": "error",
"jest/no-untyped-mock-factory": "error",
"jest/padding-around-after-all-blocks": "error",
"jest/padding-around-after-each-blocks": "error",
"jest/padding-around-all": "error",
"jest/padding-around-before-all-blocks": "error",
"jest/padding-around-before-each-blocks": "error",
"jest/padding-around-describe-blocks": "error",
"jest/padding-around-expect-groups": "error",
"jest/padding-around-test-blocks": "error",
"jest/prefer-called-with": "error",
"jest/prefer-comparison-matcher": "error",
"jest/prefer-each": "error",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync } from 'fs';
import { resolve } from 'path';
import plugin from '../';

const numberOfRules = 54;
const numberOfRules = 62;
const ruleNames = Object.keys(plugin.rules);
const deprecatedRules = Object.entries(plugin.rules)
.filter(([, rule]) => rule.meta.deprecated)
Expand Down
Loading