eslint-plugin-playwright
Version:
ESLint plugin for Playwright testing.
64 lines (63 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ast_1 = require("../utils/ast");
exports.default = {
create(context) {
const { options } = context;
const max = options[0]?.max ?? 5;
const describeCallbackStack = [];
function pushDescribeCallback(node) {
if (node.parent.type !== 'CallExpression' ||
!(0, ast_1.isDescribeCall)(node.parent)) {
return;
}
describeCallbackStack.push(0);
if (describeCallbackStack.length > max) {
context.report({
node: node.parent.callee,
messageId: 'exceededMaxDepth',
data: {
depth: describeCallbackStack.length.toString(),
max: max.toString(),
},
});
}
}
function popDescribeCallback(node) {
const { parent } = node;
if (parent.type === 'CallExpression' && (0, ast_1.isDescribeCall)(parent)) {
describeCallbackStack.pop();
}
}
return {
FunctionExpression: pushDescribeCallback,
'FunctionExpression:exit': popDescribeCallback,
ArrowFunctionExpression: pushDescribeCallback,
'ArrowFunctionExpression:exit': popDescribeCallback,
};
},
meta: {
docs: {
category: 'Best Practices',
description: 'Enforces a maximum depth to nested describe calls',
recommended: true,
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/max-nested-describe.md',
},
messages: {
exceededMaxDepth: 'Maximum describe call depth exceeded ({{ depth }}). Maximum allowed is {{ max }}.',
},
type: 'suggestion',
schema: [
{
type: 'object',
properties: {
max: {
type: 'integer',
minimum: 0,
},
},
additionalProperties: false,
},
],
},
};