|
| 1 | +'use strict' |
| 2 | + |
| 3 | +//------------------------------------------------------------------------------ |
| 4 | +// Rule Definition |
| 5 | +//------------------------------------------------------------------------------ |
| 6 | + |
| 7 | +module.exports = { |
| 8 | + meta: { |
| 9 | + type: 'suggestion', |
| 10 | + docs: { |
| 11 | + description: 'disallow using `cy.debug()` calls', |
| 12 | + category: 'Possible Errors', |
| 13 | + recommended: false, |
| 14 | + url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-debug.md', |
| 15 | + }, |
| 16 | + fixable: null, // or "code" or "whitespace" |
| 17 | + schema: [], |
| 18 | + messages: { |
| 19 | + unexpected: 'Do not use cy.debug command', |
| 20 | + }, |
| 21 | + }, |
| 22 | + |
| 23 | + create (context) { |
| 24 | + |
| 25 | + // variables should be defined here |
| 26 | + |
| 27 | + //---------------------------------------------------------------------- |
| 28 | + // Helpers |
| 29 | + //---------------------------------------------------------------------- |
| 30 | + function isCallingDebug (node) { |
| 31 | + return node.callee && |
| 32 | + node.callee.property && |
| 33 | + node.callee.property.type === 'Identifier' && |
| 34 | + node.callee.property.name === 'debug' |
| 35 | + } |
| 36 | + |
| 37 | + function isCypressCall (node) { |
| 38 | + if (!node.callee || node.callee.type !== 'MemberExpression') { |
| 39 | + return false; |
| 40 | + } |
| 41 | + if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') { |
| 42 | + return true; |
| 43 | + } |
| 44 | + return isCypressCall(node.callee.object); |
| 45 | + } |
| 46 | + |
| 47 | + //---------------------------------------------------------------------- |
| 48 | + // Public |
| 49 | + //---------------------------------------------------------------------- |
| 50 | + |
| 51 | + return { |
| 52 | + |
| 53 | + CallExpression (node) { |
| 54 | + if (isCypressCall(node) && isCallingDebug(node)) { |
| 55 | + context.report({ node, messageId: 'unexpected' }) |
| 56 | + } |
| 57 | + }, |
| 58 | + |
| 59 | + } |
| 60 | + }, |
| 61 | +} |
0 commit comments