Delete node too
This commit is contained in:
15
frontend/node_modules/eslint-plugin-jest/lib/globals.json
generated
vendored
15
frontend/node_modules/eslint-plugin-jest/lib/globals.json
generated
vendored
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"afterAll": false,
|
||||
"afterEach": false,
|
||||
"beforeAll": false,
|
||||
"beforeEach": false,
|
||||
"describe": false,
|
||||
"expect": false,
|
||||
"fit": false,
|
||||
"it": false,
|
||||
"jest": false,
|
||||
"test": false,
|
||||
"xdescribe": false,
|
||||
"xit": false,
|
||||
"xtest": false
|
||||
}
|
||||
70
frontend/node_modules/eslint-plugin-jest/lib/index.js
generated
vendored
70
frontend/node_modules/eslint-plugin-jest/lib/index.js
generated
vendored
@@ -1,70 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _fs = require("fs");
|
||||
|
||||
var _path = require("path");
|
||||
|
||||
var _globals = _interopRequireDefault(require("./globals.json"));
|
||||
|
||||
var snapshotProcessor = _interopRequireWildcard(require("./processors/snapshot-processor"));
|
||||
|
||||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
||||
|
||||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
|
||||
|
||||
/* istanbul ignore next */
|
||||
const interopRequireDefault = obj => obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
|
||||
const importDefault = moduleName => // eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
interopRequireDefault(require(moduleName)).default;
|
||||
|
||||
const rulesDir = (0, _path.join)(__dirname, 'rules');
|
||||
const excludedFiles = ['__tests__', 'detectJestVersion', 'utils'];
|
||||
const rules = (0, _fs.readdirSync)(rulesDir).map(rule => (0, _path.parse)(rule).name).filter(rule => !excludedFiles.includes(rule)).reduce((acc, curr) => ({ ...acc,
|
||||
[curr]: importDefault((0, _path.join)(rulesDir, curr))
|
||||
}), {});
|
||||
const recommendedRules = Object.entries(rules).filter(([, rule]) => rule.meta.docs.recommended).reduce((acc, [name, rule]) => ({ ...acc,
|
||||
[`jest/${name}`]: rule.meta.docs.recommended
|
||||
}), {});
|
||||
const allRules = Object.entries(rules).filter(([, rule]) => !rule.meta.deprecated).reduce((acc, [name]) => ({ ...acc,
|
||||
[`jest/${name}`]: 'error'
|
||||
}), {});
|
||||
|
||||
const createConfig = rules => ({
|
||||
plugins: ['jest'],
|
||||
env: {
|
||||
'jest/globals': true
|
||||
},
|
||||
rules
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
configs: {
|
||||
all: createConfig(allRules),
|
||||
recommended: createConfig(recommendedRules),
|
||||
style: {
|
||||
plugins: ['jest'],
|
||||
rules: {
|
||||
'jest/no-alias-methods': 'warn',
|
||||
'jest/prefer-to-be': 'error',
|
||||
'jest/prefer-to-contain': 'error',
|
||||
'jest/prefer-to-have-length': 'error'
|
||||
}
|
||||
}
|
||||
},
|
||||
environments: {
|
||||
globals: {
|
||||
globals: _globals.default
|
||||
}
|
||||
},
|
||||
processors: {
|
||||
'.snap': snapshotProcessor
|
||||
},
|
||||
rules
|
||||
};
|
||||
17
frontend/node_modules/eslint-plugin-jest/lib/processors/snapshot-processor.js
generated
vendored
17
frontend/node_modules/eslint-plugin-jest/lib/processors/snapshot-processor.js
generated
vendored
@@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.preprocess = exports.postprocess = void 0;
|
||||
|
||||
// https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins
|
||||
// https://github.com/typescript-eslint/typescript-eslint/issues/808
|
||||
const preprocess = source => [source];
|
||||
|
||||
exports.preprocess = preprocess;
|
||||
|
||||
const postprocess = messages => // snapshot files should only be linted with snapshot specific rules
|
||||
messages[0].filter(message => message.ruleId === 'jest/no-large-snapshots');
|
||||
|
||||
exports.postprocess = postprocess;
|
||||
119
frontend/node_modules/eslint-plugin-jest/lib/rules/consistent-test-it.js
generated
vendored
119
frontend/node_modules/eslint-plugin-jest/lib/rules/consistent-test-it.js
generated
vendored
@@ -1,119 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const buildFixer = (callee, nodeName, preferredTestKeyword) => fixer => [fixer.replaceText(callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression ? callee.object : callee, getPreferredNodeName(nodeName, preferredTestKeyword))];
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Have control over `test` and `it` usages',
|
||||
recommended: false
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
consistentMethod: "Prefer using '{{ testKeyword }}' instead of '{{ oppositeTestKeyword }}'",
|
||||
consistentMethodWithinDescribe: "Prefer using '{{ testKeywordWithinDescribe }}' instead of '{{ oppositeTestKeyword }}' within describe"
|
||||
},
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
fn: {
|
||||
enum: [_utils.TestCaseName.it, _utils.TestCaseName.test]
|
||||
},
|
||||
withinDescribe: {
|
||||
enum: [_utils.TestCaseName.it, _utils.TestCaseName.test]
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [{
|
||||
fn: _utils.TestCaseName.test,
|
||||
withinDescribe: _utils.TestCaseName.it
|
||||
}],
|
||||
|
||||
create(context) {
|
||||
const configObj = context.options[0] || {};
|
||||
const testKeyword = configObj.fn || _utils.TestCaseName.test;
|
||||
const testKeywordWithinDescribe = configObj.withinDescribe || configObj.fn || _utils.TestCaseName.it;
|
||||
let describeNestingLevel = 0;
|
||||
return {
|
||||
CallExpression(node) {
|
||||
const nodeName = (0, _utils.getNodeName)(node.callee);
|
||||
|
||||
if (!nodeName) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
describeNestingLevel++;
|
||||
}
|
||||
|
||||
const funcNode = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
||||
|
||||
if ((0, _utils.isTestCaseCall)(node) && describeNestingLevel === 0 && !nodeName.includes(testKeyword)) {
|
||||
const oppositeTestKeyword = getOppositeTestKeyword(testKeyword);
|
||||
context.report({
|
||||
messageId: 'consistentMethod',
|
||||
node: node.callee,
|
||||
data: {
|
||||
testKeyword,
|
||||
oppositeTestKeyword
|
||||
},
|
||||
fix: buildFixer(funcNode, nodeName, testKeyword)
|
||||
});
|
||||
}
|
||||
|
||||
if ((0, _utils.isTestCaseCall)(node) && describeNestingLevel > 0 && !nodeName.includes(testKeywordWithinDescribe)) {
|
||||
const oppositeTestKeyword = getOppositeTestKeyword(testKeywordWithinDescribe);
|
||||
context.report({
|
||||
messageId: 'consistentMethodWithinDescribe',
|
||||
node: node.callee,
|
||||
data: {
|
||||
testKeywordWithinDescribe,
|
||||
oppositeTestKeyword
|
||||
},
|
||||
fix: buildFixer(funcNode, nodeName, testKeywordWithinDescribe)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
describeNestingLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
|
||||
function getPreferredNodeName(nodeName, preferredTestKeyword) {
|
||||
if (nodeName === _utils.TestCaseName.fit) {
|
||||
return 'test.only';
|
||||
}
|
||||
|
||||
return nodeName.startsWith('f') || nodeName.startsWith('x') ? nodeName.charAt(0) + preferredTestKeyword : preferredTestKeyword;
|
||||
}
|
||||
|
||||
function getOppositeTestKeyword(test) {
|
||||
if (test === _utils.TestCaseName.test) {
|
||||
return _utils.TestCaseName.it;
|
||||
}
|
||||
|
||||
return _utils.TestCaseName.test;
|
||||
}
|
||||
29
frontend/node_modules/eslint-plugin-jest/lib/rules/detectJestVersion.js
generated
vendored
29
frontend/node_modules/eslint-plugin-jest/lib/rules/detectJestVersion.js
generated
vendored
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.detectJestVersion = void 0;
|
||||
let cachedJestVersion = null;
|
||||
|
||||
const detectJestVersion = () => {
|
||||
if (cachedJestVersion) {
|
||||
return cachedJestVersion;
|
||||
}
|
||||
|
||||
try {
|
||||
const jestPath = require.resolve('jest/package.json');
|
||||
|
||||
const jestPackageJson = // eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
require(jestPath);
|
||||
|
||||
if (jestPackageJson.version) {
|
||||
const [majorVersion] = jestPackageJson.version.split('.');
|
||||
return cachedJestVersion = parseInt(majorVersion, 10);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
throw new Error('Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly');
|
||||
};
|
||||
|
||||
exports.detectJestVersion = detectJestVersion;
|
||||
120
frontend/node_modules/eslint-plugin-jest/lib/rules/expect-expect.js
generated
vendored
120
frontend/node_modules/eslint-plugin-jest/lib/rules/expect-expect.js
generated
vendored
@@ -1,120 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
/*
|
||||
* This implementation is adapted from eslint-plugin-jasmine.
|
||||
* MIT license, Remco Haszing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if node names returned by getNodeName matches any of the given star patterns
|
||||
* Pattern examples:
|
||||
* request.*.expect
|
||||
* request.**.expect
|
||||
* request.**.expect*
|
||||
*/
|
||||
function matchesAssertFunctionName(nodeName, patterns) {
|
||||
return patterns.some(p => new RegExp(`^${p.split('.').map(x => {
|
||||
if (x === '**') return '[a-z\\.]*';
|
||||
return x.replace(/\*/gu, '[a-z]*');
|
||||
}).join('\\.')}(\\.|$)`, 'ui').test(nodeName));
|
||||
}
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Enforce assertion to be made in a test body',
|
||||
recommended: 'warn'
|
||||
},
|
||||
messages: {
|
||||
noAssertions: 'Test has no assertions'
|
||||
},
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
assertFunctionNames: {
|
||||
type: 'array',
|
||||
items: [{
|
||||
type: 'string'
|
||||
}]
|
||||
},
|
||||
additionalTestBlockFunctions: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [{
|
||||
assertFunctionNames: ['expect'],
|
||||
additionalTestBlockFunctions: []
|
||||
}],
|
||||
|
||||
create(context, [{
|
||||
assertFunctionNames = ['expect'],
|
||||
additionalTestBlockFunctions = []
|
||||
}]) {
|
||||
const unchecked = [];
|
||||
|
||||
function checkCallExpressionUsed(nodes) {
|
||||
for (const node of nodes) {
|
||||
const index = node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? unchecked.indexOf(node) : -1;
|
||||
|
||||
if (node.type === _experimentalUtils.AST_NODE_TYPES.FunctionDeclaration) {
|
||||
const declaredVariables = context.getDeclaredVariables(node);
|
||||
const testCallExpressions = (0, _utils.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
||||
checkCallExpressionUsed(testCallExpressions);
|
||||
}
|
||||
|
||||
if (index !== -1) {
|
||||
unchecked.splice(index, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
CallExpression(node) {
|
||||
var _getNodeName;
|
||||
|
||||
const name = (_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 ? _getNodeName : '';
|
||||
|
||||
if ((0, _utils.isTestCaseCall)(node) || additionalTestBlockFunctions.includes(name)) {
|
||||
if (node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(node.callee.property, 'todo')) {
|
||||
return;
|
||||
}
|
||||
|
||||
unchecked.push(node);
|
||||
} else if (matchesAssertFunctionName(name, assertFunctionNames)) {
|
||||
// Return early in case of nested `it` statements.
|
||||
checkCallExpressionUsed(context.getAncestors());
|
||||
}
|
||||
},
|
||||
|
||||
'Program:exit'() {
|
||||
unchecked.forEach(node => context.report({
|
||||
messageId: 'noAssertions',
|
||||
node
|
||||
}));
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
87
frontend/node_modules/eslint-plugin-jest/lib/rules/max-nested-describe.js
generated
vendored
87
frontend/node_modules/eslint-plugin-jest/lib/rules/max-nested-describe.js
generated
vendored
@@ -1,87 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Enforces a maximum depth to nested describe calls',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
exceededMaxDepth: 'Too many nested describe calls ({{ depth }}). Maximum allowed is {{ max }}.'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
max: {
|
||||
type: 'integer',
|
||||
minimum: 0
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}]
|
||||
},
|
||||
defaultOptions: [{
|
||||
max: 5
|
||||
}],
|
||||
|
||||
create(context, [{
|
||||
max
|
||||
}]) {
|
||||
const describeCallbackStack = [];
|
||||
|
||||
function pushDescribeCallback(node) {
|
||||
const {
|
||||
parent
|
||||
} = node;
|
||||
|
||||
if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression || !(0, _utils.isDescribeCall)(parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
describeCallbackStack.push(0);
|
||||
|
||||
if (describeCallbackStack.length > max) {
|
||||
context.report({
|
||||
node: parent,
|
||||
messageId: 'exceededMaxDepth',
|
||||
data: {
|
||||
depth: describeCallbackStack.length,
|
||||
max
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function popDescribeCallback(node) {
|
||||
const {
|
||||
parent
|
||||
} = node;
|
||||
|
||||
if ((parent === null || parent === void 0 ? void 0 : parent.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isDescribeCall)(parent)) {
|
||||
describeCallbackStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
FunctionExpression: pushDescribeCallback,
|
||||
'FunctionExpression:exit': popDescribeCallback,
|
||||
ArrowFunctionExpression: pushDescribeCallback,
|
||||
'ArrowFunctionExpression:exit': popDescribeCallback
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
77
frontend/node_modules/eslint-plugin-jest/lib/rules/no-alias-methods.js
generated
vendored
77
frontend/node_modules/eslint-plugin-jest/lib/rules/no-alias-methods.js
generated
vendored
@@ -1,77 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow alias methods',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
replaceAlias: `Replace {{ alias }}() with its canonical name of {{ canonical }}()`
|
||||
},
|
||||
fixable: 'code',
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
// map of jest matcher aliases & their canonical names
|
||||
const methodNames = {
|
||||
toBeCalled: 'toHaveBeenCalled',
|
||||
toBeCalledTimes: 'toHaveBeenCalledTimes',
|
||||
toBeCalledWith: 'toHaveBeenCalledWith',
|
||||
lastCalledWith: 'toHaveBeenLastCalledWith',
|
||||
nthCalledWith: 'toHaveBeenNthCalledWith',
|
||||
toReturn: 'toHaveReturned',
|
||||
toReturnTimes: 'toHaveReturnedTimes',
|
||||
toReturnWith: 'toHaveReturnedWith',
|
||||
lastReturnedWith: 'toHaveLastReturnedWith',
|
||||
nthReturnedWith: 'toHaveNthReturnedWith',
|
||||
toThrowError: 'toThrow'
|
||||
};
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
matcher
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (!matcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
const alias = matcher.name;
|
||||
|
||||
if (alias in methodNames) {
|
||||
const canonical = methodNames[alias];
|
||||
context.report({
|
||||
messageId: 'replaceAlias',
|
||||
data: {
|
||||
alias,
|
||||
canonical
|
||||
},
|
||||
node: matcher.node.property,
|
||||
fix: fixer => [fixer.replaceText(matcher.node.property, canonical)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
55
frontend/node_modules/eslint-plugin-jest/lib/rules/no-commented-out-tests.js
generated
vendored
55
frontend/node_modules/eslint-plugin-jest/lib/rules/no-commented-out-tests.js
generated
vendored
@@ -1,55 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
function hasTests(node) {
|
||||
return /^\s*[xf]?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/mu.test(node.value);
|
||||
}
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow commented out tests',
|
||||
recommended: 'warn'
|
||||
},
|
||||
messages: {
|
||||
commentedTests: 'Some tests seem to be commented'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
|
||||
function checkNode(node) {
|
||||
if (!hasTests(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
messageId: 'commentedTests',
|
||||
node
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
Program() {
|
||||
const comments = sourceCode.getAllComments();
|
||||
comments.forEach(checkNode);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
98
frontend/node_modules/eslint-plugin-jest/lib/rules/no-conditional-expect.js
generated
vendored
98
frontend/node_modules/eslint-plugin-jest/lib/rules/no-conditional-expect.js
generated
vendored
@@ -1,98 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const isCatchCall = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(node.callee.property, 'catch');
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent calling `expect` conditionally',
|
||||
category: 'Best Practices',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
conditionalExpect: 'Avoid calling `expect` conditionally`'
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
let conditionalDepth = 0;
|
||||
let inTestCase = false;
|
||||
let inPromiseCatch = false;
|
||||
|
||||
const increaseConditionalDepth = () => inTestCase && conditionalDepth++;
|
||||
|
||||
const decreaseConditionalDepth = () => inTestCase && conditionalDepth--;
|
||||
|
||||
return {
|
||||
FunctionDeclaration(node) {
|
||||
const declaredVariables = context.getDeclaredVariables(node);
|
||||
const testCallExpressions = (0, _utils.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
||||
|
||||
if (testCallExpressions.length > 0) {
|
||||
inTestCase = true;
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isTestCaseCall)(node)) {
|
||||
inTestCase = true;
|
||||
}
|
||||
|
||||
if (isCatchCall(node)) {
|
||||
inPromiseCatch = true;
|
||||
}
|
||||
|
||||
if (inTestCase && (0, _utils.isExpectCall)(node) && conditionalDepth > 0) {
|
||||
context.report({
|
||||
messageId: 'conditionalExpect',
|
||||
node
|
||||
});
|
||||
}
|
||||
|
||||
if (inPromiseCatch && (0, _utils.isExpectCall)(node)) {
|
||||
context.report({
|
||||
messageId: 'conditionalExpect',
|
||||
node
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
if ((0, _utils.isTestCaseCall)(node)) {
|
||||
inTestCase = false;
|
||||
}
|
||||
|
||||
if (isCatchCall(node)) {
|
||||
inPromiseCatch = false;
|
||||
}
|
||||
},
|
||||
|
||||
CatchClause: increaseConditionalDepth,
|
||||
'CatchClause:exit': decreaseConditionalDepth,
|
||||
IfStatement: increaseConditionalDepth,
|
||||
'IfStatement:exit': decreaseConditionalDepth,
|
||||
SwitchStatement: increaseConditionalDepth,
|
||||
'SwitchStatement:exit': decreaseConditionalDepth,
|
||||
ConditionalExpression: increaseConditionalDepth,
|
||||
'ConditionalExpression:exit': decreaseConditionalDepth,
|
||||
LogicalExpression: increaseConditionalDepth,
|
||||
'LogicalExpression:exit': decreaseConditionalDepth
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
103
frontend/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js
generated
vendored
103
frontend/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js
generated
vendored
@@ -1,103 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _detectJestVersion = require("./detectJestVersion");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const parseJestVersion = rawVersion => {
|
||||
if (typeof rawVersion === 'number') {
|
||||
return rawVersion;
|
||||
}
|
||||
|
||||
const [majorVersion] = rawVersion.split('.');
|
||||
return parseInt(majorVersion, 10);
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow use of deprecated functions',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
deprecatedFunction: '`{{ deprecation }}` has been deprecated in favor of `{{ replacement }}`'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: [],
|
||||
fixable: 'code'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
var _context$settings, _context$settings$jes;
|
||||
|
||||
const jestVersion = parseJestVersion(((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || (0, _detectJestVersion.detectJestVersion)());
|
||||
const deprecations = { ...(jestVersion >= 15 && {
|
||||
'jest.resetModuleRegistry': 'jest.resetModules'
|
||||
}),
|
||||
...(jestVersion >= 17 && {
|
||||
'jest.addMatchers': 'expect.extend'
|
||||
}),
|
||||
...(jestVersion >= 21 && {
|
||||
'require.requireMock': 'jest.requireMock',
|
||||
'require.requireActual': 'jest.requireActual'
|
||||
}),
|
||||
...(jestVersion >= 22 && {
|
||||
'jest.runTimersToTime': 'jest.advanceTimersByTime'
|
||||
}),
|
||||
...(jestVersion >= 26 && {
|
||||
'jest.genMockFromModule': 'jest.createMockFromModule'
|
||||
})
|
||||
};
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (node.callee.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
||||
return;
|
||||
}
|
||||
|
||||
const deprecation = (0, _utils.getNodeName)(node);
|
||||
|
||||
if (!deprecation || !(deprecation in deprecations)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const replacement = deprecations[deprecation];
|
||||
const {
|
||||
callee
|
||||
} = node;
|
||||
context.report({
|
||||
messageId: 'deprecatedFunction',
|
||||
data: {
|
||||
deprecation,
|
||||
replacement
|
||||
},
|
||||
node,
|
||||
|
||||
fix(fixer) {
|
||||
let [name, func] = replacement.split('.');
|
||||
|
||||
if (callee.property.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
|
||||
func = `'${func}'`;
|
||||
}
|
||||
|
||||
return [fixer.replaceText(callee.object, name), fixer.replaceText(callee.property, func)];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
135
frontend/node_modules/eslint-plugin-jest/lib/rules/no-disabled-tests.js
generated
vendored
135
frontend/node_modules/eslint-plugin-jest/lib/rules/no-disabled-tests.js
generated
vendored
@@ -1,135 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow disabled tests',
|
||||
recommended: 'warn'
|
||||
},
|
||||
messages: {
|
||||
missingFunction: 'Test is missing function argument',
|
||||
skippedTestSuite: 'Skipped test suite',
|
||||
skippedTest: 'Skipped test',
|
||||
pending: 'Call to pending()',
|
||||
pendingSuite: 'Call to pending() within test suite',
|
||||
pendingTest: 'Call to pending() within test',
|
||||
disabledSuite: 'Disabled test suite',
|
||||
disabledTest: 'Disabled test'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
let suiteDepth = 0;
|
||||
let testDepth = 0;
|
||||
return {
|
||||
'CallExpression[callee.name="describe"]'() {
|
||||
suiteDepth++;
|
||||
},
|
||||
|
||||
'CallExpression[callee.name=/^(it|test)$/]'() {
|
||||
testDepth++;
|
||||
},
|
||||
|
||||
'CallExpression[callee.name=/^(it|test)$/][arguments.length<2]'(node) {
|
||||
context.report({
|
||||
messageId: 'missingFunction',
|
||||
node
|
||||
});
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
const functionName = (0, _utils.getNodeName)(node.callee); // prevent duplicate warnings for it.each()()
|
||||
|
||||
if (node.callee.type === 'CallExpression') {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (functionName) {
|
||||
case 'describe.skip.each':
|
||||
case 'xdescribe.each':
|
||||
case 'describe.skip':
|
||||
context.report({
|
||||
messageId: 'skippedTestSuite',
|
||||
node
|
||||
});
|
||||
break;
|
||||
|
||||
case 'it.skip':
|
||||
case 'it.concurrent.skip':
|
||||
case 'test.skip':
|
||||
case 'test.concurrent.skip':
|
||||
case 'it.skip.each':
|
||||
case 'test.skip.each':
|
||||
case 'xit.each':
|
||||
case 'xtest.each':
|
||||
context.report({
|
||||
messageId: 'skippedTest',
|
||||
node
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression[callee.name="pending"]'(node) {
|
||||
if ((0, _utils.scopeHasLocalReference)(context.getScope(), 'pending')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (testDepth > 0) {
|
||||
context.report({
|
||||
messageId: 'pendingTest',
|
||||
node
|
||||
});
|
||||
} else if (suiteDepth > 0) {
|
||||
context.report({
|
||||
messageId: 'pendingSuite',
|
||||
node
|
||||
});
|
||||
} else {
|
||||
context.report({
|
||||
messageId: 'pending',
|
||||
node
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression[callee.name="xdescribe"]'(node) {
|
||||
context.report({
|
||||
messageId: 'disabledSuite',
|
||||
node
|
||||
});
|
||||
},
|
||||
|
||||
'CallExpression[callee.name=/^(xit|xtest)$/]'(node) {
|
||||
context.report({
|
||||
messageId: 'disabledTest',
|
||||
node
|
||||
});
|
||||
},
|
||||
|
||||
'CallExpression[callee.name="describe"]:exit'() {
|
||||
suiteDepth--;
|
||||
},
|
||||
|
||||
'CallExpression[callee.name=/^(it|test)$/]:exit'() {
|
||||
testDepth--;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
148
frontend/node_modules/eslint-plugin-jest/lib/rules/no-done-callback.js
generated
vendored
148
frontend/node_modules/eslint-plugin-jest/lib/rules/no-done-callback.js
generated
vendored
@@ -1,148 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const findCallbackArg = (node, isJestEach) => {
|
||||
if (isJestEach) {
|
||||
return node.arguments[1];
|
||||
}
|
||||
|
||||
if ((0, _utils.isHook)(node) && node.arguments.length >= 1) {
|
||||
return node.arguments[0];
|
||||
}
|
||||
|
||||
if ((0, _utils.isTestCaseCall)(node) && node.arguments.length >= 2) {
|
||||
return node.arguments[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Avoid using a callback in asynchronous tests and hooks',
|
||||
recommended: 'error',
|
||||
suggestion: true
|
||||
},
|
||||
messages: {
|
||||
noDoneCallback: 'Return a Promise instead of relying on callback parameter',
|
||||
suggestWrappingInPromise: 'Wrap in `new Promise({{ callback }} => ...`',
|
||||
useAwaitInsteadOfCallback: 'Use await instead of callback in async functions'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion',
|
||||
hasSuggestions: true
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
var _getNodeName$endsWith, _getNodeName;
|
||||
|
||||
// done is the second argument for it.each, not the first
|
||||
const isJestEach = (_getNodeName$endsWith = (_getNodeName = (0, _utils.getNodeName)(node.callee)) === null || _getNodeName === void 0 ? void 0 : _getNodeName.endsWith('.each')) !== null && _getNodeName$endsWith !== void 0 ? _getNodeName$endsWith : false;
|
||||
|
||||
if (isJestEach && node.callee.type !== _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
||||
// isJestEach but not a TaggedTemplateExpression, so this must be
|
||||
// the `jest.each([])()` syntax which this rule doesn't support due
|
||||
// to its complexity (see jest-community/eslint-plugin-jest#710)
|
||||
return;
|
||||
}
|
||||
|
||||
const callback = findCallbackArg(node, isJestEach);
|
||||
const callbackArgIndex = Number(isJestEach);
|
||||
|
||||
if (!callback || !(0, _utils.isFunction)(callback) || callback.params.length !== 1 + callbackArgIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
const argument = callback.params[callbackArgIndex];
|
||||
|
||||
if (argument.type !== _experimentalUtils.AST_NODE_TYPES.Identifier) {
|
||||
context.report({
|
||||
node: argument,
|
||||
messageId: 'noDoneCallback'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback.async) {
|
||||
context.report({
|
||||
node: argument,
|
||||
messageId: 'useAwaitInsteadOfCallback'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node: argument,
|
||||
messageId: 'noDoneCallback',
|
||||
suggest: [{
|
||||
messageId: 'suggestWrappingInPromise',
|
||||
data: {
|
||||
callback: argument.name
|
||||
},
|
||||
|
||||
fix(fixer) {
|
||||
const {
|
||||
body
|
||||
} = callback;
|
||||
const sourceCode = context.getSourceCode();
|
||||
const firstBodyToken = sourceCode.getFirstToken(body);
|
||||
const lastBodyToken = sourceCode.getLastToken(body);
|
||||
const tokenBeforeArgument = sourceCode.getTokenBefore(argument);
|
||||
const tokenAfterArgument = sourceCode.getTokenAfter(argument);
|
||||
/* istanbul ignore if */
|
||||
|
||||
if (!firstBodyToken || !lastBodyToken || !tokenBeforeArgument || !tokenAfterArgument) {
|
||||
throw new Error(`Unexpected null when attempting to fix ${context.getFilename()} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`);
|
||||
}
|
||||
|
||||
const argumentInParens = tokenBeforeArgument.value === '(' && tokenAfterArgument.value === ')';
|
||||
let argumentFix = fixer.replaceText(argument, '()');
|
||||
|
||||
if (argumentInParens) {
|
||||
argumentFix = fixer.remove(argument);
|
||||
}
|
||||
|
||||
let newCallback = argument.name;
|
||||
|
||||
if (argumentInParens) {
|
||||
newCallback = `(${newCallback})`;
|
||||
}
|
||||
|
||||
let beforeReplacement = `new Promise(${newCallback} => `;
|
||||
let afterReplacement = ')';
|
||||
let replaceBefore = true;
|
||||
|
||||
if (body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
|
||||
const keyword = 'return';
|
||||
beforeReplacement = `${keyword} ${beforeReplacement}{`;
|
||||
afterReplacement += '}';
|
||||
replaceBefore = false;
|
||||
}
|
||||
|
||||
return [argumentFix, replaceBefore ? fixer.insertTextBefore(firstBodyToken, beforeReplacement) : fixer.insertTextAfter(firstBodyToken, beforeReplacement), fixer.insertTextAfter(lastBodyToken, afterReplacement)];
|
||||
}
|
||||
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
68
frontend/node_modules/eslint-plugin-jest/lib/rules/no-duplicate-hooks.js
generated
vendored
68
frontend/node_modules/eslint-plugin-jest/lib/rules/no-duplicate-hooks.js
generated
vendored
@@ -1,68 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const newHookContext = () => ({
|
||||
beforeAll: 0,
|
||||
beforeEach: 0,
|
||||
afterAll: 0,
|
||||
afterEach: 0
|
||||
});
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow duplicate setup and teardown hooks',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
noDuplicateHook: 'Duplicate {{hook}} in describe block'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
const hookContexts = [newHookContext()];
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
hookContexts.push(newHookContext());
|
||||
}
|
||||
|
||||
if ((0, _utils.isHook)(node)) {
|
||||
const currentLayer = hookContexts[hookContexts.length - 1];
|
||||
currentLayer[node.callee.name] += 1;
|
||||
|
||||
if (currentLayer[node.callee.name] > 1) {
|
||||
context.report({
|
||||
messageId: 'noDuplicateHook',
|
||||
data: {
|
||||
hook: node.callee.name
|
||||
},
|
||||
node
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
hookContexts.pop();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
76
frontend/node_modules/eslint-plugin-jest/lib/rules/no-export.js
generated
vendored
76
frontend/node_modules/eslint-plugin-jest/lib/rules/no-export.js
generated
vendored
@@ -1,76 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow using `exports` in files containing tests',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
unexpectedExport: `Do not export from a test file.`
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
const exportNodes = [];
|
||||
let hasTestCase = false;
|
||||
return {
|
||||
'Program:exit'() {
|
||||
if (hasTestCase && exportNodes.length > 0) {
|
||||
for (const node of exportNodes) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedExport'
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isTestCaseCall)(node)) {
|
||||
hasTestCase = true;
|
||||
}
|
||||
},
|
||||
|
||||
'ExportNamedDeclaration, ExportDefaultDeclaration'(node) {
|
||||
exportNodes.push(node);
|
||||
},
|
||||
|
||||
'AssignmentExpression > MemberExpression'(node) {
|
||||
let {
|
||||
object,
|
||||
property
|
||||
} = node;
|
||||
|
||||
if (object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
||||
({
|
||||
object,
|
||||
property
|
||||
} = object);
|
||||
}
|
||||
|
||||
if ('name' in object && object.name === 'module' && property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && /^exports?$/u.test(property.name)) {
|
||||
exportNodes.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
85
frontend/node_modules/eslint-plugin-jest/lib/rules/no-focused-tests.js
generated
vendored
85
frontend/node_modules/eslint-plugin-jest/lib/rules/no-focused-tests.js
generated
vendored
@@ -1,85 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const findOnlyNode = node => {
|
||||
const callee = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
||||
|
||||
if (callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
||||
if (callee.object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
||||
if ((0, _utils.isSupportedAccessor)(callee.object.property, 'only')) {
|
||||
return callee.object.property;
|
||||
}
|
||||
}
|
||||
|
||||
if ((0, _utils.isSupportedAccessor)(callee.property, 'only')) {
|
||||
return callee.property;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow focused tests',
|
||||
recommended: 'error',
|
||||
suggestion: true
|
||||
},
|
||||
messages: {
|
||||
focusedTest: 'Unexpected focused test.',
|
||||
suggestRemoveFocus: 'Remove focus from test.'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion',
|
||||
hasSuggestions: true
|
||||
},
|
||||
defaultOptions: [],
|
||||
create: context => ({
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isDescribeCall)(node) && !(0, _utils.isTestCaseCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((0, _utils.getNodeName)(node).startsWith('f')) {
|
||||
context.report({
|
||||
messageId: 'focusedTest',
|
||||
node,
|
||||
suggest: [{
|
||||
messageId: 'suggestRemoveFocus',
|
||||
fix: fixer => fixer.removeRange([node.range[0], node.range[0] + 1])
|
||||
}]
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const onlyNode = findOnlyNode(node);
|
||||
|
||||
if (!onlyNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
messageId: 'focusedTest',
|
||||
node: onlyNode,
|
||||
suggest: [{
|
||||
messageId: 'suggestRemoveFocus',
|
||||
fix: fixer => fixer.removeRange([onlyNode.range[0] - 1, onlyNode.range[1] + Number(onlyNode.type !== _experimentalUtils.AST_NODE_TYPES.Identifier)])
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
58
frontend/node_modules/eslint-plugin-jest/lib/rules/no-hooks.js
generated
vendored
58
frontend/node_modules/eslint-plugin-jest/lib/rules/no-hooks.js
generated
vendored
@@ -1,58 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow setup and teardown hooks',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
unexpectedHook: "Unexpected '{{ hookName }}' hook"
|
||||
},
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
allow: {
|
||||
type: 'array',
|
||||
contains: ['beforeAll', 'beforeEach', 'afterAll', 'afterEach']
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [{
|
||||
allow: []
|
||||
}],
|
||||
|
||||
create(context, [{
|
||||
allow = []
|
||||
}]) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isHook)(node) && !allow.includes(node.callee.name)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedHook',
|
||||
data: {
|
||||
hookName: node.callee.name
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
92
frontend/node_modules/eslint-plugin-jest/lib/rules/no-identical-title.js
generated
vendored
92
frontend/node_modules/eslint-plugin-jest/lib/rules/no-identical-title.js
generated
vendored
@@ -1,92 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const newDescribeContext = () => ({
|
||||
describeTitles: [],
|
||||
testTitles: []
|
||||
});
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow identical titles',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
multipleTestTitle: 'Test title is used multiple times in the same describe block.',
|
||||
multipleDescribeTitle: 'Describe block title is used multiple times in the same describe block.'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
const contexts = [newDescribeContext()];
|
||||
return {
|
||||
CallExpression(node) {
|
||||
var _getNodeName;
|
||||
|
||||
const currentLayer = contexts[contexts.length - 1];
|
||||
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
contexts.push(newDescribeContext());
|
||||
}
|
||||
|
||||
if ((_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 && _getNodeName.endsWith('.each')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [argument] = node.arguments;
|
||||
|
||||
if (!argument || !(0, _utils.isStringNode)(argument)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const title = (0, _utils.getStringValue)(argument);
|
||||
|
||||
if ((0, _utils.isTestCaseCall)(node)) {
|
||||
if (currentLayer.testTitles.includes(title)) {
|
||||
context.report({
|
||||
messageId: 'multipleTestTitle',
|
||||
node: argument
|
||||
});
|
||||
}
|
||||
|
||||
currentLayer.testTitles.push(title);
|
||||
}
|
||||
|
||||
if (!(0, _utils.isDescribeCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLayer.describeTitles.includes(title)) {
|
||||
context.report({
|
||||
messageId: 'multipleDescribeTitle',
|
||||
node: argument
|
||||
});
|
||||
}
|
||||
|
||||
currentLayer.describeTitles.push(title);
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
contexts.pop();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
107
frontend/node_modules/eslint-plugin-jest/lib/rules/no-if.js
generated
vendored
107
frontend/node_modules/eslint-plugin-jest/lib/rules/no-if.js
generated
vendored
@@ -1,107 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const testCaseNames = new Set([...Object.keys(_utils.TestCaseName), 'it.only', 'it.concurrent.only', 'it.skip', 'it.concurrent.skip', 'test.only', 'test.concurrent.only', 'test.skip', 'test.concurrent.skip', 'fit.concurrent']);
|
||||
|
||||
const isTestFunctionExpression = node => node.parent !== undefined && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils.getNodeName)(node.parent.callee));
|
||||
|
||||
const conditionName = {
|
||||
[_experimentalUtils.AST_NODE_TYPES.ConditionalExpression]: 'conditional',
|
||||
[_experimentalUtils.AST_NODE_TYPES.SwitchStatement]: 'switch',
|
||||
[_experimentalUtils.AST_NODE_TYPES.IfStatement]: 'if'
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Disallow conditional logic',
|
||||
category: 'Best Practices',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
conditionalInTest: 'Test should not contain {{ condition }} statements.'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
const stack = [];
|
||||
|
||||
function validate(node) {
|
||||
const lastElementInStack = stack[stack.length - 1];
|
||||
|
||||
if (stack.length === 0 || !lastElementInStack) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
data: {
|
||||
condition: conditionName[node.type]
|
||||
},
|
||||
messageId: 'conditionalInTest',
|
||||
node
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isTestCaseCall)(node)) {
|
||||
stack.push(true);
|
||||
|
||||
if ((0, _utils.getNodeName)(node).endsWith('each')) {
|
||||
stack.push(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
FunctionExpression(node) {
|
||||
stack.push(isTestFunctionExpression(node));
|
||||
},
|
||||
|
||||
FunctionDeclaration(node) {
|
||||
const declaredVariables = context.getDeclaredVariables(node);
|
||||
const testCallExpressions = (0, _utils.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
||||
stack.push(testCallExpressions.length > 0);
|
||||
},
|
||||
|
||||
ArrowFunctionExpression(node) {
|
||||
stack.push(isTestFunctionExpression(node));
|
||||
},
|
||||
|
||||
IfStatement: validate,
|
||||
SwitchStatement: validate,
|
||||
ConditionalExpression: validate,
|
||||
|
||||
'CallExpression:exit'() {
|
||||
stack.pop();
|
||||
},
|
||||
|
||||
'FunctionExpression:exit'() {
|
||||
stack.pop();
|
||||
},
|
||||
|
||||
'FunctionDeclaration:exit'() {
|
||||
stack.pop();
|
||||
},
|
||||
|
||||
'ArrowFunctionExpression:exit'() {
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
63
frontend/node_modules/eslint-plugin-jest/lib/rules/no-interpolation-in-snapshots.js
generated
vendored
63
frontend/node_modules/eslint-plugin-jest/lib/rules/no-interpolation-in-snapshots.js
generated
vendored
@@ -1,63 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow string interpolation inside snapshots',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
noInterpolation: 'Do not use string interpolation inside of snapshots'
|
||||
},
|
||||
schema: [],
|
||||
type: 'problem'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
matcher
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (!matcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name)) {
|
||||
var _matcher$arguments;
|
||||
|
||||
// Check all since the optional 'propertyMatchers' argument might be present
|
||||
(_matcher$arguments = matcher.arguments) === null || _matcher$arguments === void 0 ? void 0 : _matcher$arguments.forEach(argument => {
|
||||
if (argument.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && argument.expressions.length > 0) {
|
||||
context.report({
|
||||
messageId: 'noInterpolation',
|
||||
node: argument
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
165
frontend/node_modules/eslint-plugin-jest/lib/rules/no-jasmine-globals.js
generated
vendored
165
frontend/node_modules/eslint-plugin-jest/lib/rules/no-jasmine-globals.js
generated
vendored
@@ -1,165 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow Jasmine globals',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
illegalGlobal: 'Illegal usage of global `{{ global }}`, prefer `{{ replacement }}`',
|
||||
illegalMethod: 'Illegal usage of `{{ method }}`, prefer `{{ replacement }}`',
|
||||
illegalFail: 'Illegal usage of `fail`, prefer throwing an error, or the `done.fail` callback',
|
||||
illegalPending: 'Illegal usage of `pending`, prefer explicitly skipping a test using `test.skip`',
|
||||
illegalJasmine: 'Illegal usage of jasmine global'
|
||||
},
|
||||
fixable: 'code',
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
const {
|
||||
callee
|
||||
} = node;
|
||||
const calleeName = (0, _utils.getNodeName)(callee);
|
||||
|
||||
if (!calleeName) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (calleeName === 'spyOn' || calleeName === 'spyOnProperty' || calleeName === 'fail' || calleeName === 'pending') {
|
||||
if ((0, _utils.scopeHasLocalReference)(context.getScope(), calleeName)) {
|
||||
// It's a local variable, not a jasmine global.
|
||||
return;
|
||||
}
|
||||
|
||||
switch (calleeName) {
|
||||
case 'spyOn':
|
||||
case 'spyOnProperty':
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'illegalGlobal',
|
||||
data: {
|
||||
global: calleeName,
|
||||
replacement: 'jest.spyOn'
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'fail':
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'illegalFail'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'pending':
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'illegalPending'
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && calleeName.startsWith('jasmine.')) {
|
||||
const functionName = calleeName.replace('jasmine.', '');
|
||||
|
||||
if (functionName === 'any' || functionName === 'anything' || functionName === 'arrayContaining' || functionName === 'objectContaining' || functionName === 'stringMatching') {
|
||||
context.report({
|
||||
fix: fixer => [fixer.replaceText(callee.object, 'expect')],
|
||||
node,
|
||||
messageId: 'illegalMethod',
|
||||
data: {
|
||||
method: calleeName,
|
||||
replacement: `expect.${functionName}`
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (functionName === 'addMatchers') {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'illegalMethod',
|
||||
data: {
|
||||
method: calleeName,
|
||||
replacement: 'expect.extend'
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (functionName === 'createSpy') {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'illegalMethod',
|
||||
data: {
|
||||
method: calleeName,
|
||||
replacement: 'jest.fn'
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'illegalJasmine'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
MemberExpression(node) {
|
||||
if ((0, _utils.isSupportedAccessor)(node.object, 'jasmine')) {
|
||||
const {
|
||||
parent,
|
||||
property
|
||||
} = node;
|
||||
|
||||
if (parent && parent.type === _experimentalUtils.AST_NODE_TYPES.AssignmentExpression) {
|
||||
if ((0, _utils.isSupportedAccessor)(property, 'DEFAULT_TIMEOUT_INTERVAL')) {
|
||||
const {
|
||||
right
|
||||
} = parent;
|
||||
|
||||
if (right.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
|
||||
context.report({
|
||||
fix: fixer => [fixer.replaceText(parent, `jest.setTimeout(${right.value})`)],
|
||||
node,
|
||||
messageId: 'illegalJasmine'
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'illegalJasmine'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
48
frontend/node_modules/eslint-plugin-jest/lib/rules/no-jest-import.js
generated
vendored
48
frontend/node_modules/eslint-plugin-jest/lib/rules/no-jest-import.js
generated
vendored
@@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow importing Jest',
|
||||
category: 'Best Practices',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
unexpectedImport: `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`
|
||||
},
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
'ImportDeclaration[source.value="jest"]'(node) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedImport'
|
||||
});
|
||||
},
|
||||
|
||||
'CallExpression[callee.name="require"][arguments.0.value="jest"]'(node) {
|
||||
context.report({
|
||||
loc: node.arguments[0].loc,
|
||||
messageId: 'unexpectedImport',
|
||||
node
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
131
frontend/node_modules/eslint-plugin-jest/lib/rules/no-large-snapshots.js
generated
vendored
131
frontend/node_modules/eslint-plugin-jest/lib/rules/no-large-snapshots.js
generated
vendored
@@ -1,131 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _path = require("path");
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const reportOnViolation = (context, node, {
|
||||
maxSize: lineLimit = 50,
|
||||
allowedSnapshots = {}
|
||||
}) => {
|
||||
const startLine = node.loc.start.line;
|
||||
const endLine = node.loc.end.line;
|
||||
const lineCount = endLine - startLine;
|
||||
const allPathsAreAbsolute = Object.keys(allowedSnapshots).every(_path.isAbsolute);
|
||||
|
||||
if (!allPathsAreAbsolute) {
|
||||
throw new Error('All paths for allowedSnapshots must be absolute. You can use JS config and `path.resolve`');
|
||||
}
|
||||
|
||||
let isAllowed = false;
|
||||
|
||||
if (node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement && 'left' in node.expression && (0, _utils.isExpectMember)(node.expression.left)) {
|
||||
const fileName = context.getFilename();
|
||||
const allowedSnapshotsInFile = allowedSnapshots[fileName];
|
||||
|
||||
if (allowedSnapshotsInFile) {
|
||||
const snapshotName = (0, _utils.getAccessorValue)(node.expression.left.property);
|
||||
isAllowed = allowedSnapshotsInFile.some(name => {
|
||||
if (name instanceof RegExp) {
|
||||
return name.test(snapshotName);
|
||||
}
|
||||
|
||||
return snapshotName === name;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAllowed && lineCount > lineLimit) {
|
||||
context.report({
|
||||
messageId: lineLimit === 0 ? 'noSnapshot' : 'tooLongSnapshots',
|
||||
data: {
|
||||
lineLimit,
|
||||
lineCount
|
||||
},
|
||||
node
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'disallow large snapshots',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
noSnapshot: '`{{ lineCount }}`s should begin with lowercase',
|
||||
tooLongSnapshots: 'Expected Jest snapshot to be smaller than {{ lineLimit }} lines but was {{ lineCount }} lines long'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
maxSize: {
|
||||
type: 'number'
|
||||
},
|
||||
inlineMaxSize: {
|
||||
type: 'number'
|
||||
},
|
||||
allowedSnapshots: {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'array'
|
||||
}
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}]
|
||||
},
|
||||
defaultOptions: [{}],
|
||||
|
||||
create(context, [options]) {
|
||||
if (context.getFilename().endsWith('.snap')) {
|
||||
return {
|
||||
ExpressionStatement(node) {
|
||||
reportOnViolation(context, node, options);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
CallExpression(node) {
|
||||
var _matcher$arguments;
|
||||
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
matcher
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if ((matcher === null || matcher === void 0 ? void 0 : matcher.node.parent.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name) && (_matcher$arguments = matcher.arguments) !== null && _matcher$arguments !== void 0 && _matcher$arguments.length) {
|
||||
var _options$inlineMaxSiz;
|
||||
|
||||
reportOnViolation(context, matcher.arguments[0], { ...options,
|
||||
maxSize: (_options$inlineMaxSiz = options.inlineMaxSize) !== null && _options$inlineMaxSiz !== void 0 ? _options$inlineMaxSiz : options.maxSize
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
61
frontend/node_modules/eslint-plugin-jest/lib/rules/no-mocks-import.js
generated
vendored
61
frontend/node_modules/eslint-plugin-jest/lib/rules/no-mocks-import.js
generated
vendored
@@ -1,61 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _path = require("path");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const mocksDirName = '__mocks__';
|
||||
|
||||
const isMockPath = path => path.split(_path.posix.sep).includes(mocksDirName);
|
||||
|
||||
const isMockImportLiteral = expression => (0, _utils.isStringNode)(expression) && isMockPath((0, _utils.getStringValue)(expression));
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow manually importing from `__mocks__`',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
noManualImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`jest.mock\` and import from the original module path.`
|
||||
},
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
ImportDeclaration(node) {
|
||||
if (isMockImportLiteral(node.source)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noManualImport'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression[callee.name="require"]'(node) {
|
||||
const [arg] = node.arguments;
|
||||
|
||||
if (arg && isMockImportLiteral(arg)) {
|
||||
context.report({
|
||||
node: arg,
|
||||
messageId: 'noManualImport'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
104
frontend/node_modules/eslint-plugin-jest/lib/rules/no-restricted-matchers.js
generated
vendored
104
frontend/node_modules/eslint-plugin-jest/lib/rules/no-restricted-matchers.js
generated
vendored
@@ -1,104 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow specific matchers & modifiers',
|
||||
recommended: false
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: [{
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: ['string', 'null']
|
||||
}
|
||||
}],
|
||||
messages: {
|
||||
restrictedChain: 'Use of `{{ chain }}` is disallowed',
|
||||
restrictedChainWithMessage: '{{ message }}'
|
||||
}
|
||||
},
|
||||
defaultOptions: [{}],
|
||||
|
||||
create(context, [restrictedChains]) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
matcher,
|
||||
modifier
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (matcher) {
|
||||
const chain = matcher.name;
|
||||
|
||||
if (chain in restrictedChains) {
|
||||
const message = restrictedChains[chain];
|
||||
context.report({
|
||||
messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
||||
data: {
|
||||
message,
|
||||
chain
|
||||
},
|
||||
node: matcher.node.property
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (modifier) {
|
||||
const chain = modifier.name;
|
||||
|
||||
if (chain in restrictedChains) {
|
||||
const message = restrictedChains[chain];
|
||||
context.report({
|
||||
messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
||||
data: {
|
||||
message,
|
||||
chain
|
||||
},
|
||||
node: modifier.node.property
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (matcher && modifier) {
|
||||
const chain = `${modifier.name}.${matcher.name}`;
|
||||
|
||||
if (chain in restrictedChains) {
|
||||
const message = restrictedChains[chain];
|
||||
context.report({
|
||||
messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
||||
data: {
|
||||
message,
|
||||
chain
|
||||
},
|
||||
loc: {
|
||||
start: modifier.node.property.loc.start,
|
||||
end: matcher.node.property.loc.end
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
143
frontend/node_modules/eslint-plugin-jest/lib/rules/no-standalone-expect.js
generated
vendored
143
frontend/node_modules/eslint-plugin-jest/lib/rules/no-standalone-expect.js
generated
vendored
@@ -1,143 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const getBlockType = statement => {
|
||||
const func = statement.parent;
|
||||
/* istanbul ignore if */
|
||||
|
||||
if (!func) {
|
||||
throw new Error(`Unexpected BlockStatement. No parent defined. - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`);
|
||||
} // functionDeclaration: function func() {}
|
||||
|
||||
|
||||
if (func.type === _experimentalUtils.AST_NODE_TYPES.FunctionDeclaration) {
|
||||
return 'function';
|
||||
}
|
||||
|
||||
if ((0, _utils.isFunction)(func) && func.parent) {
|
||||
const expr = func.parent; // arrow function or function expr
|
||||
|
||||
if (expr.type === _experimentalUtils.AST_NODE_TYPES.VariableDeclarator) {
|
||||
return 'function';
|
||||
} // if it's not a variable, it will be callExpr, we only care about describe
|
||||
|
||||
|
||||
if (expr.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isDescribeCall)(expr)) {
|
||||
return 'describe';
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow using `expect` outside of `it` or `test` blocks',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
unexpectedExpect: 'Expect must be inside of a test block.'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: [{
|
||||
properties: {
|
||||
additionalTestBlockFunctions: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}]
|
||||
},
|
||||
defaultOptions: [{
|
||||
additionalTestBlockFunctions: []
|
||||
}],
|
||||
|
||||
create(context, [{
|
||||
additionalTestBlockFunctions = []
|
||||
}]) {
|
||||
const callStack = [];
|
||||
|
||||
const isCustomTestBlockFunction = node => additionalTestBlockFunctions.includes((0, _utils.getNodeName)(node) || '');
|
||||
|
||||
const isTestBlock = node => (0, _utils.isTestCaseCall)(node) || isCustomTestBlockFunction(node);
|
||||
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isExpectCall)(node)) {
|
||||
const parent = callStack[callStack.length - 1];
|
||||
|
||||
if (!parent || parent === _utils.DescribeAlias.describe) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedExpect'
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTestBlock(node)) {
|
||||
callStack.push('test');
|
||||
}
|
||||
|
||||
if (node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
||||
callStack.push('template');
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
const top = callStack[callStack.length - 1];
|
||||
|
||||
if (top === 'test' && isTestBlock(node) && node.callee.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression || top === 'template' && node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
||||
callStack.pop();
|
||||
}
|
||||
},
|
||||
|
||||
BlockStatement(statement) {
|
||||
const blockType = getBlockType(statement);
|
||||
|
||||
if (blockType) {
|
||||
callStack.push(blockType);
|
||||
}
|
||||
},
|
||||
|
||||
'BlockStatement:exit'(statement) {
|
||||
if (callStack[callStack.length - 1] === getBlockType(statement)) {
|
||||
callStack.pop();
|
||||
}
|
||||
},
|
||||
|
||||
ArrowFunctionExpression(node) {
|
||||
var _node$parent;
|
||||
|
||||
if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression) {
|
||||
callStack.push('arrow');
|
||||
}
|
||||
},
|
||||
|
||||
'ArrowFunctionExpression:exit'() {
|
||||
if (callStack[callStack.length - 1] === 'arrow') {
|
||||
callStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
71
frontend/node_modules/eslint-plugin-jest/lib/rules/no-test-prefixes.js
generated
vendored
71
frontend/node_modules/eslint-plugin-jest/lib/rules/no-test-prefixes.js
generated
vendored
@@ -1,71 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Use `.only` and `.skip` over `f` and `x`',
|
||||
recommended: 'error'
|
||||
},
|
||||
messages: {
|
||||
usePreferredName: 'Use "{{ preferredNodeName }}" instead'
|
||||
},
|
||||
fixable: 'code',
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
const nodeName = (0, _utils.getNodeName)(node.callee);
|
||||
if (!nodeName || !(0, _utils.isDescribeCall)(node) && !(0, _utils.isTestCaseCall)(node)) return;
|
||||
const preferredNodeName = getPreferredNodeName(nodeName);
|
||||
if (!preferredNodeName) return;
|
||||
const funcNode = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
||||
context.report({
|
||||
messageId: 'usePreferredName',
|
||||
node: node.callee,
|
||||
data: {
|
||||
preferredNodeName
|
||||
},
|
||||
|
||||
fix(fixer) {
|
||||
return [fixer.replaceText(funcNode, preferredNodeName)];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
|
||||
function getPreferredNodeName(nodeName) {
|
||||
const firstChar = nodeName.charAt(0);
|
||||
const suffix = nodeName.endsWith('.each') ? '.each' : '';
|
||||
|
||||
if (firstChar === 'f') {
|
||||
return `${nodeName.slice(1).replace('.each', '')}.only${suffix}`;
|
||||
}
|
||||
|
||||
if (firstChar === 'x') {
|
||||
return `${nodeName.slice(1).replace('.each', '')}.skip${suffix}`;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
68
frontend/node_modules/eslint-plugin-jest/lib/rules/no-test-return-statement.js
generated
vendored
68
frontend/node_modules/eslint-plugin-jest/lib/rules/no-test-return-statement.js
generated
vendored
@@ -1,68 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const getBody = args => {
|
||||
const [, secondArg] = args;
|
||||
|
||||
if (secondArg && (0, _utils.isFunction)(secondArg) && secondArg.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
|
||||
return secondArg.body.body;
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Disallow explicitly returning from tests',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
noReturnValue: 'Jest tests should not return a value.'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isTestCaseCall)(node)) return;
|
||||
const body = getBody(node.arguments);
|
||||
const returnStmt = body.find(t => t.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement);
|
||||
if (!returnStmt) return;
|
||||
context.report({
|
||||
messageId: 'noReturnValue',
|
||||
node: returnStmt
|
||||
});
|
||||
},
|
||||
|
||||
FunctionDeclaration(node) {
|
||||
const declaredVariables = context.getDeclaredVariables(node);
|
||||
const testCallExpressions = (0, _utils.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
||||
if (testCallExpressions.length === 0) return;
|
||||
const returnStmt = node.body.body.find(t => t.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement);
|
||||
if (!returnStmt) return;
|
||||
context.report({
|
||||
messageId: 'noReturnValue',
|
||||
node: returnStmt
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
57
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-called-with.js
generated
vendored
57
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-called-with.js
generated
vendored
@@ -1,57 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()`',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
preferCalledWith: 'Prefer {{name}}With(/* expected args */)'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
modifier,
|
||||
matcher
|
||||
} = (0, _utils.parseExpectCall)(node); // Could check resolves/rejects here but not a likely idiom.
|
||||
|
||||
if (matcher && !modifier) {
|
||||
if (['toBeCalled', 'toHaveBeenCalled'].includes(matcher.name)) {
|
||||
context.report({
|
||||
data: {
|
||||
name: matcher.name
|
||||
},
|
||||
// todo: rename to 'matcherName'
|
||||
messageId: 'preferCalledWith',
|
||||
node: matcher.node.property
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
139
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-comparison-matcher.js
generated
vendored
139
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-comparison-matcher.js
generated
vendored
@@ -1,139 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const isBooleanLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
|
||||
|
||||
/**
|
||||
* Checks if the given `ParsedExpectMatcher` is a call to one of the equality matchers,
|
||||
* with a boolean literal as the sole argument.
|
||||
*
|
||||
* @example javascript
|
||||
* toBe(true);
|
||||
* toEqual(false);
|
||||
*
|
||||
* @param {ParsedExpectMatcher} matcher
|
||||
*
|
||||
* @return {matcher is ParsedBooleanEqualityMatcher}
|
||||
*/
|
||||
const isBooleanEqualityMatcher = matcher => (0, _utils.isParsedEqualityMatcherCall)(matcher) && isBooleanLiteral((0, _utils.followTypeAssertionChain)(matcher.arguments[0]));
|
||||
|
||||
const isString = node => {
|
||||
return (0, _utils.isStringNode)(node) || node.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral;
|
||||
};
|
||||
|
||||
const isComparingToString = expression => {
|
||||
return isString(expression.left) || isString(expression.right);
|
||||
};
|
||||
|
||||
const invertOperator = operator => {
|
||||
switch (operator) {
|
||||
case '>':
|
||||
return '<=';
|
||||
|
||||
case '<':
|
||||
return '>=';
|
||||
|
||||
case '>=':
|
||||
return '<';
|
||||
|
||||
case '<=':
|
||||
return '>';
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const determineMatcher = (operator, negated) => {
|
||||
const op = negated ? invertOperator(operator) : operator;
|
||||
|
||||
switch (op) {
|
||||
case '>':
|
||||
return 'toBeGreaterThan';
|
||||
|
||||
case '<':
|
||||
return 'toBeLessThan';
|
||||
|
||||
case '>=':
|
||||
return 'toBeGreaterThanOrEqual';
|
||||
|
||||
case '<=':
|
||||
return 'toBeLessThanOrEqual';
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using the built-in comparison matchers',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
useToBeComparison: 'Prefer using `{{ preferredMatcher }}` instead'
|
||||
},
|
||||
fixable: 'code',
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
expect: {
|
||||
arguments: [comparison],
|
||||
range: [, expectCallEnd]
|
||||
},
|
||||
matcher,
|
||||
modifier
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (!matcher || (comparison === null || comparison === void 0 ? void 0 : comparison.type) !== _experimentalUtils.AST_NODE_TYPES.BinaryExpression || isComparingToString(comparison) || !isBooleanEqualityMatcher(matcher)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const preferredMatcher = determineMatcher(comparison.operator, (0, _utils.followTypeAssertionChain)(matcher.arguments[0]).value === !!modifier);
|
||||
|
||||
if (!preferredMatcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
fix(fixer) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
return [// replace the comparison argument with the left-hand side of the comparison
|
||||
fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
|
||||
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], `.${preferredMatcher}`), // replace the matcher argument with the right-hand side of the comparison
|
||||
fixer.replaceText(matcher.arguments[0], sourceCode.getText(comparison.right))];
|
||||
},
|
||||
|
||||
messageId: 'useToBeComparison',
|
||||
data: {
|
||||
preferredMatcher
|
||||
},
|
||||
node: (modifier || matcher).node.property
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
98
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-equality-matcher.js
generated
vendored
98
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-equality-matcher.js
generated
vendored
@@ -1,98 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const isBooleanLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
|
||||
|
||||
/**
|
||||
* Checks if the given `ParsedExpectMatcher` is a call to one of the equality matchers,
|
||||
* with a boolean literal as the sole argument.
|
||||
*
|
||||
* @example javascript
|
||||
* toBe(true);
|
||||
* toEqual(false);
|
||||
*
|
||||
* @param {ParsedExpectMatcher} matcher
|
||||
*
|
||||
* @return {matcher is ParsedBooleanEqualityMatcher}
|
||||
*/
|
||||
const isBooleanEqualityMatcher = matcher => (0, _utils.isParsedEqualityMatcherCall)(matcher) && isBooleanLiteral((0, _utils.followTypeAssertionChain)(matcher.arguments[0]));
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using the built-in equality matchers',
|
||||
recommended: false,
|
||||
suggestion: true
|
||||
},
|
||||
messages: {
|
||||
useEqualityMatcher: 'Prefer using one of the equality matchers instead',
|
||||
suggestEqualityMatcher: 'Use `{{ equalityMatcher }}`'
|
||||
},
|
||||
hasSuggestions: true,
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
expect: {
|
||||
arguments: [comparison],
|
||||
range: [, expectCallEnd]
|
||||
},
|
||||
matcher,
|
||||
modifier
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (!matcher || (comparison === null || comparison === void 0 ? void 0 : comparison.type) !== _experimentalUtils.AST_NODE_TYPES.BinaryExpression || comparison.operator !== '===' && comparison.operator !== '!==' || !isBooleanEqualityMatcher(matcher)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const matcherValue = (0, _utils.followTypeAssertionChain)(matcher.arguments[0]).value; // we need to negate the expectation if the current expected
|
||||
// value is itself negated by the "not" modifier
|
||||
|
||||
const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === !!modifier;
|
||||
|
||||
const buildFixer = equalityMatcher => fixer => {
|
||||
const sourceCode = context.getSourceCode();
|
||||
return [// replace the comparison argument with the left-hand side of the comparison
|
||||
fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
|
||||
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${_utils.ModifierName.not}.${equalityMatcher}` : `.${equalityMatcher}`), // replace the matcher argument with the right-hand side of the comparison
|
||||
fixer.replaceText(matcher.arguments[0], sourceCode.getText(comparison.right))];
|
||||
};
|
||||
|
||||
context.report({
|
||||
messageId: 'useEqualityMatcher',
|
||||
suggest: ['toBe', 'toEqual', 'toStrictEqual'].map(equalityMatcher => ({
|
||||
messageId: 'suggestEqualityMatcher',
|
||||
data: {
|
||||
equalityMatcher
|
||||
},
|
||||
fix: buildFixer(equalityMatcher)
|
||||
})),
|
||||
node: (modifier || matcher).node.property
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
232
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-expect-assertions.js
generated
vendored
232
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-expect-assertions.js
generated
vendored
@@ -1,232 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const isExpectAssertionsOrHasAssertionsCall = expression => expression.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && expression.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(expression.callee.object, 'expect') && (0, _utils.isSupportedAccessor)(expression.callee.property) && ['assertions', 'hasAssertions'].includes((0, _utils.getAccessorValue)(expression.callee.property));
|
||||
|
||||
const isFirstLineExprStmt = functionBody => functionBody[0] && functionBody[0].type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement;
|
||||
|
||||
const suggestRemovingExtraArguments = (args, extraArgsStartAt) => ({
|
||||
messageId: 'suggestRemovingExtraArguments',
|
||||
fix: fixer => fixer.removeRange([args[extraArgsStartAt].range[0] - Math.sign(extraArgsStartAt), args[args.length - 1].range[1]])
|
||||
});
|
||||
|
||||
const suggestions = [['suggestAddingHasAssertions', 'expect.hasAssertions();'], ['suggestAddingAssertions', 'expect.assertions();']];
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `expect.assertions()` OR `expect.hasAssertions()`',
|
||||
recommended: false,
|
||||
suggestion: true
|
||||
},
|
||||
messages: {
|
||||
hasAssertionsTakesNoArguments: '`expect.hasAssertions` expects no arguments',
|
||||
assertionsRequiresOneArgument: '`expect.assertions` excepts a single argument of type number',
|
||||
assertionsRequiresNumberArgument: 'This argument should be a number',
|
||||
haveExpectAssertions: 'Every test should have either `expect.assertions(<number of assertions>)` or `expect.hasAssertions()` as its first expression',
|
||||
suggestAddingHasAssertions: 'Add `expect.hasAssertions()`',
|
||||
suggestAddingAssertions: 'Add `expect.assertions(<number of assertions>)`',
|
||||
suggestRemovingExtraArguments: 'Remove extra arguments'
|
||||
},
|
||||
type: 'suggestion',
|
||||
hasSuggestions: true,
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
onlyFunctionsWithAsyncKeyword: {
|
||||
type: 'boolean'
|
||||
},
|
||||
onlyFunctionsWithExpectInLoop: {
|
||||
type: 'boolean'
|
||||
},
|
||||
onlyFunctionsWithExpectInCallback: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}]
|
||||
},
|
||||
defaultOptions: [{
|
||||
onlyFunctionsWithAsyncKeyword: false,
|
||||
onlyFunctionsWithExpectInLoop: false,
|
||||
onlyFunctionsWithExpectInCallback: false
|
||||
}],
|
||||
|
||||
create(context, [options]) {
|
||||
let expressionDepth = 0;
|
||||
let hasExpectInCallback = false;
|
||||
let hasExpectInLoop = false;
|
||||
let inTestCaseCall = false;
|
||||
let inForLoop = false;
|
||||
|
||||
const shouldCheckFunction = testFunction => {
|
||||
if (!options.onlyFunctionsWithAsyncKeyword && !options.onlyFunctionsWithExpectInLoop && !options.onlyFunctionsWithExpectInCallback) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.onlyFunctionsWithAsyncKeyword) {
|
||||
if (testFunction.async) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.onlyFunctionsWithExpectInLoop) {
|
||||
if (hasExpectInLoop) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.onlyFunctionsWithExpectInCallback) {
|
||||
if (hasExpectInCallback) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const enterExpression = () => inTestCaseCall && expressionDepth++;
|
||||
|
||||
const exitExpression = () => inTestCaseCall && expressionDepth--;
|
||||
|
||||
const enterForLoop = () => inForLoop = true;
|
||||
|
||||
const exitForLoop = () => inForLoop = false;
|
||||
|
||||
return {
|
||||
FunctionExpression: enterExpression,
|
||||
'FunctionExpression:exit': exitExpression,
|
||||
ArrowFunctionExpression: enterExpression,
|
||||
'ArrowFunctionExpression:exit': exitExpression,
|
||||
ForStatement: enterForLoop,
|
||||
'ForStatement:exit': exitForLoop,
|
||||
ForInStatement: enterForLoop,
|
||||
'ForInStatement:exit': exitForLoop,
|
||||
ForOfStatement: enterForLoop,
|
||||
'ForOfStatement:exit': exitForLoop,
|
||||
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isTestCaseCall)(node)) {
|
||||
inTestCaseCall = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((0, _utils.isExpectCall)(node) && inTestCaseCall) {
|
||||
if (inForLoop) {
|
||||
hasExpectInLoop = true;
|
||||
}
|
||||
|
||||
if (expressionDepth > 1) {
|
||||
hasExpectInCallback = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
if (!(0, _utils.isTestCaseCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.arguments.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [, testFn] = node.arguments;
|
||||
|
||||
if (!(0, _utils.isFunction)(testFn) || testFn.body.type !== _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldCheckFunction(testFn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
hasExpectInLoop = false;
|
||||
hasExpectInCallback = false;
|
||||
const testFuncBody = testFn.body.body;
|
||||
|
||||
if (!isFirstLineExprStmt(testFuncBody)) {
|
||||
context.report({
|
||||
messageId: 'haveExpectAssertions',
|
||||
node,
|
||||
suggest: suggestions.map(([messageId, text]) => ({
|
||||
messageId,
|
||||
fix: fixer => fixer.insertTextBeforeRange([testFn.body.range[0] + 1, testFn.body.range[1]], text)
|
||||
}))
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const testFuncFirstLine = testFuncBody[0].expression;
|
||||
|
||||
if (!isExpectAssertionsOrHasAssertionsCall(testFuncFirstLine)) {
|
||||
context.report({
|
||||
messageId: 'haveExpectAssertions',
|
||||
node,
|
||||
suggest: suggestions.map(([messageId, text]) => ({
|
||||
messageId,
|
||||
fix: fixer => fixer.insertTextBefore(testFuncBody[0], text)
|
||||
}))
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if ((0, _utils.isSupportedAccessor)(testFuncFirstLine.callee.property, 'hasAssertions')) {
|
||||
if (testFuncFirstLine.arguments.length) {
|
||||
context.report({
|
||||
messageId: 'hasAssertionsTakesNoArguments',
|
||||
node: testFuncFirstLine.callee.property,
|
||||
suggest: [suggestRemovingExtraArguments(testFuncFirstLine.arguments, 0)]
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(0, _utils.hasOnlyOneArgument)(testFuncFirstLine)) {
|
||||
let {
|
||||
loc
|
||||
} = testFuncFirstLine.callee.property;
|
||||
const suggest = [];
|
||||
|
||||
if (testFuncFirstLine.arguments.length) {
|
||||
loc = testFuncFirstLine.arguments[1].loc;
|
||||
suggest.push(suggestRemovingExtraArguments(testFuncFirstLine.arguments, 1));
|
||||
}
|
||||
|
||||
context.report({
|
||||
messageId: 'assertionsRequiresOneArgument',
|
||||
suggest,
|
||||
loc
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const [arg] = testFuncFirstLine.arguments;
|
||||
|
||||
if (arg.type === _experimentalUtils.AST_NODE_TYPES.Literal && typeof arg.value === 'number' && Number.isInteger(arg.value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
messageId: 'assertionsRequiresNumberArgument',
|
||||
node: arg
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
48
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-expect-resolves.js
generated
vendored
48
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-expect-resolves.js
generated
vendored
@@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Prefer `await expect(...).resolves` over `expect(await ...)` syntax',
|
||||
recommended: false
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
expectResolves: 'Use `await expect(...).resolves instead.'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
create: context => ({
|
||||
CallExpression(node) {
|
||||
const [awaitNode] = node.arguments;
|
||||
|
||||
if ((0, _utils.isExpectCall)(node) && (awaitNode === null || awaitNode === void 0 ? void 0 : awaitNode.type) === _experimentalUtils.AST_NODE_TYPES.AwaitExpression) {
|
||||
context.report({
|
||||
node: node.arguments[0],
|
||||
messageId: 'expectResolves',
|
||||
|
||||
fix(fixer) {
|
||||
return [fixer.insertTextBefore(node, 'await '), fixer.removeRange([awaitNode.range[0], awaitNode.argument.range[0]]), fixer.insertTextAfter(node, '.resolves')];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
53
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-hooks-on-top.js
generated
vendored
53
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-hooks-on-top.js
generated
vendored
@@ -1,53 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest having hooks before any test cases',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
noHookOnTop: 'Hooks should come before test cases'
|
||||
},
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
const hooksContext = [false];
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isHook)(node) && (0, _utils.isTestCaseCall)(node)) {
|
||||
hooksContext[hooksContext.length - 1] = true;
|
||||
}
|
||||
|
||||
if (hooksContext[hooksContext.length - 1] && (0, _utils.isHook)(node)) {
|
||||
context.report({
|
||||
messageId: 'noHookOnTop',
|
||||
node
|
||||
});
|
||||
}
|
||||
|
||||
hooksContext.push(false);
|
||||
},
|
||||
|
||||
'CallExpression:exit'() {
|
||||
hooksContext.pop();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
150
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-lowercase-title.js
generated
vendored
150
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-lowercase-title.js
generated
vendored
@@ -1,150 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const hasStringAsFirstArgument = node => node.arguments[0] && (0, _utils.isStringNode)(node.arguments[0]);
|
||||
|
||||
const findNodeNameAndArgument = node => {
|
||||
if (!((0, _utils.isTestCaseCall)(node) || (0, _utils.isDescribeCall)(node))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!hasStringAsFirstArgument(node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [(0, _utils.getNodeName)(node).split('.')[0], node.arguments[0]];
|
||||
};
|
||||
|
||||
const populateIgnores = ignore => {
|
||||
const ignores = [];
|
||||
|
||||
if (ignore.includes(_utils.DescribeAlias.describe)) {
|
||||
ignores.push(...Object.keys(_utils.DescribeAlias));
|
||||
}
|
||||
|
||||
if (ignore.includes(_utils.TestCaseName.test)) {
|
||||
ignores.push(...Object.keys(_utils.TestCaseName).filter(k => k.endsWith(_utils.TestCaseName.test)));
|
||||
}
|
||||
|
||||
if (ignore.includes(_utils.TestCaseName.it)) {
|
||||
ignores.push(...Object.keys(_utils.TestCaseName).filter(k => k.endsWith(_utils.TestCaseName.it)));
|
||||
}
|
||||
|
||||
return ignores;
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce lowercase test names',
|
||||
category: 'Best Practices',
|
||||
recommended: false
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
unexpectedLowercase: '`{{ method }}`s should begin with lowercase'
|
||||
},
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
ignore: {
|
||||
type: 'array',
|
||||
items: {
|
||||
enum: [_utils.DescribeAlias.describe, _utils.TestCaseName.test, _utils.TestCaseName.it]
|
||||
},
|
||||
additionalItems: false
|
||||
},
|
||||
allowedPrefixes: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
additionalItems: false
|
||||
},
|
||||
ignoreTopLevelDescribe: {
|
||||
type: 'boolean',
|
||||
default: false
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}]
|
||||
},
|
||||
defaultOptions: [{
|
||||
ignore: [],
|
||||
allowedPrefixes: [],
|
||||
ignoreTopLevelDescribe: false
|
||||
}],
|
||||
|
||||
create(context, [{
|
||||
ignore = [],
|
||||
allowedPrefixes = [],
|
||||
ignoreTopLevelDescribe
|
||||
}]) {
|
||||
const ignores = populateIgnores(ignore);
|
||||
let numberOfDescribeBlocks = 0;
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
numberOfDescribeBlocks++;
|
||||
|
||||
if (ignoreTopLevelDescribe && numberOfDescribeBlocks === 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const results = findNodeNameAndArgument(node);
|
||||
|
||||
if (!results) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [name, firstArg] = results;
|
||||
const description = (0, _utils.getStringValue)(firstArg);
|
||||
|
||||
if (allowedPrefixes.some(name => description.startsWith(name))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const firstCharacter = description.charAt(0);
|
||||
|
||||
if (!firstCharacter || firstCharacter === firstCharacter.toLowerCase() || ignores.includes(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
messageId: 'unexpectedLowercase',
|
||||
node: node.arguments[0],
|
||||
data: {
|
||||
method: name
|
||||
},
|
||||
|
||||
fix(fixer) {
|
||||
const description = (0, _utils.getStringValue)(firstArg);
|
||||
const rangeIgnoringQuotes = [firstArg.range[0] + 1, firstArg.range[1] - 1];
|
||||
const newDescription = description.substring(0, 1).toLowerCase() + description.substring(1);
|
||||
return [fixer.replaceTextRange(rangeIgnoringQuotes, newDescription)];
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
numberOfDescribeBlocks--;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
89
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-spy-on.js
generated
vendored
89
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-spy-on.js
generated
vendored
@@ -1,89 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const findNodeObject = node => {
|
||||
if ('object' in node) {
|
||||
return node.object;
|
||||
}
|
||||
|
||||
if (node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
||||
return node.callee.object;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const getJestFnCall = node => {
|
||||
if (node.type !== _experimentalUtils.AST_NODE_TYPES.CallExpression && node.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const obj = findNodeObject(node);
|
||||
|
||||
if (!obj) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (obj.type === _experimentalUtils.AST_NODE_TYPES.Identifier) {
|
||||
return node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.getNodeName)(node.callee) === 'jest.fn' ? node : null;
|
||||
}
|
||||
|
||||
return getJestFnCall(obj);
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `jest.spyOn()`',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
useJestSpyOn: 'Use jest.spyOn() instead.'
|
||||
},
|
||||
fixable: 'code',
|
||||
schema: [],
|
||||
type: 'suggestion'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
AssignmentExpression(node) {
|
||||
const {
|
||||
left,
|
||||
right
|
||||
} = node;
|
||||
if (left.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) return;
|
||||
const jestFnCall = getJestFnCall(right);
|
||||
if (!jestFnCall) return;
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'useJestSpyOn',
|
||||
|
||||
fix(fixer) {
|
||||
const leftPropQuote = left.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier ? "'" : '';
|
||||
const [arg] = jestFnCall.arguments;
|
||||
const argSource = arg && context.getSourceCode().getText(arg);
|
||||
const mockImplementation = argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()';
|
||||
return [fixer.insertTextBefore(left, `jest.spyOn(`), fixer.replaceTextRange([left.object.range[1], left.property.range[0]], `, ${leftPropQuote}`), fixer.replaceTextRange([left.property.range[1], jestFnCall.range[1]], `${leftPropQuote})${mockImplementation}`)];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
57
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-strict-equal.js
generated
vendored
57
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-strict-equal.js
generated
vendored
@@ -1,57 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `toStrictEqual()`',
|
||||
recommended: false,
|
||||
suggestion: true
|
||||
},
|
||||
messages: {
|
||||
useToStrictEqual: 'Use `toStrictEqual()` instead',
|
||||
suggestReplaceWithStrictEqual: 'Replace with `toStrictEqual()`'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: [],
|
||||
hasSuggestions: true
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
matcher
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (matcher && (0, _utils.isParsedEqualityMatcherCall)(matcher, _utils.EqualityMatcher.toEqual)) {
|
||||
context.report({
|
||||
messageId: 'useToStrictEqual',
|
||||
node: matcher.node.property,
|
||||
suggest: [{
|
||||
messageId: 'suggestReplaceWithStrictEqual',
|
||||
fix: fixer => [fixer.replaceText(matcher.node.property, _utils.EqualityMatcher.toStrictEqual)]
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
136
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-to-be.js
generated
vendored
136
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-to-be.js
generated
vendored
@@ -1,136 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const isNullLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES.Literal && node.value === null;
|
||||
/**
|
||||
* Checks if the given `ParsedEqualityMatcherCall` is a call to one of the equality matchers,
|
||||
* with a `null` literal as the sole argument.
|
||||
*/
|
||||
|
||||
|
||||
const isNullEqualityMatcher = matcher => isNullLiteral(getFirstArgument(matcher));
|
||||
|
||||
const isFirstArgumentIdentifier = (matcher, name) => (0, _utils.isIdentifier)(getFirstArgument(matcher), name);
|
||||
|
||||
const shouldUseToBe = matcher => {
|
||||
const firstArg = getFirstArgument(matcher);
|
||||
|
||||
if (firstArg.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
|
||||
// regex literals are classed as literals, but they're actually objects
|
||||
// which means "toBe" will give different results than other matchers
|
||||
return !('regex' in firstArg);
|
||||
}
|
||||
|
||||
return firstArg.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral;
|
||||
};
|
||||
|
||||
const getFirstArgument = matcher => {
|
||||
return (0, _utils.followTypeAssertionChain)(matcher.arguments[0]);
|
||||
};
|
||||
|
||||
const reportPreferToBe = (context, whatToBe, matcher, modifier) => {
|
||||
const modifierNode = (modifier === null || modifier === void 0 ? void 0 : modifier.negation) || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.not && (modifier === null || modifier === void 0 ? void 0 : modifier.node);
|
||||
context.report({
|
||||
messageId: `useToBe${whatToBe}`,
|
||||
|
||||
fix(fixer) {
|
||||
var _matcher$arguments;
|
||||
|
||||
const fixes = [fixer.replaceText(matcher.node.property, `toBe${whatToBe}`)];
|
||||
|
||||
if ((_matcher$arguments = matcher.arguments) !== null && _matcher$arguments !== void 0 && _matcher$arguments.length && whatToBe !== '') {
|
||||
fixes.push(fixer.remove(matcher.arguments[0]));
|
||||
}
|
||||
|
||||
if (modifierNode) {
|
||||
fixes.push(fixer.removeRange([modifierNode.property.range[0] - 1, modifierNode.property.range[1]]));
|
||||
}
|
||||
|
||||
return fixes;
|
||||
},
|
||||
|
||||
node: matcher.node.property
|
||||
});
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `toBe()` for primitive literals',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
useToBe: 'Use `toBe` when expecting primitive literals',
|
||||
useToBeUndefined: 'Use `toBeUndefined` instead',
|
||||
useToBeDefined: 'Use `toBeDefined` instead',
|
||||
useToBeNull: 'Use `toBeNull` instead',
|
||||
useToBeNaN: 'Use `toBeNaN` instead'
|
||||
},
|
||||
fixable: 'code',
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
matcher,
|
||||
modifier
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (!matcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.not || modifier !== null && modifier !== void 0 && modifier.negation) && ['toBeUndefined', 'toBeDefined'].includes(matcher.name)) {
|
||||
reportPreferToBe(context, matcher.name === 'toBeDefined' ? 'Undefined' : 'Defined', matcher, modifier);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(0, _utils.isParsedEqualityMatcherCall)(matcher)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNullEqualityMatcher(matcher)) {
|
||||
reportPreferToBe(context, 'Null', matcher);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isFirstArgumentIdentifier(matcher, 'undefined')) {
|
||||
const name = (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.not || modifier !== null && modifier !== void 0 && modifier.negation ? 'Defined' : 'Undefined';
|
||||
reportPreferToBe(context, name, matcher, modifier);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isFirstArgumentIdentifier(matcher, 'NaN')) {
|
||||
reportPreferToBe(context, 'NaN', matcher);
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldUseToBe(matcher) && matcher.name !== _utils.EqualityMatcher.toBe) {
|
||||
reportPreferToBe(context, '', matcher);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
98
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-to-contain.js
generated
vendored
98
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-to-contain.js
generated
vendored
@@ -1,98 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const isBooleanLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
|
||||
|
||||
/**
|
||||
* Checks if the given `ParsedExpectMatcher` is a call to one of the equality matchers,
|
||||
* with a boolean literal as the sole argument.
|
||||
*
|
||||
* @example javascript
|
||||
* toBe(true);
|
||||
* toEqual(false);
|
||||
*
|
||||
* @param {ParsedExpectMatcher} matcher
|
||||
*
|
||||
* @return {matcher is ParsedBooleanEqualityMatcher}
|
||||
*/
|
||||
const isBooleanEqualityMatcher = matcher => (0, _utils.isParsedEqualityMatcherCall)(matcher) && isBooleanLiteral((0, _utils.followTypeAssertionChain)(matcher.arguments[0]));
|
||||
|
||||
/**
|
||||
* Checks if the given `node` is a `CallExpression` representing the calling
|
||||
* of an `includes`-like method that can be 'fixed' (using `toContain`).
|
||||
*
|
||||
* @param {CallExpression} node
|
||||
*
|
||||
* @return {node is FixableIncludesCallExpression}
|
||||
*/
|
||||
const isFixableIncludesCallExpression = node => node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(node.callee.property, 'includes') && (0, _utils.hasOnlyOneArgument)(node); // expect(array.includes(<value>)[not.]{toBe,toEqual}(<boolean>)
|
||||
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `toContain()`',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
useToContain: 'Use toContain() instead'
|
||||
},
|
||||
fixable: 'code',
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
expect: {
|
||||
arguments: [includesCall],
|
||||
range: [, expectCallEnd]
|
||||
},
|
||||
matcher,
|
||||
modifier
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (!matcher || !includesCall || modifier && modifier.name !== _utils.ModifierName.not || !isBooleanEqualityMatcher(matcher) || !isFixableIncludesCallExpression(includesCall)) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
fix(fixer) {
|
||||
const sourceCode = context.getSourceCode(); // we need to negate the expectation if the current expected
|
||||
// value is itself negated by the "not" modifier
|
||||
|
||||
const addNotModifier = (0, _utils.followTypeAssertionChain)(matcher.arguments[0]).value === !!modifier;
|
||||
return [// remove the "includes" call entirely
|
||||
fixer.removeRange([includesCall.callee.property.range[0] - 1, includesCall.range[1]]), // replace the current matcher with "toContain", adding "not" if needed
|
||||
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${_utils.ModifierName.not}.toContain` : '.toContain'), // replace the matcher argument with the value from the "includes"
|
||||
fixer.replaceText(matcher.arguments[0], sourceCode.getText(includesCall.arguments[0]))];
|
||||
},
|
||||
|
||||
messageId: 'useToContain',
|
||||
node: (modifier || matcher).node.property
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
64
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-to-have-length.js
generated
vendored
64
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-to-have-length.js
generated
vendored
@@ -1,64 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `toHaveLength()`',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
useToHaveLength: 'Use toHaveLength() instead'
|
||||
},
|
||||
fixable: 'code',
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
expect: {
|
||||
arguments: [argument]
|
||||
},
|
||||
matcher
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if (!matcher || !(0, _utils.isParsedEqualityMatcherCall)(matcher) || (argument === null || argument === void 0 ? void 0 : argument.type) !== _experimentalUtils.AST_NODE_TYPES.MemberExpression || !(0, _utils.isSupportedAccessor)(argument.property, 'length')) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
fix(fixer) {
|
||||
return [// remove the "length" property accessor
|
||||
fixer.removeRange([argument.property.range[0] - 1, argument.range[1]]), // replace the current matcher with "toHaveLength"
|
||||
fixer.replaceTextRange([matcher.node.object.range[1], matcher.node.range[1]], '.toHaveLength')];
|
||||
},
|
||||
|
||||
messageId: 'useToHaveLength',
|
||||
node: matcher.node.property
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
76
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-todo.js
generated
vendored
76
frontend/node_modules/eslint-plugin-jest/lib/rules/prefer-todo.js
generated
vendored
@@ -1,76 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
function isEmptyFunction(node) {
|
||||
if (!(0, _utils.isFunction)(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return node.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement && !node.body.body.length;
|
||||
}
|
||||
|
||||
function createTodoFixer(node, fixer) {
|
||||
const testName = (0, _utils.getNodeName)(node).split('.').shift();
|
||||
return fixer.replaceText(node.callee, `${testName}.todo`);
|
||||
}
|
||||
|
||||
const isTargetedTestCase = node => (0, _utils.isTestCaseCall)(node) && [_utils.TestCaseName.it, _utils.TestCaseName.test, 'it.skip', 'test.skip'].includes((0, _utils.getNodeName)(node));
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Suggest using `test.todo`',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
emptyTest: 'Prefer todo test case over empty test case',
|
||||
unimplementedTest: 'Prefer todo test case over unimplemented test case'
|
||||
},
|
||||
fixable: 'code',
|
||||
schema: [],
|
||||
type: 'layout'
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
const [title, callback] = node.arguments;
|
||||
|
||||
if (!title || !isTargetedTestCase(node) || !(0, _utils.isStringNode)(title)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback && isEmptyFunction(callback)) {
|
||||
context.report({
|
||||
messageId: 'emptyTest',
|
||||
node,
|
||||
fix: fixer => [fixer.removeRange([title.range[1], callback.range[1]]), createTodoFixer(node, fixer)]
|
||||
});
|
||||
}
|
||||
|
||||
if ((0, _utils.hasOnlyOneArgument)(node)) {
|
||||
context.report({
|
||||
messageId: 'unimplementedTest',
|
||||
node,
|
||||
fix: fixer => [createTodoFixer(node, fixer)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
121
frontend/node_modules/eslint-plugin-jest/lib/rules/require-hook.js
generated
vendored
121
frontend/node_modules/eslint-plugin-jest/lib/rules/require-hook.js
generated
vendored
@@ -1,121 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const isJestFnCall = node => {
|
||||
var _getNodeName;
|
||||
|
||||
if ((0, _utils.isDescribeCall)(node) || (0, _utils.isTestCaseCall)(node) || (0, _utils.isHook)(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!((_getNodeName = (0, _utils.getNodeName)(node)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith('jest.'));
|
||||
};
|
||||
|
||||
const isNullOrUndefined = node => {
|
||||
return node.type === _experimentalUtils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils.isIdentifier)(node, 'undefined');
|
||||
};
|
||||
|
||||
const shouldBeInHook = (node, allowedFunctionCalls = []) => {
|
||||
switch (node.type) {
|
||||
case _experimentalUtils.AST_NODE_TYPES.ExpressionStatement:
|
||||
return shouldBeInHook(node.expression, allowedFunctionCalls);
|
||||
|
||||
case _experimentalUtils.AST_NODE_TYPES.CallExpression:
|
||||
return !(isJestFnCall(node) || allowedFunctionCalls.includes((0, _utils.getNodeName)(node)));
|
||||
|
||||
case _experimentalUtils.AST_NODE_TYPES.VariableDeclaration:
|
||||
{
|
||||
if (node.kind === 'const') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return node.declarations.some(({
|
||||
init
|
||||
}) => init !== null && !isNullOrUndefined(init));
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Require setup and teardown code to be within a hook',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
useHook: 'This should be done within a hook'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
allowedFunctionCalls: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}]
|
||||
},
|
||||
defaultOptions: [{
|
||||
allowedFunctionCalls: []
|
||||
}],
|
||||
|
||||
create(context) {
|
||||
var _context$options$;
|
||||
|
||||
const {
|
||||
allowedFunctionCalls
|
||||
} = (_context$options$ = context.options[0]) !== null && _context$options$ !== void 0 ? _context$options$ : {};
|
||||
|
||||
const checkBlockBody = body => {
|
||||
for (const statement of body) {
|
||||
if (shouldBeInHook(statement, allowedFunctionCalls)) {
|
||||
context.report({
|
||||
node: statement,
|
||||
messageId: 'useHook'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
Program(program) {
|
||||
checkBlockBody(program.body);
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
if (!(0, _utils.isDescribeCall)(node) || node.arguments.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [, testFn] = node.arguments;
|
||||
|
||||
if (!(0, _utils.isFunction)(testFn) || testFn.body.type !== _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkBlockBody(testFn.body.body);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
57
frontend/node_modules/eslint-plugin-jest/lib/rules/require-to-throw-message.js
generated
vendored
57
frontend/node_modules/eslint-plugin-jest/lib/rules/require-to-throw-message.js
generated
vendored
@@ -1,57 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Require a message for `toThrow()`',
|
||||
recommended: false
|
||||
},
|
||||
messages: {
|
||||
addErrorMessage: 'Add an error message to {{ matcherName }}()'
|
||||
},
|
||||
type: 'suggestion',
|
||||
schema: []
|
||||
},
|
||||
defaultOptions: [],
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
var _matcher$arguments;
|
||||
|
||||
if (!(0, _utils.isExpectCall)(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
matcher,
|
||||
modifier
|
||||
} = (0, _utils.parseExpectCall)(node);
|
||||
|
||||
if ((matcher === null || matcher === void 0 ? void 0 : (_matcher$arguments = matcher.arguments) === null || _matcher$arguments === void 0 ? void 0 : _matcher$arguments.length) === 0 && ['toThrow', 'toThrowError'].includes(matcher.name) && (!modifier || !(modifier.name === _utils.ModifierName.not || modifier.negation))) {
|
||||
// Look for `toThrow` calls with no arguments.
|
||||
context.report({
|
||||
messageId: 'addErrorMessage',
|
||||
data: {
|
||||
matcherName: matcher.name
|
||||
},
|
||||
node: matcher.node.property
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
100
frontend/node_modules/eslint-plugin-jest/lib/rules/require-top-level-describe.js
generated
vendored
100
frontend/node_modules/eslint-plugin-jest/lib/rules/require-top-level-describe.js
generated
vendored
@@ -1,100 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const messages = {
|
||||
tooManyDescribes: 'There should not be more than {{ max }} describe{{ s }} at the top level',
|
||||
unexpectedTestCase: 'All test cases must be wrapped in a describe block.',
|
||||
unexpectedHook: 'All hooks must be wrapped in a describe block.'
|
||||
};
|
||||
|
||||
var _default = (0, _utils.createRule)({
|
||||
name: __filename,
|
||||
meta: {
|
||||
docs: {
|
||||
category: 'Best Practices',
|
||||
description: 'Require test cases and hooks to be inside a `describe` block',
|
||||
recommended: false
|
||||
},
|
||||
messages,
|
||||
type: 'suggestion',
|
||||
schema: [{
|
||||
type: 'object',
|
||||
properties: {
|
||||
maxNumberOfTopLevelDescribes: {
|
||||
type: 'number',
|
||||
minimum: 1
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}]
|
||||
},
|
||||
defaultOptions: [{}],
|
||||
|
||||
create(context) {
|
||||
var _context$options$;
|
||||
|
||||
const {
|
||||
maxNumberOfTopLevelDescribes = Infinity
|
||||
} = (_context$options$ = context.options[0]) !== null && _context$options$ !== void 0 ? _context$options$ : {};
|
||||
let numberOfTopLevelDescribeBlocks = 0;
|
||||
let numberOfDescribeBlocks = 0;
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
numberOfDescribeBlocks++;
|
||||
|
||||
if (numberOfDescribeBlocks === 1) {
|
||||
numberOfTopLevelDescribeBlocks++;
|
||||
|
||||
if (numberOfTopLevelDescribeBlocks > maxNumberOfTopLevelDescribes) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'tooManyDescribes',
|
||||
data: {
|
||||
max: maxNumberOfTopLevelDescribes,
|
||||
s: maxNumberOfTopLevelDescribes === 1 ? '' : 's'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (numberOfDescribeBlocks === 0) {
|
||||
if ((0, _utils.isTestCaseCall)(node)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedTestCase'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if ((0, _utils.isHook)(node)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpectedHook'
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'CallExpression:exit'(node) {
|
||||
if ((0, _utils.isDescribeCall)(node)) {
|
||||
numberOfDescribeBlocks--;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
Reference in New Issue
Block a user