eslint-plugin-cypress
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
'use strict' | ||
@@ -7,4 +7,4 @@ module.exports = { | ||
'cypress/no-assigning-return-values': 'error', | ||
'cypress/no-unnecessary-waiting': 'error' | ||
} | ||
}; | ||
'cypress/no-unnecessary-waiting': 'error', | ||
}, | ||
} |
@@ -6,4 +6,15 @@ /** | ||
'use strict'; | ||
'use strict' | ||
// safely get nested object property | ||
function get (obj, propertyString = '') { | ||
const properties = propertyString.split('.') | ||
for (let i = 0; i < properties.length; i++) { | ||
const value = (obj || {})[properties[i]] | ||
if (value == null) return value | ||
obj = value | ||
} | ||
return obj | ||
} | ||
module.exports = { | ||
@@ -15,37 +26,43 @@ meta: { | ||
recommended: true, | ||
url: 'https://docs.cypress.io/guides/references/best-practices.html#Assigning-Return-Values' | ||
url: 'https://docs.cypress.io/guides/references/best-practices.html#Assigning-Return-Values', | ||
}, | ||
schema: [], | ||
messages: { | ||
unexpected: 'Do not assign the return value of a Cypress command' | ||
} | ||
unexpected: 'Do not assign the return value of a Cypress command', | ||
}, | ||
}, | ||
create(context) { | ||
create (context) { | ||
return { | ||
VariableDeclaration(node) { | ||
VariableDeclaration (node) { | ||
if (node.declarations.some(isCypressCommandDeclaration)) { | ||
context.report({ node, messageId: 'unexpected' }); | ||
context.report({ node, messageId: 'unexpected' }) | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
}, | ||
} | ||
}, | ||
} | ||
function isCypressCommandDeclaration(declarator) { | ||
if (!declarator) { return; } | ||
if (!declarator.init) { return; } | ||
if (!declarator.init.callee) { return; } | ||
const whitelistedCommands = { | ||
now: true, | ||
spy: true, | ||
state: true, | ||
stub: true, | ||
} | ||
let object = declarator.init.callee.object; | ||
function isCypressCommandDeclaration (declarator) { | ||
let object = get(declarator, 'init.callee.object') | ||
if (!object) { return; } | ||
if (!object) return | ||
while (object.callee) { | ||
object = object.callee.object; | ||
if (!object) { | ||
return; | ||
} | ||
object = object.callee.object | ||
if (!object) return | ||
} | ||
return object.name === 'cy'; | ||
const commandName = get(object, 'parent.property.name') | ||
if (commandName && whitelistedCommands[commandName]) return | ||
return object.name === 'cy' | ||
} |
@@ -6,3 +6,3 @@ /** | ||
'use strict'; | ||
'use strict' | ||
@@ -15,21 +15,21 @@ module.exports = { | ||
recommended: true, | ||
url: 'https://docs.cypress.io/guides/references/best-practices.html#Unnecessary-Waiting' | ||
url: 'https://docs.cypress.io/guides/references/best-practices.html#Unnecessary-Waiting', | ||
}, | ||
schema: [], | ||
messages: { | ||
unexpected: 'Do not wait for arbitrary time periods' | ||
} | ||
unexpected: 'Do not wait for arbitrary time periods', | ||
}, | ||
}, | ||
create(context) { | ||
create (context) { | ||
return { | ||
CallExpression(node) { | ||
CallExpression (node) { | ||
if (isCallingCyWait(node) && isNumberArgument(node)) { | ||
context.report({ node, messageId: 'unexpected' }); | ||
context.report({ node, messageId: 'unexpected' }) | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
}, | ||
} | ||
}, | ||
} | ||
function isCallingCyWait(node) { | ||
function isCallingCyWait (node) { | ||
return node.callee.type === 'MemberExpression' && | ||
@@ -39,9 +39,9 @@ node.callee.object.type === 'Identifier' && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'wait'; | ||
node.callee.property.name === 'wait' | ||
} | ||
function isNumberArgument(node) { | ||
function isNumberArgument (node) { | ||
return node.arguments.length > 0 && | ||
node.arguments[0].type === 'Literal' && | ||
typeof(node.arguments[0].value) === 'number'; | ||
typeof (node.arguments[0].value) === 'number' | ||
} |
@@ -1,1 +0,1 @@ | ||
{"name":"eslint-plugin-cypress","version":"2.1.2","description":"An ESLint plugin for projects using Cypress","main":"index.js","author":"Chris Breiding (chris@cypress.io)","license":"MIT","keywords":["eslint","eslintplugin","cypress"],"repository":{"type":"git","url":"git+https://github.com/cypress-io/eslint-plugin-cypress.git"},"bugs":{"url":"https://github.com/cypress-io/eslint-plugin-cypress/issues"},"homepage":"https://github.com/cypress-io/eslint-plugin-cypress#readme","peerDependencies":{"eslint":">= 3.2.1"},"dependencies":{"globals":"^11.0.1"},"devDependencies":{"condition-circle":"1.5.0","eslint":"^5.7.0","eslint-plugin-cypress-dev":"1.1.2","github-post-release":"1.13.1","husky":"^0.14.3","jest":"^23.6.0","semantic-release":"8.2.0","simple-commit-message":"3.3.1"},"scripts":{"precommit":"npm run lint","lint":"eslint *.js","semantic-release":"semantic-release pre && npm publish --access public && semantic-release post","start":"yarn run test:watch","test":"jest","test-watch":"jest --watchAll"},"release":{"verifyConditions":"condition-circle","analyzeCommits":"simple-commit-message","generateNotes":"github-post-release"},"jest":{"testMatch":["**/tests/**/*.js"]}} | ||
{"name":"eslint-plugin-cypress","version":"2.1.3","description":"An ESLint plugin for projects using Cypress","main":"index.js","author":"Chris Breiding (chris@cypress.io)","license":"MIT","keywords":["eslint","eslintplugin","cypress"],"repository":{"type":"git","url":"git+https://github.com/cypress-io/eslint-plugin-cypress.git"},"bugs":{"url":"https://github.com/cypress-io/eslint-plugin-cypress/issues"},"homepage":"https://github.com/cypress-io/eslint-plugin-cypress#readme","peerDependencies":{"eslint":">= 3.2.1"},"dependencies":{"globals":"^11.0.1"},"devDependencies":{"condition-circle":"1.5.0","eslint":"^5.7.0","eslint-plugin-cypress-dev":"1.1.2","github-post-release":"1.13.1","husky":"^0.14.3","jest":"^23.6.0","semantic-release":"8.2.0","simple-commit-message":"3.3.1"},"scripts":{"precommit":"npm run lint","lint":"eslint *.js","semantic-release":"semantic-release pre && npm publish --access public && semantic-release post","start":"yarn run test:watch","test":"jest","test-watch":"jest --watchAll"},"release":{"verifyConditions":"condition-circle","analyzeCommits":"simple-commit-message","generateNotes":"github-post-release"},"jest":{"testMatch":["**/tests/**/*.js"]}} |
@@ -1,10 +0,10 @@ | ||
"use strict"; | ||
'use strict' | ||
const rule = require('../../../lib/rules/no-assigning-return-values'); | ||
const RuleTester = require('eslint').RuleTester; | ||
const rule = require('../../../lib/rules/no-assigning-return-values') | ||
const RuleTester = require('eslint').RuleTester | ||
const ruleTester = new RuleTester(); | ||
const ruleTester = new RuleTester() | ||
const errors = [{ messageId: 'unexpected' }]; | ||
const parserOptions = { ecmaVersion: 6 }; | ||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 6 } | ||
@@ -18,4 +18,8 @@ ruleTester.run('no-assigning-return-values', rule, { | ||
{ code: 'const foo = bar().baz();', parserOptions }, | ||
{ code: 'const spy = cy.spy();', parserOptions }, | ||
{ code: 'const stub = cy.stub();', parserOptions }, | ||
{ code: 'const result = cy.now();', parserOptions }, | ||
{ code: 'const state = cy.state();', parserOptions }, | ||
{ code: 'cy.get("foo");', parserOptions }, | ||
{ code: 'cy.contains("foo").click();', parserOptions } | ||
{ code: 'cy.contains("foo").click();', parserOptions }, | ||
], | ||
@@ -32,4 +36,4 @@ | ||
{ code: 'let a = cy.contains("foo").click()', parserOptions, errors } | ||
] | ||
}); | ||
{ code: 'let a = cy.contains("foo").click()', parserOptions, errors }, | ||
], | ||
}) |
@@ -1,10 +0,10 @@ | ||
"use strict"; | ||
'use strict' | ||
const rule = require('../../../lib/rules/no-unnecessary-waiting'); | ||
const RuleTester = require('eslint').RuleTester; | ||
const rule = require('../../../lib/rules/no-unnecessary-waiting') | ||
const RuleTester = require('eslint').RuleTester | ||
const ruleTester = new RuleTester(); | ||
const ruleTester = new RuleTester() | ||
const errors = [{ messageId: 'unexpected' }]; | ||
const parserOptions = { ecmaVersion: 6 }; | ||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 6 } | ||
@@ -18,5 +18,5 @@ ruleTester.run('no-unnecessary-waiting', rule, { | ||
{ code: 'cy.clock(5000)', parserOptions}, | ||
{ code: 'cy.clock(5000)', parserOptions }, | ||
{ code: 'cy.scrollTo(0, 10)', parserOptions }, | ||
{ code: 'cy.tick(500)', parserOptions } | ||
{ code: 'cy.tick(500)', parserOptions }, | ||
], | ||
@@ -27,4 +27,4 @@ | ||
{ code: 'cy.wait(100)', parserOptions, errors }, | ||
{ code: 'cy.wait(5000)', parserOptions, errors } | ||
] | ||
}); | ||
{ code: 'cy.wait(5000)', parserOptions, errors }, | ||
], | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9880
184