eslint-plugin-cypress
Advanced tools
Comparing version
@@ -35,3 +35,3 @@ # Contributing to cypress-io/eslint-plugin-cypress | ||
* Run `npm run lint` | ||
* Run `npm test` to run [Jest](https://jestjs.io/) (or run `npm start` to run [Jest](https://jestjs.io/) in [watchAll](https://jestjs.io/docs/cli#--watchall) mode where it remains active and reruns when source changes are made) | ||
* Run `npm test` to run [Vitest](https://vitest.dev/) | ||
* Make sure all tests are passing | ||
@@ -38,0 +38,0 @@ * Add the rule to [flat.js](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/lib/flat.js) |
@@ -23,4 +23,4 @@ const globals = require('globals') | ||
const commonGlobals = | ||
Object.assign({ | ||
const commonGlobals | ||
= Object.assign({ | ||
cy: false, | ||
@@ -37,3 +37,3 @@ Cypress: false, | ||
plugins: { | ||
cypress: plugin | ||
cypress: plugin, | ||
}, | ||
@@ -43,4 +43,4 @@ languageOptions: { | ||
commonGlobals, | ||
} | ||
} | ||
}, | ||
}, | ||
}) | ||
@@ -52,3 +52,3 @@ | ||
plugins: { | ||
cypress: plugin | ||
cypress: plugin, | ||
}, | ||
@@ -64,6 +64,6 @@ rules: { | ||
commonGlobals, | ||
} | ||
} | ||
}, | ||
}, | ||
}) | ||
module.exports = plugin |
@@ -31,5 +31,5 @@ 'use strict' | ||
}, | ||
create (context) { | ||
create(context) { | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if (isCallingCyScreenshot(node) && !isPreviousAnAssertion(node)) { | ||
@@ -43,8 +43,8 @@ context.report({ node, messageId: 'unexpected' }) | ||
function isRootCypress (node) { | ||
function isRootCypress(node) { | ||
while (node.type === 'CallExpression') { | ||
if (node.callee.type !== 'MemberExpression') return false | ||
if (node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy') { | ||
if (node.callee.object.type === 'Identifier' | ||
&& node.callee.object.name === 'cy') { | ||
return true | ||
@@ -59,22 +59,22 @@ } | ||
function getPreviousInChain (node) { | ||
return node.type === 'CallExpression' && | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'CallExpression' && | ||
node.callee.object.callee.type === 'MemberExpression' && | ||
node.callee.object.callee.property.type === 'Identifier' && | ||
node.callee.object.callee.property.name | ||
function getPreviousInChain(node) { | ||
return node.type === 'CallExpression' | ||
&& node.callee.type === 'MemberExpression' | ||
&& node.callee.object.type === 'CallExpression' | ||
&& node.callee.object.callee.type === 'MemberExpression' | ||
&& node.callee.object.callee.property.type === 'Identifier' | ||
&& node.callee.object.callee.property.name | ||
} | ||
function getCallExpressionCypressCommand (node) { | ||
return isRootCypress(node) && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name | ||
function getCallExpressionCypressCommand(node) { | ||
return isRootCypress(node) | ||
&& node.callee.property.type === 'Identifier' | ||
&& node.callee.property.name | ||
} | ||
function isCallingCyScreenshot (node) { | ||
function isCallingCyScreenshot(node) { | ||
return getCallExpressionCypressCommand(node) === 'screenshot' | ||
} | ||
function getPreviousCypressCommand (node) { | ||
function getPreviousCypressCommand(node) { | ||
const previousInChain = getPreviousInChain(node) | ||
@@ -103,4 +103,4 @@ | ||
if (previousStatement.type !== 'ExpressionStatement' || | ||
previousStatement.expression.type !== 'CallExpression') { | ||
if (previousStatement.type !== 'ExpressionStatement' | ||
|| previousStatement.expression.type !== 'CallExpression') { | ||
return null | ||
@@ -112,3 +112,3 @@ } | ||
function isPreviousAnAssertion (node) { | ||
function isPreviousAnAssertion(node) { | ||
const previousCypressCommand = getPreviousCypressCommand(node) | ||
@@ -115,0 +115,0 @@ |
'use strict' | ||
// safely get nested object property | ||
function get (obj, propertyString = '') { | ||
function get(obj, propertyString = '') { | ||
const properties = propertyString.split('.') | ||
@@ -32,5 +32,5 @@ | ||
}, | ||
create (context) { | ||
create(context) { | ||
return { | ||
VariableDeclaration (node) { | ||
VariableDeclaration(node) { | ||
if (node.declarations.some(isCypressCommandDeclaration)) { | ||
@@ -51,3 +51,3 @@ context.report({ node, messageId: 'unexpected' }) | ||
function isCypressCommandDeclaration (declarator) { | ||
function isCypressCommandDeclaration(declarator) { | ||
let object = get(declarator, 'init.callee.object') | ||
@@ -54,0 +54,0 @@ |
@@ -18,14 +18,14 @@ 'use strict' | ||
create (context) { | ||
function isBeforeBlock (callExpressionNode) { | ||
create(context) { | ||
function isBeforeBlock(callExpressionNode) { | ||
const { type, name } = callExpressionNode.callee | ||
return type === 'Identifier' | ||
&& name === 'before' || name === 'beforeEach' | ||
&& (name === 'before' || name === 'beforeEach') | ||
} | ||
function isBeforeAsync (node) { | ||
function isBeforeAsync(node) { | ||
return node.arguments | ||
&& node.arguments.length >= 2 | ||
&& node.arguments[1].async === true | ||
&& node.arguments.length >= 2 | ||
&& node.arguments[1].async === true | ||
} | ||
@@ -35,3 +35,3 @@ const sourceCode = context.sourceCode ?? context.getSourceCode() | ||
return { | ||
Identifier (node) { | ||
Identifier(node) { | ||
if (node.name === 'cy' || node.name === 'Cypress') { | ||
@@ -42,5 +42,5 @@ const ancestors = sourceCode.getAncestors | ||
const asyncTestBlocks = ancestors | ||
.filter((n) => n.type === 'CallExpression') | ||
.filter(isBeforeBlock) | ||
.filter(isBeforeAsync) | ||
.filter((n) => n.type === 'CallExpression') | ||
.filter(isBeforeBlock) | ||
.filter(isBeforeAsync) | ||
@@ -47,0 +47,0 @@ if (asyncTestBlocks.length >= 1) { |
@@ -18,14 +18,14 @@ 'use strict' | ||
create (context) { | ||
function isTestBlock (callExpressionNode) { | ||
create(context) { | ||
function isTestBlock(callExpressionNode) { | ||
const { type, name } = callExpressionNode.callee | ||
return type === 'Identifier' | ||
&& name === 'it' || name === 'test' | ||
&& (name === 'it' || name === 'test') | ||
} | ||
function isTestAsync (node) { | ||
function isTestAsync(node) { | ||
return node.arguments | ||
&& node.arguments.length >= 2 | ||
&& node.arguments[1].async === true | ||
&& node.arguments.length >= 2 | ||
&& node.arguments[1].async === true | ||
} | ||
@@ -35,3 +35,3 @@ const sourceCode = context.sourceCode ?? context.getSourceCode() | ||
return { | ||
Identifier (node) { | ||
Identifier(node) { | ||
if (node.name === 'cy' || node.name === 'Cypress') { | ||
@@ -42,5 +42,5 @@ const ancestors = sourceCode.getAncestors | ||
const asyncTestBlocks = ancestors | ||
.filter((n) => n.type === 'CallExpression') | ||
.filter(isTestBlock) | ||
.filter(isTestAsync) | ||
.filter((n) => n.type === 'CallExpression') | ||
.filter(isTestBlock) | ||
.filter(isTestAsync) | ||
@@ -47,0 +47,0 @@ if (asyncTestBlocks.length >= 1) { |
@@ -1,6 +0,6 @@ | ||
'use strict'; | ||
'use strict' | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
@@ -26,51 +26,51 @@ /** @type {import('eslint').Rule.RuleModule} */ | ||
if ( | ||
node.type !== 'CallExpression' || | ||
node.callee.type !== 'MemberExpression' | ||
node.type !== 'CallExpression' | ||
|| node.callee.type !== 'MemberExpression' | ||
) { | ||
return false; | ||
return false | ||
} | ||
if ( | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy' | ||
node.callee.object.type === 'Identifier' | ||
&& node.callee.object.name === 'cy' | ||
) { | ||
return true; | ||
return true | ||
} | ||
return isRootCypress(node.callee.object); | ||
}; | ||
return isRootCypress(node.callee.object) | ||
} | ||
const hasChainedGet = (node) => { | ||
// Check if this node is a get() call | ||
const isGetCall = | ||
node.callee && | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.property && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'get'; | ||
const isGetCall | ||
= node.callee | ||
&& node.callee.type === 'MemberExpression' | ||
&& node.callee.property | ||
&& node.callee.property.type === 'Identifier' | ||
&& node.callee.property.name === 'get' | ||
if (!isGetCall) { | ||
return false; | ||
return false | ||
} | ||
const obj = node.callee.object; | ||
const obj = node.callee.object | ||
if (obj.type === 'CallExpression') { | ||
const objCallee = obj.callee; | ||
const objCallee = obj.callee | ||
if ( | ||
objCallee && | ||
objCallee.type === 'MemberExpression' && | ||
objCallee.property && | ||
objCallee.property.type === 'Identifier' && | ||
objCallee.property.name === 'get' | ||
objCallee | ||
&& objCallee.type === 'MemberExpression' | ||
&& objCallee.property | ||
&& objCallee.property.type === 'Identifier' | ||
&& objCallee.property.name === 'get' | ||
) { | ||
return true; | ||
return true | ||
} | ||
return hasChainedGet(obj); | ||
return hasChainedGet(obj) | ||
} | ||
return false; | ||
}; | ||
return false | ||
} | ||
@@ -83,7 +83,7 @@ return { | ||
messageId: 'unexpected', | ||
}); | ||
}) | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; | ||
} |
'use strict' | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
@@ -23,33 +23,32 @@ module.exports = { | ||
create (context) { | ||
create(context) { | ||
// variables should be defined here | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// Helpers | ||
//---------------------------------------------------------------------- | ||
function isCallingDebug (node) { | ||
return node.callee && | ||
node.callee.property && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'debug' | ||
// ---------------------------------------------------------------------- | ||
function isCallingDebug(node) { | ||
return node.callee | ||
&& node.callee.property | ||
&& node.callee.property.type === 'Identifier' | ||
&& node.callee.property.name === 'debug' | ||
} | ||
function isCypressCall (node) { | ||
function isCypressCall(node) { | ||
if (!node.callee || node.callee.type !== 'MemberExpression') { | ||
return false; | ||
return false | ||
} | ||
if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') { | ||
return true; | ||
return true | ||
} | ||
return isCypressCall(node.callee.object); | ||
return isCypressCall(node.callee.object) | ||
} | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// Public | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if (isCypressCall(node) && isCallingDebug(node)) { | ||
@@ -56,0 +55,0 @@ context.report({ node, messageId: 'unexpected' }) |
'use strict' | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
@@ -23,35 +23,32 @@ module.exports = { | ||
create (context) { | ||
create(context) { | ||
// variables should be defined here | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// Helpers | ||
//---------------------------------------------------------------------- | ||
function isCallingClickOrType (node) { | ||
// ---------------------------------------------------------------------- | ||
function isCallingClickOrType(node) { | ||
const allowedMethods = ['click', 'dblclick', 'type', 'trigger', 'check', 'rightclick', 'focus', 'select'] | ||
return node.property && node.property.type === 'Identifier' && | ||
allowedMethods.includes(node.property.name) | ||
return node.property && node.property.type === 'Identifier' | ||
&& allowedMethods.includes(node.property.name) | ||
} | ||
function isCypressCall (node) { | ||
return node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy' | ||
function isCypressCall(node) { | ||
return node.callee.type === 'MemberExpression' | ||
&& node.callee.object.type === 'Identifier' | ||
&& node.callee.object.name === 'cy' | ||
} | ||
function hasOptionForce (node) { | ||
return node.arguments && node.arguments.length && | ||
node.arguments.some((arg) => { | ||
return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key && propNode.key.name === 'force') | ||
}) | ||
function hasOptionForce(node) { | ||
return node.arguments && node.arguments.length | ||
&& node.arguments.some((arg) => { | ||
return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key && propNode.key.name === 'force') | ||
}) | ||
} | ||
function deepCheck (node, checkFunc) { | ||
function deepCheck(node, checkFunc) { | ||
let currentNode = node | ||
while (currentNode.parent) { | ||
if (checkFunc(currentNode.parent)) { | ||
@@ -67,9 +64,9 @@ return true | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// Public | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if (isCypressCall(node) && deepCheck(node, isCallingClickOrType) && deepCheck(node, hasOptionForce)) { | ||
@@ -76,0 +73,0 @@ context.report({ node, messageId: 'unexpected' }) |
'use strict' | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
@@ -23,33 +23,32 @@ module.exports = { | ||
create (context) { | ||
create(context) { | ||
// variables should be defined here | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// Helpers | ||
//---------------------------------------------------------------------- | ||
function isCallingPause (node) { | ||
return node.callee && | ||
node.callee.property && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'pause' | ||
// ---------------------------------------------------------------------- | ||
function isCallingPause(node) { | ||
return node.callee | ||
&& node.callee.property | ||
&& node.callee.property.type === 'Identifier' | ||
&& node.callee.property.name === 'pause' | ||
} | ||
function isCypressCall (node) { | ||
function isCypressCall(node) { | ||
if (!node.callee || node.callee.type !== 'MemberExpression') { | ||
return false; | ||
return false | ||
} | ||
if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') { | ||
return true; | ||
return true | ||
} | ||
return isCypressCall(node.callee.object); | ||
return isCypressCall(node.callee.object) | ||
} | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// Public | ||
//---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if (isCypressCall(node) && isCallingPause(node)) { | ||
@@ -56,0 +55,0 @@ context.report({ node, messageId: 'unexpected' }) |
@@ -17,7 +17,7 @@ 'use strict' | ||
}, | ||
create (context) { | ||
create(context) { | ||
const sourceCode = context.sourceCode ?? context.getSourceCode() | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if (isCallingCyWait(node)) { | ||
@@ -37,3 +37,3 @@ const scope = sourceCode.getScope | ||
function nodeIsCalledByCy (node) { | ||
function nodeIsCalledByCy(node) { | ||
if (node.type === 'Identifier' && node.name === 'cy') return true | ||
@@ -48,16 +48,16 @@ | ||
function isCallingCyWait (node) { | ||
return node.callee.type === 'MemberExpression' && | ||
nodeIsCalledByCy(node) && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'wait' | ||
function isCallingCyWait(node) { | ||
return node.callee.type === 'MemberExpression' | ||
&& nodeIsCalledByCy(node) | ||
&& node.callee.property.type === 'Identifier' | ||
&& node.callee.property.name === 'wait' | ||
} | ||
function isNumberArgument (node) { | ||
return node.arguments.length > 0 && | ||
node.arguments[0].type === 'Literal' && | ||
typeof (node.arguments[0].value) === 'number' | ||
function isNumberArgument(node) { | ||
return node.arguments.length > 0 | ||
&& node.arguments[0].type === 'Literal' | ||
&& typeof (node.arguments[0].value) === 'number' | ||
} | ||
function isIdentifierNumberConstArgument (node, scope) { | ||
function isIdentifierNumberConstArgument(node, scope) { | ||
if (node.arguments.length === 0) return false | ||
@@ -64,0 +64,0 @@ |
@@ -9,3 +9,3 @@ 'use strict' | ||
recommended: false, | ||
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-xpath.md' | ||
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-xpath.md', | ||
}, | ||
@@ -19,5 +19,5 @@ fixable: null, // Or `code` or `whitespace` | ||
create (context) { | ||
create(context) { | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if (isCallingCyXpath(node)) { | ||
@@ -29,10 +29,10 @@ context.report({ node, messageId: 'unexpected' }) | ||
}, | ||
}; | ||
} | ||
function isCallingCyXpath (node) { | ||
return node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy' && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'xpath' | ||
function isCallingCyXpath(node) { | ||
return node.callee.type === 'MemberExpression' | ||
&& node.callee.object.type === 'Identifier' | ||
&& node.callee.object.name === 'cy' | ||
&& node.callee.property.type === 'Identifier' | ||
&& node.callee.property.name === 'xpath' | ||
} |
@@ -18,5 +18,5 @@ 'use strict' | ||
create (context) { | ||
create(context) { | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if (isCallingCyGet(node) && !isDataArgument(node)) { | ||
@@ -30,19 +30,19 @@ context.report({ node, messageId: 'unexpected' }) | ||
function isCallingCyGet (node) { | ||
return node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy' && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'get' | ||
function isCallingCyGet(node) { | ||
return node.callee.type === 'MemberExpression' | ||
&& node.callee.object.type === 'Identifier' | ||
&& node.callee.object.name === 'cy' | ||
&& node.callee.property.type === 'Identifier' | ||
&& node.callee.property.name === 'get' | ||
} | ||
function isDataArgument (node) { | ||
return node.arguments.length > 0 && | ||
( | ||
(node.arguments[0].type === 'Literal' && isAliasOrDataSelector(String(node.arguments[0].value))) || | ||
(node.arguments[0].type === 'TemplateLiteral' && isAliasOrDataSelector(String(node.arguments[0].quasis[0].value.cooked))) | ||
function isDataArgument(node) { | ||
return node.arguments.length > 0 | ||
&& ( | ||
(node.arguments[0].type === 'Literal' && isAliasOrDataSelector(String(node.arguments[0].value))) | ||
|| (node.arguments[0].type === 'TemplateLiteral' && isAliasOrDataSelector(String(node.arguments[0].quasis[0].value.cooked))) | ||
) | ||
} | ||
function isAliasOrDataSelector (selector) { | ||
function isAliasOrDataSelector(selector) { | ||
return ['[data-', '@'].some(function (validValue) { | ||
@@ -49,0 +49,0 @@ return selector.startsWith(validValue) |
@@ -85,11 +85,11 @@ 'use strict' | ||
}, | ||
create (context) { | ||
create(context) { | ||
const { methods } = getDefaultOptions(context) | ||
return { | ||
CallExpression (node) { | ||
CallExpression(node) { | ||
if ( | ||
isRootCypress(node) && | ||
isActionUnsafeToChain(node, methods) && | ||
node.parent.type === 'MemberExpression' | ||
isRootCypress(node) | ||
&& isActionUnsafeToChain(node, methods) | ||
&& node.parent.type === 'MemberExpression' | ||
) { | ||
@@ -112,4 +112,4 @@ context.report({ | ||
if ( | ||
node.type !== 'CallExpression' || | ||
node.callee.type !== 'MemberExpression' | ||
node.type !== 'CallExpression' | ||
|| node.callee.type !== 'MemberExpression' | ||
) { | ||
@@ -120,4 +120,4 @@ return false | ||
if ( | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy' | ||
node.callee.object.type === 'Identifier' | ||
&& node.callee.object.name === 'cy' | ||
) { | ||
@@ -141,7 +141,7 @@ return true | ||
return ( | ||
node.callee && | ||
node.callee.property && | ||
node.callee.property.type === 'Identifier' && | ||
unsafeActionsRegex.test(node.callee.property.name) | ||
node.callee | ||
&& node.callee.property | ||
&& node.callee.property.type === 'Identifier' | ||
&& unsafeActionsRegex.test(node.callee.property.name) | ||
) | ||
} |
{ | ||
"name": "eslint-plugin-cypress", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "An ESLint plugin for projects using Cypress", | ||
@@ -32,2 +32,3 @@ "main": "./lib/flat.js", | ||
"devDependencies": { | ||
"@stylistic/eslint-plugin": "^4.4.0", | ||
"eslint": "^9.27.0", | ||
@@ -37,4 +38,4 @@ "eslint-plugin-eslint-plugin": "^6.4.0", | ||
"husky": "^9.1.7", | ||
"jest": "^29.7.0", | ||
"semantic-release": "24.2.5" | ||
"semantic-release": "24.2.5", | ||
"vitest": "^3.1.4" | ||
}, | ||
@@ -45,7 +46,5 @@ "scripts": { | ||
"semantic-release": "semantic-release", | ||
"start": "npm run test-watch", | ||
"test": "jest", | ||
"test-watch": "jest --watchAll", | ||
"test": "vitest run", | ||
"prepare": "husky" | ||
} | ||
} |
@@ -5,28 +5,28 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
const rule = require("../../../lib/rules/no-chained-get"), | ||
RuleTester = require("eslint").RuleTester; | ||
const rule = require('../../../lib/rules/no-chained-get'), | ||
RuleTester = require('eslint').RuleTester | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
const ruleTester = new RuleTester(); | ||
ruleTester.run("no-chained-get", rule, { | ||
const ruleTester = new RuleTester() | ||
ruleTester.run('no-chained-get', rule, { | ||
valid: [ | ||
{ code: "cy.get('div')" }, | ||
{ code: "cy.get('.div').find().get()" }, | ||
{ code: "cy.get('input').should('be.disabled')" }, | ||
{ code: 'cy.get(\'div\')' }, | ||
{ code: 'cy.get(\'.div\').find().get()' }, | ||
{ code: 'cy.get(\'input\').should(\'be.disabled\')' }, | ||
], | ||
invalid: [ | ||
{ | ||
code: "cy.get('div').get('div')", | ||
errors: [{ messageId: "unexpected" }], | ||
code: 'cy.get(\'div\').get(\'div\')', | ||
errors: [{ messageId: 'unexpected' }], | ||
}, | ||
], | ||
}); | ||
}) |
@@ -13,12 +13,12 @@ 'use strict' | ||
valid: [ | ||
{ code: `debug()` }, | ||
{ code: `cy.get('button').dblclick()` }, | ||
{ code: 'debug()' }, | ||
{ code: 'cy.get(\'button\').dblclick()' }, | ||
], | ||
invalid: [ | ||
{ code: `cy.debug()`, errors }, | ||
{ code: `cy.debug({ log: false })`, errors }, | ||
{ code: `cy.get('button').debug()`, errors }, | ||
{ code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).debug()`, errors } | ||
{ code: 'cy.debug()', errors }, | ||
{ code: 'cy.debug({ log: false })', errors }, | ||
{ code: 'cy.get(\'button\').debug()', errors }, | ||
{ code: 'cy.get(\'a\').should(\'have.attr\', \'href\').and(\'match\', /dashboard/).debug()', errors }, | ||
], | ||
}) |
@@ -13,28 +13,28 @@ 'use strict' | ||
valid: [ | ||
{ code: `cy.get('button').click()` }, | ||
{ code: `cy.get('button').click({multiple: true})` }, | ||
{ code: `cy.get('button').dblclick()` }, | ||
{ code: `cy.get('input').type('somth')` }, | ||
{ code: `cy.get('input').type('somth', {anyoption: true})` }, | ||
{ code: `cy.get('input').trigger('click', {anyoption: true})` }, | ||
{ code: `cy.get('input').rightclick({anyoption: true})` }, | ||
{ code: `cy.get('input').check()` }, | ||
{ code: `cy.get('input').select()` }, | ||
{ code: `cy.get('input').focus()` }, | ||
{ code: `cy.document().trigger("keydown", { ...event })` }, | ||
{ code: 'cy.get(\'button\').click()' }, | ||
{ code: 'cy.get(\'button\').click({multiple: true})' }, | ||
{ code: 'cy.get(\'button\').dblclick()' }, | ||
{ code: 'cy.get(\'input\').type(\'somth\')' }, | ||
{ code: 'cy.get(\'input\').type(\'somth\', {anyoption: true})' }, | ||
{ code: 'cy.get(\'input\').trigger(\'click\', {anyoption: true})' }, | ||
{ code: 'cy.get(\'input\').rightclick({anyoption: true})' }, | ||
{ code: 'cy.get(\'input\').check()' }, | ||
{ code: 'cy.get(\'input\').select()' }, | ||
{ code: 'cy.get(\'input\').focus()' }, | ||
{ code: 'cy.document().trigger("keydown", { ...event })' }, | ||
], | ||
invalid: [ | ||
{ code: `cy.get('button').click({force: true})`, errors }, | ||
{ code: `cy.get('button').dblclick({force: true})`, errors }, | ||
{ code: `cy.get('input').type('somth', {force: true})`, errors }, | ||
{ code: `cy.get('div').find('.foo').type('somth', {force: true})`, errors }, | ||
{ code: `cy.get('div').find('.foo').find('.bar').click({force: true})`, errors }, | ||
{ code: `cy.get('div').find('.foo').find('.bar').trigger('change', {force: true})`, errors }, | ||
{ code: `cy.get('input').trigger('click', {force: true})`, errors }, | ||
{ code: `cy.get('input').rightclick({force: true})`, errors }, | ||
{ code: `cy.get('input').check({force: true})`, errors }, | ||
{ code: `cy.get('input').select({force: true})`, errors }, | ||
{ code: `cy.get('input').focus({force: true})`, errors }, | ||
{ code: 'cy.get(\'button\').click({force: true})', errors }, | ||
{ code: 'cy.get(\'button\').dblclick({force: true})', errors }, | ||
{ code: 'cy.get(\'input\').type(\'somth\', {force: true})', errors }, | ||
{ code: 'cy.get(\'div\').find(\'.foo\').type(\'somth\', {force: true})', errors }, | ||
{ code: 'cy.get(\'div\').find(\'.foo\').find(\'.bar\').click({force: true})', errors }, | ||
{ code: 'cy.get(\'div\').find(\'.foo\').find(\'.bar\').trigger(\'change\', {force: true})', errors }, | ||
{ code: 'cy.get(\'input\').trigger(\'click\', {force: true})', errors }, | ||
{ code: 'cy.get(\'input\').rightclick({force: true})', errors }, | ||
{ code: 'cy.get(\'input\').check({force: true})', errors }, | ||
{ code: 'cy.get(\'input\').select({force: true})', errors }, | ||
{ code: 'cy.get(\'input\').focus({force: true})', errors }, | ||
], | ||
}) |
@@ -13,12 +13,12 @@ 'use strict' | ||
valid: [ | ||
{ code: `pause()` }, | ||
{ code: `cy.get('button').dblclick()` }, | ||
{ code: 'pause()' }, | ||
{ code: 'cy.get(\'button\').dblclick()' }, | ||
], | ||
invalid: [ | ||
{ code: `cy.pause()`, errors }, | ||
{ code: `cy.pause({ log: false })`, errors }, | ||
{ code: `cy.get('button').pause()`, errors }, | ||
{ code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`, errors } | ||
{ code: 'cy.pause()', errors }, | ||
{ code: 'cy.pause({ log: false })', errors }, | ||
{ code: 'cy.get(\'button\').pause()', errors }, | ||
{ code: 'cy.get(\'a\').should(\'have.attr\', \'href\').and(\'match\', /dashboard/).pause()', errors }, | ||
], | ||
}) |
@@ -1,16 +0,16 @@ | ||
"use strict"; | ||
'use strict' | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
const rule = require("../../../lib/rules/no-xpath"), | ||
RuleTester = require("eslint").RuleTester; | ||
const rule = require('../../../lib/rules/no-xpath'), | ||
RuleTester = require('eslint').RuleTester | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
// ------------------------------------------------------------------------------ | ||
const ruleTester = new RuleTester(); | ||
ruleTester.run("no-xpath", rule, { | ||
const ruleTester = new RuleTester() | ||
ruleTester.run('no-xpath', rule, { | ||
valid: [ | ||
@@ -22,10 +22,10 @@ { code: 'cy.get("button").click({force: true})' }, | ||
{ | ||
code: "cy.xpath('//div[@class=\"container\"]/p[1]').click()", | ||
errors: [{ messageId: "unexpected" }], | ||
code: 'cy.xpath(\'//div[@class="container"]/p[1]\').click()', | ||
errors: [{ messageId: 'unexpected' }], | ||
}, | ||
{ | ||
code: "cy.xpath('//p[1]').should('exist')", | ||
errors: [{ messageId: "unexpected" }] | ||
} | ||
code: 'cy.xpath(\'//p[1]\').should(\'exist\')', | ||
errors: [{ messageId: 'unexpected' }], | ||
}, | ||
], | ||
}); | ||
}) |
@@ -13,3 +13,3 @@ 'use strict' | ||
{ | ||
code: 'cy.get("new-todo").type("todo A{enter}"); cy.get("new-todo").type("todo B{enter}"); cy.get("new-todo").should("have.class", "active");' | ||
code: 'cy.get("new-todo").type("todo A{enter}"); cy.get("new-todo").type("todo B{enter}"); cy.get("new-todo").should("have.class", "active");', | ||
}, | ||
@@ -16,0 +16,0 @@ { code: 'cy.focused().should("be.visible");' }, |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
152974
0.02%3150
0.06%7
16.67%