2020-08-26 01:57:08 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
exports.default = void 0;
|
2022-11-10 11:43:16 +01:00
|
|
|
var _utils = require("@typescript-eslint/utils");
|
|
|
|
var _utils2 = require("./utils");
|
|
|
|
var _default = (0, _utils2.createRule)({
|
2020-08-26 01:57:08 +02:00
|
|
|
name: __filename,
|
|
|
|
meta: {
|
|
|
|
docs: {
|
|
|
|
category: 'Best Practices',
|
2022-11-10 11:43:16 +01:00
|
|
|
description: 'Require using `.only` and `.skip` over `f` and `x`',
|
2020-08-26 01:57:08 +02:00
|
|
|
recommended: 'error'
|
|
|
|
},
|
|
|
|
messages: {
|
|
|
|
usePreferredName: 'Use "{{ preferredNodeName }}" instead'
|
|
|
|
},
|
|
|
|
fixable: 'code',
|
|
|
|
schema: [],
|
|
|
|
type: 'suggestion'
|
|
|
|
},
|
|
|
|
defaultOptions: [],
|
|
|
|
create(context) {
|
|
|
|
return {
|
|
|
|
CallExpression(node) {
|
2022-11-10 11:43:16 +01:00
|
|
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
|
|
if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe' && (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (jestFnCall.name[0] !== 'f' && jestFnCall.name[0] !== 'x') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const preferredNodeName = [jestFnCall.name.slice(1), jestFnCall.name[0] === 'f' ? 'only' : 'skip', ...jestFnCall.members.map(s => (0, _utils2.getAccessorValue)(s))].join('.');
|
|
|
|
const funcNode = node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
2020-08-26 01:57:08 +02:00
|
|
|
context.report({
|
|
|
|
messageId: 'usePreferredName',
|
|
|
|
node: node.callee,
|
|
|
|
data: {
|
|
|
|
preferredNodeName
|
|
|
|
},
|
|
|
|
fix(fixer) {
|
2022-11-10 11:43:16 +01:00
|
|
|
return [fixer.replaceText(funcNode, preferredNodeName)];
|
2020-08-26 01:57:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2022-11-10 11:43:16 +01:00
|
|
|
exports.default = _default;
|