Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cypress-io/eslint-plugin-cypress
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.11.2
Choose a base ref
...
head repository: cypress-io/eslint-plugin-cypress
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.11.3
Choose a head ref
  • 2 commits
  • 4 files changed
  • 3 contributors

Commits on Apr 27, 2021

  1. chore(docs): Explain how to temporarily disable rules (#81)

    Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
    bahmutov and chrisbreiding authored Apr 27, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e9e8a77 View commit details

Commits on May 4, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    61a9de1 View commit details
Showing with 77 additions and 8 deletions.
  1. +45 −0 README.md
  2. +1 −1 lib/rules/no-force.js
  3. +8 −7 tests/lib/rules/no-force.js
  4. +23 −0 tests/lib/rules/no-unnecessary-waiting.js
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -62,6 +62,51 @@ Use the recommended configuration and you can forego configuring _plugins_, _rul
}
```

## Disable rules

You can disable specific rules per file, for a portion of a file, or for a single line.

Disable the `cypress/no-unnecessary-waiting` rule for the entire file by placing this at the start of the file:

```js
/* eslint-disable cypress/no-unnecessary-waiting */
```

Disable the `cypress/no-unnecessary-waiting` rule for a portion of the file:

```js
it('waits for a second', () => {
...
/* eslint-disable cypress/no-unnecessary-waiting */
cy.wait(1000)
/* eslint-enable cypress/no-unnecessary-waiting */
...
})
```

Disable the `cypress/no-unnecessary-waiting` rule for a specific line:

```js
it('waits for a second', () => {
...
cy.wait(1000) // eslint-disable-line cypress/no-unnecessary-waiting
...
})
```

You can also disable a rule for the next line:

```js
it('waits for a second', () => {
...
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000)
...
})
```

For more, see the [ESLint rules](https://eslint.org/docs/user-guide/configuring/rules) documentation.

## Rules

These rules enforce some of the [best practices recommended for using Cypress](https://on.cypress.io/best-practices).
2 changes: 1 addition & 1 deletion lib/rules/no-force.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ module.exports = {

return node.arguments && node.arguments.length &&
node.arguments.some((arg) => {
return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key.name === 'force')
return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key && propNode.key.name === 'force')
})
}

15 changes: 8 additions & 7 deletions tests/lib/rules/no-force.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const rule = require('../../../lib/rules/no-force')
const RuleTester = require('eslint').RuleTester

const errors = [{ messageId: 'unexpected' }]
const parserOptions = { ecmaVersion: 6 }
const parserOptions = { ecmaVersion: 2018 }

//------------------------------------------------------------------------------
// Tests
@@ -24,12 +24,13 @@ ruleTester.run('no-force', rule, {
{ code: `cy.get('button').click({multiple: true})`, parserOptions },
{ code: `cy.get('button').dblclick()`, parserOptions },
{ code: `cy.get('input').type('somth')`, parserOptions },
{ code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions, errors },
{ code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions, errors },
{ code: `cy.get('input').rightclick({anyoption: true})`, parserOptions, errors },
{ code: `cy.get('input').check()`, parserOptions, errors },
{ code: `cy.get('input').select()`, parserOptions, errors },
{ code: `cy.get('input').focus()`, parserOptions, errors },
{ code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions },
{ code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions },
{ code: `cy.get('input').rightclick({anyoption: true})`, parserOptions },
{ code: `cy.get('input').check()`, parserOptions },
{ code: `cy.get('input').select()`, parserOptions },
{ code: `cy.get('input').focus()`, parserOptions },
{ code: `cy.document().trigger("keydown", { ...event })`, parserOptions },
],

invalid: [
23 changes: 23 additions & 0 deletions tests/lib/rules/no-unnecessary-waiting.js
Original file line number Diff line number Diff line change
@@ -26,6 +26,29 @@ ruleTester.run('no-unnecessary-waiting', rule, {
{ code: 'const customWait = (alias = "@someRequest") => { cy.wait(alias) }', parserOptions, errors },
{ code: 'function customWait (ms) { cy.wait(ms) }', parserOptions, errors },
{ code: 'const customWait = (ms) => { cy.wait(ms) }', parserOptions, errors },

// disable the eslint rule
{
code: `
cy.wait(100); // eslint-disable-line no-unnecessary-waiting
`,
parserOptions,
},
{
code: `
/* eslint-disable-next-line no-unnecessary-waiting */
cy.wait(100)
`,
parserOptions,
},
{
code: `
/* eslint-disable no-unnecessary-waiting */
cy.wait(100)
/* eslint-enable no-unnecessary-waiting */
`,
parserOptions,
},
],

invalid: [