eslint-plugin-jest 28.0.0-next.4 → 28.0.0-next.6
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/README.md
CHANGED
|
@@ -275,35 +275,6 @@ While the `recommended` and `style` configurations only change in major versions
|
|
|
275
275
|
the `all` configuration may change in any release and is thus unsuited for
|
|
276
276
|
installations requiring long-term consistency.
|
|
277
277
|
|
|
278
|
-
## Snapshot processing
|
|
279
|
-
|
|
280
|
-
> [!NOTE]
|
|
281
|
-
>
|
|
282
|
-
> This is only relevant for `eslint.config.js`
|
|
283
|
-
|
|
284
|
-
This plugin provides a
|
|
285
|
-
[custom processor](https://eslint.org/docs/latest/extend/custom-processors) to
|
|
286
|
-
allow rules to "lint" snapshot files.
|
|
287
|
-
|
|
288
|
-
For `.eslintrc` based configs, this is automatically enabled out of the box but
|
|
289
|
-
must be opted into for `eslint.config.js` using the `flat/snapshots` config:
|
|
290
|
-
|
|
291
|
-
```js
|
|
292
|
-
const jest = require('eslint-plugin-jest');
|
|
293
|
-
|
|
294
|
-
module.exports = [
|
|
295
|
-
{
|
|
296
|
-
...jest.configs['flat/snapshots'],
|
|
297
|
-
rules: {
|
|
298
|
-
'jest/no-large-snapshots': ['error', { maxSize: 1 }],
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
];
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
Unlike other configs, this includes a `files` array that matches `.snap` files
|
|
305
|
-
meaning you can use it directly
|
|
306
|
-
|
|
307
278
|
## Rules
|
|
308
279
|
|
|
309
280
|
<!-- begin auto-generated rules list -->
|
package/lib/index.js
CHANGED
|
@@ -4,9 +4,6 @@ var _fs = require("fs");
|
|
|
4
4
|
var _path = require("path");
|
|
5
5
|
var _package = require("../package.json");
|
|
6
6
|
var _globals = _interopRequireDefault(require("./globals.json"));
|
|
7
|
-
var snapshotProcessor = _interopRequireWildcard(require("./processors/snapshot-processor"));
|
|
8
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
8
|
// copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
|
|
12
9
|
/* istanbul ignore next */
|
|
@@ -60,10 +57,6 @@ const plugin = {
|
|
|
60
57
|
globals: _globals.default
|
|
61
58
|
}
|
|
62
59
|
},
|
|
63
|
-
processors: {
|
|
64
|
-
snapshots: snapshotProcessor,
|
|
65
|
-
'.snap': snapshotProcessor
|
|
66
|
-
},
|
|
67
60
|
rules
|
|
68
61
|
};
|
|
69
62
|
const createRCConfig = rules => ({
|
|
@@ -88,14 +81,6 @@ plugin.configs = {
|
|
|
88
81
|
style: createRCConfig(styleRules),
|
|
89
82
|
'flat/all': createFlatConfig(allRules),
|
|
90
83
|
'flat/recommended': createFlatConfig(recommendedRules),
|
|
91
|
-
'flat/style': createFlatConfig(styleRules)
|
|
92
|
-
'flat/snapshots': {
|
|
93
|
-
// @ts-expect-error this is introduced in flat config
|
|
94
|
-
files: ['**/*.snap'],
|
|
95
|
-
plugins: {
|
|
96
|
-
jest: plugin
|
|
97
|
-
},
|
|
98
|
-
processor: 'jest/snapshots'
|
|
99
|
-
}
|
|
84
|
+
'flat/style': createFlatConfig(styleRules)
|
|
100
85
|
};
|
|
101
86
|
module.exports = plugin;
|
|
@@ -92,7 +92,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
92
92
|
|
|
93
93
|
/* istanbul ignore if */
|
|
94
94
|
if (!firstBodyToken || !lastBodyToken || !tokenBeforeFirstParam || !tokenAfterLastParam) {
|
|
95
|
-
throw new Error(`Unexpected null when attempting to fix ${
|
|
95
|
+
throw new Error(`Unexpected null when attempting to fix ${(0, _utils2.getFilename)(context)} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`);
|
|
96
96
|
}
|
|
97
97
|
let argumentFix = fixer.replaceText(firstParam, '()');
|
|
98
98
|
if (tokenBeforeFirstParam.value === '(' && tokenAfterLastParam.value === ')') {
|
|
@@ -25,10 +25,10 @@ const reportOnViolation = (context, node, {
|
|
|
25
25
|
if (allowedSnapshotsInFile) {
|
|
26
26
|
const snapshotName = (0, _utils2.getAccessorValue)(node.expression.left.property);
|
|
27
27
|
isAllowed = allowedSnapshotsInFile.some(name => {
|
|
28
|
-
if (name
|
|
29
|
-
return name
|
|
28
|
+
if (typeof name === 'string') {
|
|
29
|
+
return snapshotName === name;
|
|
30
30
|
}
|
|
31
|
-
return snapshotName
|
|
31
|
+
return name.test(snapshotName);
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -75,7 +75,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
75
75
|
},
|
|
76
76
|
defaultOptions: [{}],
|
|
77
77
|
create(context, [options]) {
|
|
78
|
-
if (
|
|
78
|
+
if ((0, _utils2.getFilename)(context).endsWith('.snap')) {
|
|
79
79
|
return {
|
|
80
80
|
ExpressionStatement(node) {
|
|
81
81
|
reportOnViolation(context, node, options);
|
package/lib/rules/utils/misc.js
CHANGED
|
@@ -99,11 +99,11 @@ function getNodeName(node) {
|
|
|
99
99
|
const isFunction = node => node.type === _utils.AST_NODE_TYPES.FunctionExpression || node.type === _utils.AST_NODE_TYPES.ArrowFunctionExpression;
|
|
100
100
|
exports.isFunction = isFunction;
|
|
101
101
|
const getTestCallExpressionsFromDeclaredVariables = (declaredVariables, context) => {
|
|
102
|
-
return declaredVariables.
|
|
102
|
+
return declaredVariables.flatMap(({
|
|
103
103
|
references
|
|
104
|
-
}) =>
|
|
104
|
+
}) => references.map(({
|
|
105
105
|
identifier
|
|
106
|
-
}) => identifier.parent).filter(node => node?.type === _utils.AST_NODE_TYPES.CallExpression && (0, _parseJestFnCall.isTypeOfJestFnCall)(node, context, ['test'])))
|
|
106
|
+
}) => identifier.parent).filter(node => node?.type === _utils.AST_NODE_TYPES.CallExpression && (0, _parseJestFnCall.isTypeOfJestFnCall)(node, context, ['test'])));
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
/**
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.preprocess = exports.postprocess = exports.meta = void 0;
|
|
7
|
-
var _package = require("../../package.json");
|
|
8
|
-
// https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins
|
|
9
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/808
|
|
10
|
-
|
|
11
|
-
const meta = exports.meta = {
|
|
12
|
-
name: _package.name,
|
|
13
|
-
version: _package.version
|
|
14
|
-
};
|
|
15
|
-
const preprocess = source => [source];
|
|
16
|
-
exports.preprocess = preprocess;
|
|
17
|
-
const postprocess = messages =>
|
|
18
|
-
// snapshot files should only be linted with snapshot specific rules
|
|
19
|
-
messages[0].filter(message => message.ruleId === 'jest/no-large-snapshots');
|
|
20
|
-
exports.postprocess = postprocess;
|