eslint-plugin-cypress 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.json CHANGED
@@ -1,8 +1,40 @@
1
1
  {
2
+ "env": {
3
+ "node": true,
4
+ "es6": true
5
+ },
2
6
  "plugins": [
3
- "@cypress/dev"
7
+ "eslint-plugin",
8
+ "n",
9
+ "mocha"
4
10
  ],
5
11
  "extends": [
6
- "plugin:@cypress/dev/general"
7
- ]
12
+ "eslint:recommended",
13
+ "plugin:eslint-plugin/recommended",
14
+ "plugin:n/recommended",
15
+ "plugin:mocha/recommended"
16
+ ],
17
+ "rules": {
18
+ "eslint-plugin/require-meta-docs-url": [
19
+ "error",
20
+ {
21
+ "pattern": "https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md"
22
+ }
23
+ ],
24
+ "eslint-plugin/require-meta-docs-description": "error",
25
+ "n/no-extraneous-require": [
26
+ "error",
27
+ {
28
+ "allowModules": [
29
+ "jest-config"
30
+ ]
31
+ }
32
+ ],
33
+ "no-redeclare": "off",
34
+ "mocha/no-mocha-arrows": "off",
35
+ "mocha/no-setup-in-describe": "off"
36
+ },
37
+ "parserOptions": {
38
+ "ecmaVersion": 2020
39
+ }
8
40
  }
package/circle.yml CHANGED
@@ -41,6 +41,9 @@ jobs:
41
41
  - run:
42
42
  name: Install dependencies
43
43
  command: npm ci
44
+ - run:
45
+ name: Remove unneeded plugins # minimum eslint@8.23.0 required
46
+ command: npm uninstall eslint-plugin-eslint-plugin eslint-plugin-n
44
47
  - run:
45
48
  name: Install ESLint 7
46
49
  command: npm install eslint@7
@@ -1,6 +1,6 @@
1
1
  # Prevent using async/await in Cypress test cases (no-async-tests)
2
2
 
3
- Cypress commands that return a promise may cause side effects in before/beforeEach hooks, possibly causing unexpected behavior.
3
+ Cypress commands that return a promise may cause side effects in before/beforeEach hooks, possibly causing unexpected behavior.
4
4
 
5
5
  ## Rule Details
6
6
 
@@ -47,6 +47,5 @@ If there are genuine use-cases for using `async/await` in your before then you m
47
47
 
48
48
  ## Further Reading
49
49
 
50
- - [Commands Are Asynchronous](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)
51
- - [Commands Are Promises](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Promises)
52
- - [Commands Are Not Promises](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Not-Promises)
50
+ - [Mixing Async and Sync code](https://on.cypress.io/guides/core-concepts/introduction-to-cypress#Mixing-Async-and-Sync-code)
51
+ - [Commands Are Asynchronous](https://on.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)
@@ -47,6 +47,5 @@ If there are genuine use-cases for using `async/await` in your test cases then y
47
47
 
48
48
  ## Further Reading
49
49
 
50
- - [Commands Are Asynchronous](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)
51
- - [Commands Are Promises](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Promises)
52
- - [Commands Are Not Promises](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Not-Promises)
50
+ - [Mixing Async and Sync code](https://on.cypress.io/guides/core-concepts/introduction-to-cypress#Mixing-Async-and-Sync-code)
51
+ - [Commands Are Asynchronous](https://on.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)
package/index.js CHANGED
@@ -5,6 +5,7 @@ module.exports = {
5
5
  'no-assigning-return-values': require('./lib/rules/no-assigning-return-values'),
6
6
  'unsafe-to-chain-command': require('./lib/rules/unsafe-to-chain-command'),
7
7
  'no-unnecessary-waiting': require('./lib/rules/no-unnecessary-waiting'),
8
+ 'no-async-before': require('./lib/rules/no-async-before'),
8
9
  'no-async-tests': require('./lib/rules/no-async-tests'),
9
10
  'assertion-before-screenshot': require('./lib/rules/assertion-before-screenshot'),
10
11
  'require-data-selectors': require('./lib/rules/require-data-selectors'),
@@ -16,10 +16,12 @@ const assertionCommands = [
16
16
 
17
17
  module.exports = {
18
18
  meta: {
19
+ type: 'problem',
19
20
  docs: {
20
- description: 'Assert on the page state before taking a screenshot, so the screenshot is consistent',
21
+ description: 'require screenshots to be preceded by an assertion',
21
22
  category: 'Possible Errors',
22
23
  recommended: false,
24
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/assertion-before-screenshot.md',
23
25
  },
24
26
  schema: [],
25
27
  messages: {
@@ -17,11 +17,12 @@ function get (obj, propertyString = '') {
17
17
 
18
18
  module.exports = {
19
19
  meta: {
20
+ type: 'problem',
20
21
  docs: {
21
- description: 'Prevent assigning return values of cy calls',
22
+ description: 'disallow assigning return values of `cy` calls',
22
23
  category: 'Possible Errors',
23
24
  recommended: true,
24
- url: 'https://on.cypress.io/best-practices#Assigning-Return-Values',
25
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-assigning-return-values.md',
25
26
  },
26
27
  schema: [],
27
28
  messages: {
@@ -2,11 +2,14 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'problem',
5
6
  docs: {
6
- description: 'Prevent using async/await in Cypress before methods',
7
+ description: 'disallow using `async`/`await` in Cypress `before` methods',
7
8
  category: 'Possible Errors',
8
9
  recommended: true,
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-async-before.md',
9
11
  },
12
+ schema: [],
10
13
  messages: {
11
14
  unexpected: 'Avoid using async functions with Cypress before / beforeEach functions',
12
15
  },
@@ -25,11 +28,14 @@ module.exports = {
25
28
  && node.arguments.length >= 2
26
29
  && node.arguments[1].async === true
27
30
  }
31
+ const sourceCode = context.sourceCode ?? context.getSourceCode()
28
32
 
29
33
  return {
30
34
  Identifier (node) {
31
35
  if (node.name === 'cy' || node.name === 'Cypress') {
32
- const ancestors = context.getAncestors()
36
+ const ancestors = sourceCode.getAncestors
37
+ ? sourceCode.getAncestors(node)
38
+ : context.getAncestors()
33
39
  const asyncTestBlocks = ancestors
34
40
  .filter((n) => n.type === 'CallExpression')
35
41
  .filter(isBeforeBlock)
@@ -2,11 +2,14 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'problem',
5
6
  docs: {
6
- description: 'Prevent using async/await in Cypress test cases',
7
+ description: 'disallow using `async`/`await` in Cypress test cases',
7
8
  category: 'Possible Errors',
8
9
  recommended: true,
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-async-tests.md',
9
11
  },
12
+ schema: [],
10
13
  messages: {
11
14
  unexpected: 'Avoid using async functions with Cypress tests',
12
15
  },
@@ -25,11 +28,14 @@ module.exports = {
25
28
  && node.arguments.length >= 2
26
29
  && node.arguments[1].async === true
27
30
  }
31
+ const sourceCode = context.sourceCode ?? context.getSourceCode()
28
32
 
29
33
  return {
30
34
  Identifier (node) {
31
35
  if (node.name === 'cy' || node.name === 'Cypress') {
32
- const ancestors = context.getAncestors()
36
+ const ancestors = sourceCode.getAncestors
37
+ ? sourceCode.getAncestors(node)
38
+ : context.getAncestors()
33
39
  const asyncTestBlocks = ancestors
34
40
  .filter((n) => n.type === 'CallExpression')
35
41
  .filter(isTestBlock)
@@ -6,10 +6,12 @@
6
6
 
7
7
  module.exports = {
8
8
  meta: {
9
+ type: 'suggestion',
9
10
  docs: {
10
- description: 'Disallow using of \'force: true\' option for click and type calls',
11
+ description: 'disallow using `force: true` with action commands',
11
12
  category: 'Possible Errors',
12
13
  recommended: false,
14
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-force.md',
13
15
  },
14
16
  fixable: null, // or "code" or "whitespace"
15
17
  schema: [],
@@ -6,10 +6,12 @@
6
6
 
7
7
  module.exports = {
8
8
  meta: {
9
+ type: 'suggestion',
9
10
  docs: {
10
- description: 'Disallow using of \'cy.pause\' calls',
11
+ description: 'disallow using `cy.pause()` calls',
11
12
  category: 'Possible Errors',
12
13
  recommended: false,
14
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-pause.md',
13
15
  },
14
16
  fixable: null, // or "code" or "whitespace"
15
17
  schema: [],
@@ -2,11 +2,12 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'problem',
5
6
  docs: {
6
- description: 'Prevent waiting for arbitrary time periods',
7
+ description: 'disallow waiting for arbitrary time periods',
7
8
  category: 'Possible Errors',
8
9
  recommended: true,
9
- url: 'https://on.cypress.io/best-practices#Unnecessary-Waiting',
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-unnecessary-waiting.md',
10
11
  },
11
12
  schema: [],
12
13
  messages: {
@@ -14,10 +15,14 @@ module.exports = {
14
15
  },
15
16
  },
16
17
  create (context) {
18
+ const sourceCode = context.sourceCode ?? context.getSourceCode()
19
+
17
20
  return {
18
21
  CallExpression (node) {
19
22
  if (isCallingCyWait(node)) {
20
- const scope = context.getScope()
23
+ const scope = sourceCode.getScope
24
+ ? sourceCode.getScope(node)
25
+ : context.getScope()
21
26
 
22
27
  if (isIdentifierNumberConstArgument(node, scope) || isNumberArgument(node)) {
23
28
  context.report({ node, messageId: 'unexpected' })
@@ -2,11 +2,12 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'suggestion',
5
6
  docs: {
6
- description: 'Use data-* attributes to provide context to your selectors and insulate them from CSS or JS changes https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements',
7
+ description: 'require `data-*` attribute selectors',
7
8
  category: 'Possible Errors',
8
9
  recommended: false,
9
- url: 'https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements',
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/require-data-selectors.md',
10
11
  },
11
12
  schema: [],
12
13
  messages: {
@@ -3,7 +3,7 @@
3
3
  const { basename } = require('path')
4
4
 
5
5
  const NAME = basename(__dirname)
6
- const DESCRIPTION = 'Actions should be in the end of chains, not in the middle'
6
+ const DESCRIPTION = 'disallow actions within chains'
7
7
 
8
8
  /**
9
9
  * Commands listed in the documentation with text: 'It is unsafe to chain further commands that rely on the subject after xxx.'
@@ -69,11 +69,12 @@ const getDefaultOptions = (context) => {
69
69
  /** @type {import('eslint').Rule.RuleModule} */
70
70
  module.exports = {
71
71
  meta: {
72
+ type: 'problem',
72
73
  docs: {
73
74
  description: DESCRIPTION,
74
75
  category: 'Possible Errors',
75
76
  recommended: true,
76
- url: 'https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle',
77
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/unsafe-to-chain-command.md',
77
78
  },
78
79
  schema: [schema],
79
80
  messages: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "index.js",
6
6
  "author": "Cypress-io",
@@ -25,19 +25,14 @@
25
25
  "globals": "^13.20.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@cypress/eslint-plugin-dev": "3.9.1",
29
- "@cypress/eslint-plugin-json": "3.2.3",
30
- "@typescript-eslint/eslint-plugin": "^4.33.0",
31
- "@typescript-eslint/parser": "^4.33.0",
32
- "eslint": "^7.32.0",
33
- "eslint-plugin-mocha": "^6.3.0",
28
+ "eslint": "^8.57.0",
29
+ "eslint-plugin-eslint-plugin": "^6.0.0",
30
+ "eslint-plugin-mocha": "^10.4.3",
31
+ "eslint-plugin-n": "^17.2.1",
34
32
  "husky": "^8.0.3",
35
33
  "jest": "^29.7.0",
36
34
  "semantic-release": "19.0.3"
37
35
  },
38
- "overrides": {
39
- "eslint-plugin-mocha": "$eslint-plugin-mocha"
40
- },
41
36
  "scripts": {
42
37
  "lint": "eslint \"*.js\" \"**/**/*.js\"",
43
38
  "lint-fix": "npm run lint -- --fix",
@@ -15,7 +15,7 @@ ruleTester.run('require-data-selectors', rule, {
15
15
  { code: 'cy.clock(5000)', parserOptions },
16
16
  { code: 'cy.scrollTo(0, 10)', parserOptions },
17
17
  { code: 'cy.tick(500)', parserOptions },
18
- { code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions },
18
+ { code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions }, // eslint-disable-line no-useless-escape
19
19
  { code: 'cy.get("@my-alias")', parserOptions, errors },
20
20
  { code: 'cy.get(`@my-alias`)', parserOptions, errors },
21
21
  ],
@@ -26,6 +26,6 @@ ruleTester.run('require-data-selectors', rule, {
26
26
  { code: 'cy.get(".btn-large").click()', parserOptions, errors },
27
27
  { code: 'cy.get(".btn-.large").click()', parserOptions, errors },
28
28
  { code: 'cy.get(".a")', parserOptions, errors },
29
- { code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors },
29
+ { code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors }, // eslint-disable-line no-useless-escape
30
30
  ],
31
31
  })