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

Adds a recommended config with new no-assigning-return-values rule #6

Conversation

SaladFork
Copy link
Contributor

@SaladFork SaladFork commented Oct 25, 2018

Adds an opinionated rule as suggested in #4. Tries to help with the "Assigning Return Values" Best Practice described in the guide, something that bit me when I was first trying out Cypress.

When writing the rules and the folder layout, I tried to follow the practices described in the ESLint guide. I also chose jest as the test runner but it can be easily switched to Mocha or whatever a maintainer would prefer.

I also updated the readme to instruct on how to add the recommended config, as well as a list of rules and instructions for developing new rules.

Known shortcomings:

  • This rule should catch any assignment type (let, const, var). However, it will not catch more complex assignment operations such as destructuring: let [a, b] = [true, cypress.get('foo')].

Feedback/ideas on this or other potential rules welcome.


Example:

// cypress/.eslintrc.js
module.exports = {
  plugins: ['cypress'],
  extends: 'plugin:cypress/recommended',
  env: {
    'cypress/globals': true
  }
}
// cypress/test.js
describe('something', () => {
  it('might do a thing', () => {
    let a = cy.contains('Submit');
    a.click();
  });
});
$ yarn run eslint cypress/test.js

./cypress/test.js
  3:5  error  Do not assign the return value of a Cypress command  cypress/no-assigning-return-values

✖ 1 problem (1 error, 0 warnings)

@SaladFork SaladFork force-pushed the feature/add-no-assigning-return-values-rule branch from 2736f5d to 41cd775 Compare October 30, 2018 14:48
Copy link
Contributor

@chrisbreiding chrisbreiding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Thanks for contributing this. I added just one minor change request, but otherwise it looks good. Once this is in, I'll add a CircleCI config so the tests get run in CI.

package.json Outdated Show resolved Hide resolved
Adds an opinionated rule as suggested in cypress-io#4. Tries to help with the
"Assigning Return Values" Best Practice described in the guide:
  <https://docs.cypress.io/guides/references/best-practices.html#Assigning-Return-Values>
@SaladFork SaladFork force-pushed the feature/add-no-assigning-return-values-rule branch from 41cd775 to 74f592b Compare November 2, 2018 19:47
@chrisbreiding chrisbreiding merged commit ad207bb into cypress-io:master Nov 2, 2018
@chrisbreiding
Copy link
Contributor

Released in v2.1.0 🎉

@SaladFork SaladFork deleted the feature/add-no-assigning-return-values-rule branch November 5, 2018 19:10
tobiasweibel added a commit to tobiasweibel/codacy-eslint that referenced this pull request May 14, 2019
Basically to support using recommended rules. They were added in cypress-io/eslint-plugin-cypress#6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants