Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,51 @@ Use the recommended configuration and you can forego configuring _plugins_, _rul
}
```

## Disable rules

You can disable a specific rule(s) per file, for a portion of a file, or for a single line. For example:

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

```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 the specific line:

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

You can also disable the 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).
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/no-unnecessary-waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down