eslint-plugin-jest-formatting 1.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +2 -2
- package/.eslintrc +15 -4
- package/CHANGELOG.md +6 -0
- package/README.md +11 -11
- package/docs/rules/padding-around-all.md +13 -0
- package/lib/ast-utils.js +1 -0
- package/lib/index.js +37 -107
- package/lib/rules/padding.js +11 -5
- package/package.json +21 -20
- package/src/ast-utils.ts +2 -0
- package/src/index.ts +36 -141
- package/src/rules/padding.ts +19 -10
- package/tests/catfood.js +2 -0
- package/tests/dogfood.spec.js +2 -0
- package/tests/lib/rules/padding-around-after-all-blocks.spec.js +2 -1
- package/tests/lib/rules/padding-around-after-each-blocks.spec.js +2 -1
- package/tests/lib/rules/padding-around-before-all-blocks.spec.js +2 -1
- package/tests/lib/rules/padding-around-before-each-blocks.spec.js +2 -1
- package/tests/lib/rules/padding-around-describe-blocks.spec.js +2 -1
- package/tests/lib/rules/padding-around-expect-groups.spec.js +66 -3
- package/tests/lib/rules/padding-around-test-blocks.spec.js +1 -0
- package/.nvmrc +0 -1
- package/tests/lib/rules/padding-before-after-all-blocks.spec.js +0 -98
- package/tests/lib/rules/padding-before-after-each-blocks.spec.js +0 -98
- package/tests/lib/rules/padding-before-before-all-blocks.spec.js +0 -98
- package/tests/lib/rules/padding-before-before-each-blocks.spec.js +0 -98
- package/tests/lib/rules/padding-before-describe-blocks.spec.js +0 -144
- package/tests/lib/rules/padding-before-expect-statements.spec.js +0 -138
- package/tests/lib/rules/padding-before-test-blocks.spec.js +0 -153
- package/yarn.lock +0 -4234
package/.circleci/config.yml
CHANGED
|
@@ -7,7 +7,7 @@ version: 2
|
|
|
7
7
|
defaults: &defaults
|
|
8
8
|
working_directory: ~/repo
|
|
9
9
|
docker:
|
|
10
|
-
- image: circleci/node:
|
|
10
|
+
- image: circleci/node:10
|
|
11
11
|
|
|
12
12
|
jobs:
|
|
13
13
|
test:
|
|
@@ -28,7 +28,7 @@ jobs:
|
|
|
28
28
|
command: yarn test
|
|
29
29
|
|
|
30
30
|
- run: yarn lint
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
- save_cache:
|
|
33
33
|
paths:
|
|
34
34
|
- node_modules
|
package/.eslintrc
CHANGED
|
@@ -3,21 +3,32 @@
|
|
|
3
3
|
"parserOptions": {
|
|
4
4
|
"sourceType": "module"
|
|
5
5
|
},
|
|
6
|
-
"plugins": ["jest-formatting", "jest"],
|
|
6
|
+
"plugins": ["jest-formatting", "jest", "@typescript-eslint/eslint-plugin"],
|
|
7
7
|
"env": {
|
|
8
8
|
"jest/globals": true
|
|
9
9
|
},
|
|
10
10
|
"extends": [
|
|
11
11
|
"airbnb-base",
|
|
12
|
+
"plugin:@typescript-eslint/recommended",
|
|
12
13
|
"plugin:prettier/recommended",
|
|
13
|
-
"plugin:jest-formatting/recommended"
|
|
14
|
+
"plugin:jest-formatting/recommended",
|
|
15
|
+
"plugin:import/typescript"
|
|
14
16
|
],
|
|
15
17
|
"overrides": [
|
|
16
18
|
{
|
|
17
19
|
"files": ["**.*"],
|
|
18
20
|
"rules": {
|
|
19
|
-
"camelcase": "off"
|
|
21
|
+
"camelcase": "off",
|
|
22
|
+
"no-plusplus": "off",
|
|
23
|
+
"import/extensions": "off"
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
|
-
]
|
|
26
|
+
],
|
|
27
|
+
"settings": {
|
|
28
|
+
"import/resolver": {
|
|
29
|
+
"typescript": {
|
|
30
|
+
"alwaysTryTypes": true // Without this `@types/estree` `estree` isn't actually in our node_modules.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
23
34
|
}
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
[](https://circleci.com/gh/dangreenisrael/eslint-plugin-jest-formatting/tree/master)
|
|
2
2
|

|
|
3
3
|
|
|
4
|
-
**_Note: The master version may not be the version deployed to npm. Please treat https://www.npmjs.com/package/eslint-plugin-jest-formatting as the cannonical source for docs._**
|
|
5
|
-
|
|
6
4
|
# eslint-plugin-jest-formatting
|
|
7
5
|
|
|
6
|
+
This package provides ESLint rules for jest test suites.
|
|
7
|
+
|
|
8
8
|
This project aims to provide formatting rules (auto-fixable where possible) to ensure consistency and readability in jest test suites.
|
|
9
9
|
|
|
10
10
|
Like this plugin? [Say thanks with a ⭐️](https://github.com/dangreenisrael/eslint-plugin-jest-formatting/stargazers)
|
|
11
11
|
|
|
12
|
+
**_Note: The master version may not be the version deployed to npm. Please treat https://www.npmjs.com/package/eslint-plugin-jest-formatting as the cannonical source for docs._**
|
|
13
|
+
|
|
12
14
|
## Installation
|
|
13
15
|
|
|
14
16
|
You'll first need to install [ESLint](http://eslint.org):
|
|
@@ -73,14 +75,12 @@ We also support a "strict" settings which enabled all of the rules for you
|
|
|
73
75
|
- [padding-around-expect-groups](docs/rules/padding-around-expect-groups.md)
|
|
74
76
|
- [padding-around-describe-blocks](docs/rules/padding-around-describe-blocks.md)
|
|
75
77
|
- [padding-around-test-blocks](docs/rules/padding-around-test-blocks.md)
|
|
78
|
+
- [padding-around-all](docs/rules/padding-around-all.md)
|
|
79
|
+
|
|
80
|
+
## Related Projects
|
|
81
|
+
|
|
82
|
+
### eslint-plugin-jest
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
This provides an extensive set of jest eslint rules
|
|
78
85
|
|
|
79
|
-
-
|
|
80
|
-
- [padding-before-before-each-blocks](docs/rules/padding-before-before-each-blocks.md)
|
|
81
|
-
- [padding-before-after-each-blocks](docs/rules/padding-before-after-each-blocks.md)
|
|
82
|
-
- [padding-before-before-all-blocks](docs/rules/padding-before-before-all-blocks.md)
|
|
83
|
-
- [padding-before-after-all-blocks](docs/rules/padding-before-after-all-blocks.md)
|
|
84
|
-
- [padding-before-describe-blocks](docs/rules/padding-before-describe-blocks.md)
|
|
85
|
-
- [padding-before-expect-statements](docs/rules/padding-before-expect-statements.md)
|
|
86
|
-
- [padding-before-test-blocks](docs/rules/padding-before-test-blocks.md)
|
|
86
|
+
https://github.com/jest-community/eslint-plugin-jest
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# padding-around-all
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This is a meta rule that simply enables all of the following rules:
|
|
6
|
+
|
|
7
|
+
- [padding-around-after-all-blocks](padding-around-after-all-blocks.md)
|
|
8
|
+
- [padding-around-after-each-blocks](padding-around-after-each-blocks.md)
|
|
9
|
+
- [padding-around-before-all-blocks](padding-around-before-all-blocks.md)
|
|
10
|
+
- [padding-around-before-each-blocks](padding-around-before-each-blocks.md)
|
|
11
|
+
- [padding-around-expect-groups](padding-around-expect-groups.md)
|
|
12
|
+
- [padding-around-describe-blocks](padding-around-describe-blocks.md)
|
|
13
|
+
- [padding-around-test-blocks](padding-around-test-blocks.md)
|
package/lib/ast-utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPaddingLineSequences = exports.getActualLastToken = exports.isValidParent = exports.areTokensOnSameLine = exports.isTokenASemicolon = void 0;
|
|
3
4
|
exports.isTokenASemicolon = (token) => token.value === ';' && token.type === 'Punctuator';
|
|
4
5
|
exports.areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
|
|
5
6
|
const STATEMENT_LIST_PARENTS = new Set([
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configs = exports.rules = void 0;
|
|
3
4
|
const padding_1 = require("./rules/padding");
|
|
4
5
|
const paddingConfigs = {
|
|
5
6
|
afterAll: [
|
|
@@ -120,121 +121,50 @@ exports.rules = {
|
|
|
120
121
|
'padding-around-describe-blocks': padding_1.createRule(paddingConfigs.describe),
|
|
121
122
|
'padding-around-expect-groups': padding_1.createRule(paddingConfigs.expect),
|
|
122
123
|
'padding-around-test-blocks': padding_1.createRule(paddingConfigs.test),
|
|
123
|
-
'padding-around-all': padding_1.createRule([].concat(...Object.keys(paddingConfigs).map(k => paddingConfigs[k]))),
|
|
124
|
-
'padding-before-after-all-blocks': padding_1.createRule([
|
|
125
|
-
{
|
|
126
|
-
paddingType: 1,
|
|
127
|
-
prevStatementType: 0,
|
|
128
|
-
nextStatementType: 1,
|
|
129
|
-
},
|
|
130
|
-
], true),
|
|
131
|
-
'padding-before-after-each-blocks': padding_1.createRule([
|
|
132
|
-
{
|
|
133
|
-
paddingType: 1,
|
|
134
|
-
prevStatementType: 0,
|
|
135
|
-
nextStatementType: 2,
|
|
136
|
-
},
|
|
137
|
-
], true),
|
|
138
|
-
'padding-before-before-all-blocks': padding_1.createRule([
|
|
139
|
-
{
|
|
140
|
-
paddingType: 1,
|
|
141
|
-
prevStatementType: 0,
|
|
142
|
-
nextStatementType: 3,
|
|
143
|
-
},
|
|
144
|
-
], true),
|
|
145
|
-
'padding-before-before-each-blocks': padding_1.createRule([
|
|
146
|
-
{
|
|
147
|
-
paddingType: 1,
|
|
148
|
-
prevStatementType: 0,
|
|
149
|
-
nextStatementType: 4,
|
|
150
|
-
},
|
|
151
|
-
], true),
|
|
152
|
-
'padding-before-describe-blocks': padding_1.createRule([
|
|
153
|
-
{
|
|
154
|
-
paddingType: 1,
|
|
155
|
-
prevStatementType: 0,
|
|
156
|
-
nextStatementType: 5,
|
|
157
|
-
},
|
|
158
|
-
], true),
|
|
159
|
-
'padding-before-expect-statements': padding_1.createRule([
|
|
160
|
-
{
|
|
161
|
-
paddingType: 1,
|
|
162
|
-
prevStatementType: 0,
|
|
163
|
-
nextStatementType: 6,
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
paddingType: 0,
|
|
167
|
-
prevStatementType: 6,
|
|
168
|
-
nextStatementType: 6,
|
|
169
|
-
},
|
|
170
|
-
], true),
|
|
171
|
-
'padding-before-test-blocks': padding_1.createRule([
|
|
172
|
-
{
|
|
173
|
-
paddingType: 1,
|
|
174
|
-
prevStatementType: 0,
|
|
175
|
-
nextStatementType: [10, 9],
|
|
176
|
-
},
|
|
177
|
-
], true),
|
|
178
|
-
'padding-before-all': padding_1.createRule([
|
|
179
|
-
{
|
|
180
|
-
paddingType: 1,
|
|
181
|
-
prevStatementType: 0,
|
|
182
|
-
nextStatementType: [
|
|
183
|
-
1,
|
|
184
|
-
2,
|
|
185
|
-
3,
|
|
186
|
-
4,
|
|
187
|
-
5,
|
|
188
|
-
6,
|
|
189
|
-
9,
|
|
190
|
-
10,
|
|
191
|
-
],
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
paddingType: 0,
|
|
195
|
-
prevStatementType: 6,
|
|
196
|
-
nextStatementType: 6,
|
|
197
|
-
},
|
|
198
|
-
], true),
|
|
124
|
+
'padding-around-all': padding_1.createRule([].concat(...Object.keys(paddingConfigs).map((k) => paddingConfigs[k]))),
|
|
199
125
|
};
|
|
200
126
|
exports.configs = {
|
|
201
127
|
recommended: {
|
|
202
128
|
plugins: ['jest-formatting'],
|
|
203
|
-
overrides:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
129
|
+
overrides: [
|
|
130
|
+
{
|
|
131
|
+
files: [
|
|
132
|
+
'**/*.test.*',
|
|
133
|
+
'**/*_test.*',
|
|
134
|
+
'**/*Test.*',
|
|
135
|
+
'**/*.spec.*',
|
|
136
|
+
'**/*_spec.*',
|
|
137
|
+
'**/*Spec.*',
|
|
138
|
+
'**/__tests__/*',
|
|
139
|
+
],
|
|
140
|
+
rules: {
|
|
141
|
+
'jest-formatting/padding-around-after-all-blocks': 2,
|
|
142
|
+
'jest-formatting/padding-around-after-each-blocks': 2,
|
|
143
|
+
'jest-formatting/padding-around-before-all-blocks': 2,
|
|
144
|
+
'jest-formatting/padding-around-before-each-blocks': 2,
|
|
145
|
+
'jest-formatting/padding-around-describe-blocks': 2,
|
|
146
|
+
'jest-formatting/padding-around-test-blocks': 2,
|
|
147
|
+
},
|
|
220
148
|
},
|
|
221
|
-
|
|
149
|
+
],
|
|
222
150
|
},
|
|
223
151
|
strict: {
|
|
224
152
|
plugins: ['jest-formatting'],
|
|
225
|
-
overrides:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
153
|
+
overrides: [
|
|
154
|
+
{
|
|
155
|
+
files: [
|
|
156
|
+
'**/*.test.*',
|
|
157
|
+
'**/*_test.*',
|
|
158
|
+
'**/*Test.*',
|
|
159
|
+
'**/*.spec.*',
|
|
160
|
+
'**/*_spec.*',
|
|
161
|
+
'**/*Spec.*',
|
|
162
|
+
'**/__tests__/*',
|
|
163
|
+
],
|
|
164
|
+
rules: {
|
|
165
|
+
'jest-formatting/padding-around-all': 2,
|
|
166
|
+
},
|
|
237
167
|
},
|
|
238
|
-
|
|
168
|
+
],
|
|
239
169
|
},
|
|
240
170
|
};
|
package/lib/rules/padding.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRule = exports.PaddingType = exports.StatementType = void 0;
|
|
3
4
|
const astUtils = require("../ast-utils");
|
|
4
5
|
var StatementType;
|
|
5
6
|
(function (StatementType) {
|
|
@@ -25,10 +26,15 @@ var PaddingType;
|
|
|
25
26
|
})(PaddingType = exports.PaddingType || (exports.PaddingType = {}));
|
|
26
27
|
const createTokenTester = (tokenName) => {
|
|
27
28
|
return (node, sourceCode) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
let activeNode = node;
|
|
30
|
+
if (activeNode.type === 'ExpressionStatement') {
|
|
31
|
+
if (activeNode.expression.type === 'AwaitExpression') {
|
|
32
|
+
activeNode = activeNode.expression.argument;
|
|
33
|
+
}
|
|
34
|
+
const token = sourceCode.getFirstToken(activeNode);
|
|
35
|
+
return token.type === 'Identifier' && token.value === tokenName;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
32
38
|
};
|
|
33
39
|
};
|
|
34
40
|
const statementTesters = {
|
|
@@ -105,7 +111,7 @@ const nodeMatchesType = (node, statementType, paddingContext) => {
|
|
|
105
111
|
innerStatementNode = innerStatementNode.body;
|
|
106
112
|
}
|
|
107
113
|
if (Array.isArray(statementType)) {
|
|
108
|
-
return statementType.some(type => nodeMatchesType(innerStatementNode, type, paddingContext));
|
|
114
|
+
return statementType.some((type) => nodeMatchesType(innerStatementNode, type, paddingContext));
|
|
109
115
|
}
|
|
110
116
|
return statementTesters[statementType](innerStatementNode, sourceCode);
|
|
111
117
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest-formatting",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "ESLint rules for formatting jest tests",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
7
7
|
"eslintplugin",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"module": "src/index.ts",
|
|
21
21
|
"scripts": {
|
|
22
22
|
"pretty": "yarn prettier '**/*.*'",
|
|
23
|
-
"lint": "yarn build && yarn link-plugin && yarn pretty --check && yarn eslint .",
|
|
24
|
-
"format": "yarn build && yarn link-plugin && yarn pretty --write && yarn eslint --fix .",
|
|
23
|
+
"lint": "yarn build && yarn link-plugin && yarn pretty --check && yarn eslint --ext .ts,.js .",
|
|
24
|
+
"format": "yarn build && yarn link-plugin && yarn pretty --write && yarn eslint --fix --ext .ts,.js .",
|
|
25
25
|
"build": "tsc",
|
|
26
26
|
"test": "yarn build && jest",
|
|
27
27
|
"link-plugin": "yarn link && yarn link eslint-plugin-jest-formatting"
|
|
@@ -30,25 +30,26 @@
|
|
|
30
30
|
"eslint": ">=0.8.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/eslint": "
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/
|
|
36
|
-
"@
|
|
37
|
-
"@typescript-eslint/parser": "
|
|
38
|
-
"eslint": "
|
|
39
|
-
"eslint-config-airbnb-base": "
|
|
40
|
-
"eslint-config-prettier": "
|
|
41
|
-
"eslint-
|
|
42
|
-
"eslint-plugin-
|
|
33
|
+
"@types/eslint": "^7.2.0",
|
|
34
|
+
"@types/jest": "^26.0.0",
|
|
35
|
+
"@types/node": "^14.0.13",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^3.4.0",
|
|
37
|
+
"@typescript-eslint/parser": "^3.4.0",
|
|
38
|
+
"eslint": "^7.3.1",
|
|
39
|
+
"eslint-config-airbnb-base": "^14.2.0",
|
|
40
|
+
"eslint-config-prettier": "^6.11.0",
|
|
41
|
+
"eslint-import-resolver-typescript": "^2.0.0",
|
|
42
|
+
"eslint-plugin-import": "^2.21.2",
|
|
43
|
+
"eslint-plugin-jest": "^23.17.1",
|
|
43
44
|
"eslint-plugin-jest-formatting": "file:.",
|
|
44
|
-
"eslint-plugin-prettier": "3.1.
|
|
45
|
-
"jest": "
|
|
46
|
-
"prettier": "
|
|
47
|
-
"typescript": "3.
|
|
48
|
-
"ts-jest": "
|
|
45
|
+
"eslint-plugin-prettier": "^3.1.4",
|
|
46
|
+
"jest": "^26.1.0",
|
|
47
|
+
"prettier": "2.0.5",
|
|
48
|
+
"typescript": "^3.9.5",
|
|
49
|
+
"ts-jest": "^26.1.1"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
52
|
+
"node": "^10.12.0 || >=12.0.0"
|
|
52
53
|
},
|
|
53
54
|
"license": "MIT"
|
|
54
55
|
}
|
package/src/ast-utils.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { AST, SourceCode } from 'eslint';
|
|
2
|
+
// This is because we are using @types/estree that are brought in with eslint
|
|
3
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
4
|
import { Node } from 'estree';
|
|
3
5
|
|
|
4
6
|
export const isTokenASemicolon = (token: AST.Token): boolean =>
|
package/src/index.ts
CHANGED
|
@@ -131,157 +131,52 @@ export const rules = {
|
|
|
131
131
|
'padding-around-expect-groups': createRule(paddingConfigs.expect),
|
|
132
132
|
'padding-around-test-blocks': createRule(paddingConfigs.test),
|
|
133
133
|
'padding-around-all': createRule(
|
|
134
|
-
[].concat(...Object.keys(paddingConfigs).map(k => paddingConfigs[k])),
|
|
135
|
-
),
|
|
136
|
-
|
|
137
|
-
// ===========================================================================
|
|
138
|
-
// DEPRECATED
|
|
139
|
-
'padding-before-after-all-blocks': createRule(
|
|
140
|
-
[
|
|
141
|
-
{
|
|
142
|
-
paddingType: PaddingType.Always,
|
|
143
|
-
prevStatementType: StatementType.Any,
|
|
144
|
-
nextStatementType: StatementType.AfterAllToken,
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
true,
|
|
148
|
-
),
|
|
149
|
-
// DEPRECATED
|
|
150
|
-
'padding-before-after-each-blocks': createRule(
|
|
151
|
-
[
|
|
152
|
-
{
|
|
153
|
-
paddingType: PaddingType.Always,
|
|
154
|
-
prevStatementType: StatementType.Any,
|
|
155
|
-
nextStatementType: StatementType.AfterEachToken,
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
true,
|
|
159
|
-
),
|
|
160
|
-
// DEPRECATED
|
|
161
|
-
'padding-before-before-all-blocks': createRule(
|
|
162
|
-
[
|
|
163
|
-
{
|
|
164
|
-
paddingType: PaddingType.Always,
|
|
165
|
-
prevStatementType: StatementType.Any,
|
|
166
|
-
nextStatementType: StatementType.BeforeAllToken,
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
true,
|
|
170
|
-
),
|
|
171
|
-
// DEPRECATED
|
|
172
|
-
'padding-before-before-each-blocks': createRule(
|
|
173
|
-
[
|
|
174
|
-
{
|
|
175
|
-
paddingType: PaddingType.Always,
|
|
176
|
-
prevStatementType: StatementType.Any,
|
|
177
|
-
nextStatementType: StatementType.BeforeEachToken,
|
|
178
|
-
},
|
|
179
|
-
],
|
|
180
|
-
true,
|
|
181
|
-
),
|
|
182
|
-
// DEPRECATED
|
|
183
|
-
'padding-before-describe-blocks': createRule(
|
|
184
|
-
[
|
|
185
|
-
{
|
|
186
|
-
paddingType: PaddingType.Always,
|
|
187
|
-
prevStatementType: StatementType.Any,
|
|
188
|
-
nextStatementType: StatementType.DescribeToken,
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
true,
|
|
192
|
-
),
|
|
193
|
-
// DEPRECATED
|
|
194
|
-
'padding-before-expect-statements': createRule(
|
|
195
|
-
[
|
|
196
|
-
{
|
|
197
|
-
paddingType: PaddingType.Always,
|
|
198
|
-
prevStatementType: StatementType.Any,
|
|
199
|
-
nextStatementType: StatementType.ExpectToken,
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
paddingType: PaddingType.Any,
|
|
203
|
-
prevStatementType: StatementType.ExpectToken,
|
|
204
|
-
nextStatementType: StatementType.ExpectToken,
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
true,
|
|
208
|
-
),
|
|
209
|
-
// DEPRECATED
|
|
210
|
-
'padding-before-test-blocks': createRule(
|
|
211
|
-
[
|
|
212
|
-
{
|
|
213
|
-
paddingType: PaddingType.Always,
|
|
214
|
-
prevStatementType: StatementType.Any,
|
|
215
|
-
nextStatementType: [StatementType.TestToken, StatementType.ItToken],
|
|
216
|
-
},
|
|
217
|
-
],
|
|
218
|
-
true,
|
|
219
|
-
),
|
|
220
|
-
// DEPRECATED
|
|
221
|
-
'padding-before-all': createRule(
|
|
222
|
-
[
|
|
223
|
-
{
|
|
224
|
-
paddingType: PaddingType.Always,
|
|
225
|
-
prevStatementType: StatementType.Any,
|
|
226
|
-
nextStatementType: [
|
|
227
|
-
StatementType.AfterAllToken,
|
|
228
|
-
StatementType.AfterEachToken,
|
|
229
|
-
StatementType.BeforeAllToken,
|
|
230
|
-
StatementType.BeforeEachToken,
|
|
231
|
-
StatementType.DescribeToken,
|
|
232
|
-
StatementType.ExpectToken,
|
|
233
|
-
StatementType.ItToken,
|
|
234
|
-
StatementType.TestToken,
|
|
235
|
-
],
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
paddingType: PaddingType.Any,
|
|
239
|
-
prevStatementType: StatementType.ExpectToken,
|
|
240
|
-
nextStatementType: StatementType.ExpectToken,
|
|
241
|
-
},
|
|
242
|
-
],
|
|
243
|
-
true,
|
|
134
|
+
[].concat(...Object.keys(paddingConfigs).map((k) => paddingConfigs[k])),
|
|
244
135
|
),
|
|
245
136
|
};
|
|
246
137
|
|
|
247
138
|
export const configs = {
|
|
248
139
|
recommended: {
|
|
249
140
|
plugins: ['jest-formatting'],
|
|
250
|
-
overrides:
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
141
|
+
overrides: [
|
|
142
|
+
{
|
|
143
|
+
files: [
|
|
144
|
+
'**/*.test.*',
|
|
145
|
+
'**/*_test.*',
|
|
146
|
+
'**/*Test.*',
|
|
147
|
+
'**/*.spec.*',
|
|
148
|
+
'**/*_spec.*',
|
|
149
|
+
'**/*Spec.*',
|
|
150
|
+
'**/__tests__/*',
|
|
151
|
+
],
|
|
152
|
+
rules: {
|
|
153
|
+
'jest-formatting/padding-around-after-all-blocks': 2,
|
|
154
|
+
'jest-formatting/padding-around-after-each-blocks': 2,
|
|
155
|
+
'jest-formatting/padding-around-before-all-blocks': 2,
|
|
156
|
+
'jest-formatting/padding-around-before-each-blocks': 2,
|
|
157
|
+
'jest-formatting/padding-around-describe-blocks': 2,
|
|
158
|
+
'jest-formatting/padding-around-test-blocks': 2,
|
|
159
|
+
},
|
|
267
160
|
},
|
|
268
|
-
|
|
161
|
+
],
|
|
269
162
|
},
|
|
270
163
|
strict: {
|
|
271
164
|
plugins: ['jest-formatting'],
|
|
272
|
-
overrides:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
165
|
+
overrides: [
|
|
166
|
+
{
|
|
167
|
+
files: [
|
|
168
|
+
'**/*.test.*',
|
|
169
|
+
'**/*_test.*',
|
|
170
|
+
'**/*Test.*',
|
|
171
|
+
'**/*.spec.*',
|
|
172
|
+
'**/*_spec.*',
|
|
173
|
+
'**/*Spec.*',
|
|
174
|
+
'**/__tests__/*',
|
|
175
|
+
],
|
|
176
|
+
rules: {
|
|
177
|
+
'jest-formatting/padding-around-all': 2,
|
|
178
|
+
},
|
|
284
179
|
},
|
|
285
|
-
|
|
180
|
+
],
|
|
286
181
|
},
|
|
287
182
|
};
|
package/src/rules/padding.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { AST, Rule, SourceCode } from 'eslint';
|
|
12
|
+
// This is because we are using @types/estree that are brought in with eslint
|
|
13
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
12
14
|
import { Node } from 'estree';
|
|
13
15
|
import * as astUtils from '../ast-utils';
|
|
14
16
|
|
|
@@ -77,13 +79,20 @@ interface PaddingContext {
|
|
|
77
79
|
// Creates a StatementTester to test an ExpressionStatement's first token name
|
|
78
80
|
const createTokenTester = (tokenName: string): StatementTester => {
|
|
79
81
|
return (node: Node, sourceCode: SourceCode): boolean => {
|
|
80
|
-
|
|
82
|
+
let activeNode = node;
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
if (activeNode.type === 'ExpressionStatement') {
|
|
85
|
+
// In the case of `await`, we actually care about its argument
|
|
86
|
+
if (activeNode.expression.type === 'AwaitExpression') {
|
|
87
|
+
activeNode = activeNode.expression.argument;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const token = sourceCode.getFirstToken(activeNode);
|
|
91
|
+
|
|
92
|
+
return token.type === 'Identifier' && token.value === tokenName;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return false;
|
|
87
96
|
};
|
|
88
97
|
};
|
|
89
98
|
|
|
@@ -219,7 +228,7 @@ const nodeMatchesType = (
|
|
|
219
228
|
// If it's an array recursively check if any of the statement types match
|
|
220
229
|
// the node
|
|
221
230
|
if (Array.isArray(statementType)) {
|
|
222
|
-
return statementType.some(type =>
|
|
231
|
+
return statementType.some((type) =>
|
|
223
232
|
nodeMatchesType(innerStatementNode, type, paddingContext),
|
|
224
233
|
);
|
|
225
234
|
}
|
|
@@ -271,8 +280,8 @@ const verifyNode = (node: Node, paddingContext: PaddingContext): void => {
|
|
|
271
280
|
// ESTree.Node doesn't support the parent property which is added by
|
|
272
281
|
// ESLint during traversal. Our best bet is to ignore the property access
|
|
273
282
|
// here as it's the only place that it's checked.
|
|
274
|
-
// @
|
|
275
|
-
if (!astUtils.isValidParent(node.parent.type)) {
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
284
|
+
if (!astUtils.isValidParent((node as any).parent.type)) {
|
|
276
285
|
return;
|
|
277
286
|
}
|
|
278
287
|
|
|
@@ -314,7 +323,7 @@ const verifyNode = (node: Node, paddingContext: PaddingContext): void => {
|
|
|
314
323
|
*/
|
|
315
324
|
export const createRule = (
|
|
316
325
|
configs: Config[],
|
|
317
|
-
deprecated
|
|
326
|
+
deprecated = false,
|
|
318
327
|
): Rule.RuleModule => ({
|
|
319
328
|
meta: {
|
|
320
329
|
fixable: 'whitespace',
|