eslint-plugin-jest-formatting 1.2.0 → 3.1.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 +17 -4
- package/.github/workflows/codeql-analysis.yml +71 -0
- package/CHANGELOG.md +6 -0
- package/README.md +10 -11
- package/lib/ast-utils.js +16 -8
- package/lib/index.js +9 -83
- package/lib/rules/padding.js +15 -8
- package/package.json +21 -20
- package/src/ast-utils.ts +5 -1
- package/src/index.ts +1 -110
- package/src/rules/padding.ts +61 -53
- 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:12
|
|
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,34 @@
|
|
|
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",
|
|
24
|
+
"no-shadow": "off",
|
|
25
|
+
"@typescript-eslint/no-shadow": "error"
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
|
-
]
|
|
28
|
+
],
|
|
29
|
+
"settings": {
|
|
30
|
+
"import/resolver": {
|
|
31
|
+
"typescript": {
|
|
32
|
+
"alwaysTryTypes": true // Without this `@types/estree` `estree` isn't actually in our node_modules.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
23
36
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
|
2
|
+
# to commit it to your repository.
|
|
3
|
+
#
|
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
|
5
|
+
# or to provide custom queries or build logic.
|
|
6
|
+
#
|
|
7
|
+
# ******** NOTE ********
|
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
|
+
# supported CodeQL languages.
|
|
11
|
+
#
|
|
12
|
+
name: "CodeQL"
|
|
13
|
+
|
|
14
|
+
on:
|
|
15
|
+
push:
|
|
16
|
+
branches: [ master ]
|
|
17
|
+
pull_request:
|
|
18
|
+
# The branches below must be a subset of the branches above
|
|
19
|
+
branches: [ master ]
|
|
20
|
+
schedule:
|
|
21
|
+
- cron: '42 12 * * 5'
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
analyze:
|
|
25
|
+
name: Analyze
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
permissions:
|
|
28
|
+
actions: read
|
|
29
|
+
contents: read
|
|
30
|
+
security-events: write
|
|
31
|
+
|
|
32
|
+
strategy:
|
|
33
|
+
fail-fast: false
|
|
34
|
+
matrix:
|
|
35
|
+
language: [ 'javascript' ]
|
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
|
37
|
+
# Learn more:
|
|
38
|
+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
|
39
|
+
|
|
40
|
+
steps:
|
|
41
|
+
- name: Checkout repository
|
|
42
|
+
uses: actions/checkout@v2
|
|
43
|
+
|
|
44
|
+
# Initializes the CodeQL tools for scanning.
|
|
45
|
+
- name: Initialize CodeQL
|
|
46
|
+
uses: github/codeql-action/init@v1
|
|
47
|
+
with:
|
|
48
|
+
languages: ${{ matrix.language }}
|
|
49
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
50
|
+
# By default, queries listed here will override any specified in a config file.
|
|
51
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
52
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
53
|
+
|
|
54
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
55
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
|
56
|
+
- name: Autobuild
|
|
57
|
+
uses: github/codeql-action/autobuild@v1
|
|
58
|
+
|
|
59
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
|
60
|
+
# 📚 https://git.io/JvXDl
|
|
61
|
+
|
|
62
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
63
|
+
# and modify them (or add more) to build your code if your project
|
|
64
|
+
# uses a compiled language
|
|
65
|
+
|
|
66
|
+
#- run: |
|
|
67
|
+
# make bootstrap
|
|
68
|
+
# make release
|
|
69
|
+
|
|
70
|
+
- name: Perform CodeQL Analysis
|
|
71
|
+
uses: github/codeql-action/analyze@v1
|
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):
|
|
@@ -75,13 +77,10 @@ We also support a "strict" settings which enabled all of the rules for you
|
|
|
75
77
|
- [padding-around-test-blocks](docs/rules/padding-around-test-blocks.md)
|
|
76
78
|
- [padding-around-all](docs/rules/padding-around-all.md)
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
## Related Projects
|
|
81
|
+
|
|
82
|
+
### eslint-plugin-jest
|
|
83
|
+
|
|
84
|
+
This provides an extensive set of jest eslint rules
|
|
79
85
|
|
|
80
|
-
-
|
|
81
|
-
- [padding-before-before-each-blocks](docs/rules/padding-before-before-each-blocks.md)
|
|
82
|
-
- [padding-before-after-each-blocks](docs/rules/padding-before-after-each-blocks.md)
|
|
83
|
-
- [padding-before-before-all-blocks](docs/rules/padding-before-before-all-blocks.md)
|
|
84
|
-
- [padding-before-after-all-blocks](docs/rules/padding-before-after-all-blocks.md)
|
|
85
|
-
- [padding-before-describe-blocks](docs/rules/padding-before-describe-blocks.md)
|
|
86
|
-
- [padding-before-expect-statements](docs/rules/padding-before-expect-statements.md)
|
|
87
|
-
- [padding-before-test-blocks](docs/rules/padding-before-test-blocks.md)
|
|
86
|
+
https://github.com/jest-community/eslint-plugin-jest
|
package/lib/ast-utils.js
CHANGED
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.getPaddingLineSequences = exports.getActualLastToken = exports.isValidParent = exports.areTokensOnSameLine = exports.isTokenASemicolon = void 0;
|
|
4
|
+
const isTokenASemicolon = (token) => token.value === ';' && token.type === 'Punctuator';
|
|
5
|
+
exports.isTokenASemicolon = isTokenASemicolon;
|
|
6
|
+
const areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
|
|
7
|
+
exports.areTokensOnSameLine = areTokensOnSameLine;
|
|
5
8
|
const STATEMENT_LIST_PARENTS = new Set([
|
|
6
9
|
'Program',
|
|
7
10
|
'BlockStatement',
|
|
8
11
|
'SwitchCase',
|
|
9
12
|
'SwitchStatement',
|
|
10
13
|
]);
|
|
11
|
-
|
|
14
|
+
const isValidParent = (parentType) => {
|
|
12
15
|
return STATEMENT_LIST_PARENTS.has(parentType);
|
|
13
16
|
};
|
|
14
|
-
exports.
|
|
17
|
+
exports.isValidParent = isValidParent;
|
|
18
|
+
const getActualLastToken = (sourceCode, node) => {
|
|
15
19
|
const semiToken = sourceCode.getLastToken(node);
|
|
16
20
|
const prevToken = sourceCode.getTokenBefore(semiToken);
|
|
17
21
|
const nextToken = sourceCode.getTokenAfter(semiToken);
|
|
18
22
|
const isSemicolonLessStyle = Boolean(prevToken &&
|
|
19
23
|
nextToken &&
|
|
20
24
|
prevToken.range[0] >= node.range[0] &&
|
|
21
|
-
exports.isTokenASemicolon(semiToken) &&
|
|
25
|
+
(0, exports.isTokenASemicolon)(semiToken) &&
|
|
22
26
|
semiToken.loc.start.line !== prevToken.loc.end.line &&
|
|
23
27
|
semiToken.loc.end.line === nextToken.loc.start.line);
|
|
24
28
|
return isSemicolonLessStyle ? prevToken : semiToken;
|
|
25
29
|
};
|
|
26
|
-
exports.
|
|
30
|
+
exports.getActualLastToken = getActualLastToken;
|
|
31
|
+
const getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
|
|
27
32
|
const pairs = [];
|
|
28
33
|
const includeComments = true;
|
|
29
|
-
let prevToken = exports.getActualLastToken(sourceCode, prevNode);
|
|
34
|
+
let prevToken = (0, exports.getActualLastToken)(sourceCode, prevNode);
|
|
30
35
|
if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
|
|
31
36
|
do {
|
|
32
|
-
const token = sourceCode.getTokenAfter(prevToken, {
|
|
37
|
+
const token = sourceCode.getTokenAfter(prevToken, {
|
|
38
|
+
includeComments,
|
|
39
|
+
});
|
|
33
40
|
if (token.loc.start.line - prevToken.loc.end.line >= 2) {
|
|
34
41
|
pairs.push([prevToken, token]);
|
|
35
42
|
}
|
|
@@ -38,3 +45,4 @@ exports.getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
|
|
|
38
45
|
}
|
|
39
46
|
return pairs;
|
|
40
47
|
};
|
|
48
|
+
exports.getPaddingLineSequences = getPaddingLineSequences;
|
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: [
|
|
@@ -113,89 +114,14 @@ const paddingConfigs = {
|
|
|
113
114
|
],
|
|
114
115
|
};
|
|
115
116
|
exports.rules = {
|
|
116
|
-
'padding-around-after-all-blocks': padding_1.createRule(paddingConfigs.afterAll),
|
|
117
|
-
'padding-around-after-each-blocks': padding_1.createRule(paddingConfigs.afterEach),
|
|
118
|
-
'padding-around-before-all-blocks': padding_1.createRule(paddingConfigs.beforeAll),
|
|
119
|
-
'padding-around-before-each-blocks': padding_1.createRule(paddingConfigs.beforeEach),
|
|
120
|
-
'padding-around-describe-blocks': padding_1.createRule(paddingConfigs.describe),
|
|
121
|
-
'padding-around-expect-groups': padding_1.createRule(paddingConfigs.expect),
|
|
122
|
-
'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),
|
|
117
|
+
'padding-around-after-all-blocks': (0, padding_1.createRule)(paddingConfigs.afterAll),
|
|
118
|
+
'padding-around-after-each-blocks': (0, padding_1.createRule)(paddingConfigs.afterEach),
|
|
119
|
+
'padding-around-before-all-blocks': (0, padding_1.createRule)(paddingConfigs.beforeAll),
|
|
120
|
+
'padding-around-before-each-blocks': (0, padding_1.createRule)(paddingConfigs.beforeEach),
|
|
121
|
+
'padding-around-describe-blocks': (0, padding_1.createRule)(paddingConfigs.describe),
|
|
122
|
+
'padding-around-expect-groups': (0, padding_1.createRule)(paddingConfigs.expect),
|
|
123
|
+
'padding-around-test-blocks': (0, padding_1.createRule)(paddingConfigs.test),
|
|
124
|
+
'padding-around-all': (0, padding_1.createRule)([].concat(...Object.keys(paddingConfigs).map((k) => paddingConfigs[k]))),
|
|
199
125
|
};
|
|
200
126
|
exports.configs = {
|
|
201
127
|
recommended: {
|
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 = {
|
|
@@ -58,7 +64,7 @@ const paddingAlwaysTester = (prevNode, nextNode, paddingContext) => {
|
|
|
58
64
|
message: 'Expected blank line before this statement.',
|
|
59
65
|
fix(fixer) {
|
|
60
66
|
let prevToken = astUtils.getActualLastToken(sourceCode, prevNode);
|
|
61
|
-
const nextToken = sourceCode.getFirstTokenBetween(prevToken, nextNode, {
|
|
67
|
+
const nextToken = (sourceCode.getFirstTokenBetween(prevToken, nextNode, {
|
|
62
68
|
includeComments: true,
|
|
63
69
|
filter(token) {
|
|
64
70
|
if (astUtils.areTokensOnSameLine(prevToken, token)) {
|
|
@@ -67,7 +73,7 @@ const paddingAlwaysTester = (prevNode, nextNode, paddingContext) => {
|
|
|
67
73
|
}
|
|
68
74
|
return true;
|
|
69
75
|
},
|
|
70
|
-
}) || nextNode;
|
|
76
|
+
}) || nextNode);
|
|
71
77
|
const insertText = astUtils.areTokensOnSameLine(prevToken, nextToken)
|
|
72
78
|
? '\n\n'
|
|
73
79
|
: '\n';
|
|
@@ -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
|
};
|
|
@@ -131,7 +137,7 @@ const verifyNode = (node, paddingContext) => {
|
|
|
131
137
|
}
|
|
132
138
|
scopeInfo.prevNode = node;
|
|
133
139
|
};
|
|
134
|
-
|
|
140
|
+
const createRule = (configs, deprecated = false) => ({
|
|
135
141
|
meta: {
|
|
136
142
|
fixable: 'whitespace',
|
|
137
143
|
deprecated,
|
|
@@ -160,3 +166,4 @@ exports.createRule = (configs, deprecated = false) => ({
|
|
|
160
166
|
};
|
|
161
167
|
},
|
|
162
168
|
});
|
|
169
|
+
exports.createRule = createRule;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest-formatting",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.1.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.29.0",
|
|
34
|
+
"@types/jest": "^27.0.2",
|
|
35
|
+
"@types/node": "^16.11.7",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
38
|
+
"eslint": "^8.2.0",
|
|
39
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
40
|
+
"eslint-config-prettier": "^8.3.0",
|
|
41
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
42
|
+
"eslint-plugin-import": "^2.25.3",
|
|
43
|
+
"eslint-plugin-jest": "^25.2.4",
|
|
43
44
|
"eslint-plugin-jest-formatting": "file:.",
|
|
44
|
-
"eslint-plugin-prettier": "
|
|
45
|
-
"jest": "
|
|
46
|
-
"prettier": "
|
|
47
|
-
"typescript": "
|
|
48
|
-
"ts-jest": "
|
|
45
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
46
|
+
"jest": "^27.3.1",
|
|
47
|
+
"prettier": "2.4.1",
|
|
48
|
+
"typescript": "^4.4.4",
|
|
49
|
+
"ts-jest": "^27.0.7"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
52
|
+
"node": "^12.22.0 || ^14.17.0 || >=16.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 =>
|
|
@@ -64,7 +66,9 @@ export const getPaddingLineSequences = (
|
|
|
64
66
|
|
|
65
67
|
if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
|
|
66
68
|
do {
|
|
67
|
-
const token = sourceCode.getTokenAfter(prevToken, {
|
|
69
|
+
const token = sourceCode.getTokenAfter(prevToken, {
|
|
70
|
+
includeComments,
|
|
71
|
+
}) as AST.Token;
|
|
68
72
|
|
|
69
73
|
if (token.loc.start.line - prevToken.loc.end.line >= 2) {
|
|
70
74
|
pairs.push([prevToken, token]);
|
package/src/index.ts
CHANGED
|
@@ -131,116 +131,7 @@ 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
|
|