eslint-plugin-jest 23.6.0 → 23.7.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/CHANGELOG.md +14 -0
- package/README.md +3 -3
- package/docs/rules/expect-expect.md +2 -2
- package/docs/rules/valid-title.md +45 -3
- package/lib/rules/expect-expect.js +16 -5
- package/lib/rules/no-commented-out-tests.js +1 -1
- package/lib/rules/no-export.js +1 -1
- package/lib/rules/valid-title.js +33 -15
- package/package.json +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [23.7.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.6.0...v23.7.0) (2020-02-07)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- **expect-expect:** use `u` flag in regex
|
|
6
|
+
([#532](https://github.com/jest-community/eslint-plugin-jest/issues/532))
|
|
7
|
+
([c12b725](https://github.com/jest-community/eslint-plugin-jest/commit/c12b7251ef1506073d268973b93c7fc9fbcf50af))
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- **valid-title:** support `disallowedWords` option
|
|
12
|
+
([#522](https://github.com/jest-community/eslint-plugin-jest/issues/522))
|
|
13
|
+
([38bbe93](https://github.com/jest-community/eslint-plugin-jest/commit/38bbe93794ed456c6e9e5d7be848b2aeb55ce0ba))
|
|
14
|
+
|
|
1
15
|
# [23.6.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.5.0...v23.6.0) (2020-01-12)
|
|
2
16
|
|
|
3
17
|
### Features
|
package/README.md
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
[](https://github.com/jest-community/eslint-plugin-jest/actions)
|
|
2
|
-
[](https://renovatebot.com/)
|
|
3
|
-
|
|
4
1
|
<div align="center">
|
|
5
2
|
<a href="https://eslint.org/">
|
|
6
3
|
<img width="150" height="150" src="https://eslint.org/assets/img/logo.svg">
|
|
@@ -12,6 +9,9 @@
|
|
|
12
9
|
<p>ESLint plugin for Jest</p>
|
|
13
10
|
</div>
|
|
14
11
|
|
|
12
|
+
[](https://github.com/jest-community/eslint-plugin-jest/actions)
|
|
13
|
+
[](https://renovatebot.com/)
|
|
14
|
+
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
17
17
|
```
|
|
@@ -43,8 +43,8 @@ it('should work with callbacks/async', () => {
|
|
|
43
43
|
### `assertFunctionNames`
|
|
44
44
|
|
|
45
45
|
This array option whitelists the assertion function names to look for. Function
|
|
46
|
-
names can
|
|
47
|
-
|
|
46
|
+
names can use wildcards like `request.*.expect`, `request.**.expect`,
|
|
47
|
+
`request.*.expect*`
|
|
48
48
|
|
|
49
49
|
Examples of **incorrect** code for the `{ "assertFunctionNames": ["expect"] }`
|
|
50
50
|
option:
|
|
@@ -45,7 +45,7 @@ xtest('foo', () => {});
|
|
|
45
45
|
|
|
46
46
|
Titles for test blocks should always be a string literal or expression.
|
|
47
47
|
|
|
48
|
-
This is also applied to describe blocks by default, but can be turned off via
|
|
48
|
+
This is also applied to `describe` blocks by default, but can be turned off via
|
|
49
49
|
the `ignoreTypeOfDescribeName` option:
|
|
50
50
|
|
|
51
51
|
Examples of **incorrect** code for this rule:
|
|
@@ -87,7 +87,7 @@ describe(6, function() {});
|
|
|
87
87
|
|
|
88
88
|
**duplicatePrefix**
|
|
89
89
|
|
|
90
|
-
A describe/ test block should not start with duplicatePrefix
|
|
90
|
+
A `describe` / `test` block should not start with `duplicatePrefix`
|
|
91
91
|
|
|
92
92
|
Examples of **incorrect** code for this rule
|
|
93
93
|
|
|
@@ -117,7 +117,7 @@ describe('foo', () => {
|
|
|
117
117
|
|
|
118
118
|
**accidentalSpace**
|
|
119
119
|
|
|
120
|
-
A describe/ test block should not contain accidentalSpace
|
|
120
|
+
A `describe` / `test` block should not contain accidentalSpace
|
|
121
121
|
|
|
122
122
|
Examples of **incorrect** code for this rule
|
|
123
123
|
|
|
@@ -148,3 +148,45 @@ describe('foo', () => {
|
|
|
148
148
|
test('bar', () => {});
|
|
149
149
|
});
|
|
150
150
|
```
|
|
151
|
+
|
|
152
|
+
## Options
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
interface {
|
|
156
|
+
ignoreTypeOfDescribeName?: boolean;
|
|
157
|
+
disallowedWords?: string[];
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### `ignoreTypeOfDescribeName`
|
|
162
|
+
|
|
163
|
+
Default: `false`
|
|
164
|
+
|
|
165
|
+
When enabled, the type of the first argument to `describe` blocks won't be
|
|
166
|
+
checked.
|
|
167
|
+
|
|
168
|
+
#### `disallowedWords`
|
|
169
|
+
|
|
170
|
+
Default: `[]`
|
|
171
|
+
|
|
172
|
+
A string array of words that are not allowed to be used in test titles. Matching
|
|
173
|
+
is not case-sensitive, and looks for complete words:
|
|
174
|
+
|
|
175
|
+
Examples of **incorrect** code using `disallowedWords`:
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
// with disallowedWords: ['correct', 'all', 'every', 'properly']
|
|
179
|
+
describe('the correct way to do things', () => {});
|
|
180
|
+
it('has ALL the things', () => {});
|
|
181
|
+
xdescribe('every single one of them', () => {});
|
|
182
|
+
test(`that the value is set properly`, () => {});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Examples of **correct** code when using `disallowedWords`:
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
// with disallowedWords: ['correct', 'all', 'every', 'properly']
|
|
189
|
+
it('correctly sets the value', () => {});
|
|
190
|
+
test('that everything is as it should be', () => {});
|
|
191
|
+
describe('the proper way to handle things', () => {});
|
|
192
|
+
```
|
|
@@ -7,16 +7,27 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
|
9
9
|
|
|
10
|
-
var _micromatch = _interopRequireDefault(require("micromatch"));
|
|
11
|
-
|
|
12
10
|
var _utils = require("./utils");
|
|
13
11
|
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
12
|
/*
|
|
17
13
|
* This implementation is adapted from eslint-plugin-jasmine.
|
|
18
14
|
* MIT license, Remco Haszing.
|
|
19
15
|
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks if node names returned by getNodeName matches any of the given star patterns
|
|
19
|
+
* Pattern examples:
|
|
20
|
+
* request.*.expect
|
|
21
|
+
* request.**.expect
|
|
22
|
+
* request.**.expect*
|
|
23
|
+
*/
|
|
24
|
+
function matchesAssertFunctionName(nodeName, patterns) {
|
|
25
|
+
return patterns.some(p => new RegExp(`^${p.split('.').map(x => {
|
|
26
|
+
if (x === '**') return '[a-z\\.]*';
|
|
27
|
+
return x.replace(/\*/gu, '[a-z]*');
|
|
28
|
+
}).join('\\.')}(\\.|$)`, 'ui').test(nodeName));
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
var _default = (0, _utils.createRule)({
|
|
21
32
|
name: __filename,
|
|
22
33
|
meta: {
|
|
@@ -74,7 +85,7 @@ var _default = (0, _utils.createRule)({
|
|
|
74
85
|
|
|
75
86
|
if (name === _utils.TestCaseName.it || name === _utils.TestCaseName.test) {
|
|
76
87
|
unchecked.push(node);
|
|
77
|
-
} else if (name &&
|
|
88
|
+
} else if (name && matchesAssertFunctionName(name, assertFunctionNames)) {
|
|
78
89
|
// Return early in case of nested `it` statements.
|
|
79
90
|
checkCallExpressionUsed(context.getAncestors());
|
|
80
91
|
}
|
|
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _utils = require("./utils");
|
|
9
9
|
|
|
10
10
|
function hasTests(node) {
|
|
11
|
-
return /^\s*[xf]?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/
|
|
11
|
+
return /^\s*[xf]?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/mu.test(node.value);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
var _default = (0, _utils.createRule)({
|
package/lib/rules/no-export.js
CHANGED
|
@@ -63,7 +63,7 @@ var _default = (0, _utils.createRule)({
|
|
|
63
63
|
} = object);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
if ('name' in object && object.name === 'module' && property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && /^exports
|
|
66
|
+
if ('name' in object && object.name === 'module' && property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && /^exports?$/u.test(property.name)) {
|
|
67
67
|
exportNodes.push(node);
|
|
68
68
|
}
|
|
69
69
|
}
|
package/lib/rules/valid-title.js
CHANGED
|
@@ -23,6 +23,8 @@ const doesBinaryExpressionContainStringNode = binaryExp => {
|
|
|
23
23
|
return (0, _utils.isStringNode)(binaryExp.left);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
const quoteStringValue = node => node.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral ? `\`${node.quasis[0].value.raw}\`` : node.raw;
|
|
27
|
+
|
|
26
28
|
var _default = (0, _utils.createRule)({
|
|
27
29
|
name: __filename,
|
|
28
30
|
meta: {
|
|
@@ -35,7 +37,8 @@ var _default = (0, _utils.createRule)({
|
|
|
35
37
|
titleMustBeString: 'Title must be a string',
|
|
36
38
|
emptyTitle: '{{ jestFunctionName }} should not have an empty title',
|
|
37
39
|
duplicatePrefix: 'should not have duplicate prefix',
|
|
38
|
-
accidentalSpace: 'should not have leading or trailing spaces'
|
|
40
|
+
accidentalSpace: 'should not have leading or trailing spaces',
|
|
41
|
+
disallowedWord: '"{{ word }}" is not allowed in test titles.'
|
|
39
42
|
},
|
|
40
43
|
type: 'suggestion',
|
|
41
44
|
schema: [{
|
|
@@ -44,6 +47,13 @@ var _default = (0, _utils.createRule)({
|
|
|
44
47
|
ignoreTypeOfDescribeName: {
|
|
45
48
|
type: 'boolean',
|
|
46
49
|
default: false
|
|
50
|
+
},
|
|
51
|
+
disallowedWords: {
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: {
|
|
54
|
+
type: 'string'
|
|
55
|
+
},
|
|
56
|
+
default: []
|
|
47
57
|
}
|
|
48
58
|
},
|
|
49
59
|
additionalProperties: false
|
|
@@ -51,12 +61,15 @@ var _default = (0, _utils.createRule)({
|
|
|
51
61
|
fixable: 'code'
|
|
52
62
|
},
|
|
53
63
|
defaultOptions: [{
|
|
54
|
-
ignoreTypeOfDescribeName: false
|
|
64
|
+
ignoreTypeOfDescribeName: false,
|
|
65
|
+
disallowedWords: []
|
|
55
66
|
}],
|
|
56
67
|
|
|
57
68
|
create(context, [{
|
|
58
|
-
ignoreTypeOfDescribeName
|
|
69
|
+
ignoreTypeOfDescribeName,
|
|
70
|
+
disallowedWords
|
|
59
71
|
}]) {
|
|
72
|
+
const disallowedWordsRegexp = new RegExp(`\\b(${disallowedWords.join('|')})\\b`, 'iu');
|
|
60
73
|
return {
|
|
61
74
|
CallExpression(node) {
|
|
62
75
|
if (!((0, _utils.isDescribe)(node) || (0, _utils.isTestCase)(node)) || !node.arguments.length) {
|
|
@@ -93,16 +106,26 @@ var _default = (0, _utils.createRule)({
|
|
|
93
106
|
return;
|
|
94
107
|
}
|
|
95
108
|
|
|
109
|
+
if (disallowedWords.length > 0) {
|
|
110
|
+
const disallowedMatch = disallowedWordsRegexp.exec(title);
|
|
111
|
+
|
|
112
|
+
if (disallowedMatch) {
|
|
113
|
+
context.report({
|
|
114
|
+
data: {
|
|
115
|
+
word: disallowedMatch[1]
|
|
116
|
+
},
|
|
117
|
+
messageId: 'disallowedWord',
|
|
118
|
+
node: argument
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
96
124
|
if (title.trim().length !== title.length) {
|
|
97
125
|
context.report({
|
|
98
126
|
messageId: 'accidentalSpace',
|
|
99
127
|
node: argument,
|
|
100
|
-
|
|
101
|
-
fix(fixer) {
|
|
102
|
-
const stringValue = argument.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral ? `\`${argument.quasis[0].value.raw}\`` : argument.raw;
|
|
103
|
-
return [fixer.replaceTextRange(argument.range, stringValue.replace(/^([`'"]) +?/, '$1').replace(/ +?([`'"])$/, '$1'))];
|
|
104
|
-
}
|
|
105
|
-
|
|
128
|
+
fix: fixer => [fixer.replaceTextRange(argument.range, quoteStringValue(argument).replace(/^([`'"]) +?/u, '$1').replace(/ +?([`'"])$/u, '$1'))]
|
|
106
129
|
});
|
|
107
130
|
}
|
|
108
131
|
|
|
@@ -113,12 +136,7 @@ var _default = (0, _utils.createRule)({
|
|
|
113
136
|
context.report({
|
|
114
137
|
messageId: 'duplicatePrefix',
|
|
115
138
|
node: argument,
|
|
116
|
-
|
|
117
|
-
fix(fixer) {
|
|
118
|
-
const stringValue = argument.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral ? `\`${argument.quasis[0].value.raw}\`` : argument.raw;
|
|
119
|
-
return [fixer.replaceTextRange(argument.range, stringValue.replace(/^([`'"]).+? /, '$1'))];
|
|
120
|
-
}
|
|
121
|
-
|
|
139
|
+
fix: fixer => [fixer.replaceTextRange(argument.range, quoteStringValue(argument).replace(/^([`'"]).+? /u, '$1'))]
|
|
122
140
|
});
|
|
123
141
|
}
|
|
124
142
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.7.0",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"repository": "jest-community/eslint-plugin-jest",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
"typecheck": "tsc -p ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@typescript-eslint/experimental-utils": "^2.5.0"
|
|
41
|
-
"micromatch": "^4.0.2"
|
|
40
|
+
"@typescript-eslint/experimental-utils": "^2.5.0"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@babel/cli": "^7.4.4",
|
|
@@ -51,7 +50,6 @@
|
|
|
51
50
|
"@semantic-release/git": "^7.0.17",
|
|
52
51
|
"@types/eslint": "^6.1.3",
|
|
53
52
|
"@types/jest": "^24.0.15",
|
|
54
|
-
"@types/micromatch": "^4.0.0",
|
|
55
53
|
"@types/node": "^12.6.6",
|
|
56
54
|
"@typescript-eslint/eslint-plugin": "^2.5.0",
|
|
57
55
|
"@typescript-eslint/parser": "^2.5.0",
|