Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

add rule no-unused-expressions=off #698

Merged
merged 3 commits into from
Oct 3, 2018
Merged

add rule no-unused-expressions=off #698

merged 3 commits into from
Oct 3, 2018

Conversation

lysz210
Copy link

@lysz210 lysz210 commented Sep 21, 2018

some chai tests may trigger the eslint no-used-expressions

  ✘  http://eslint.org/docs/rules/no-unused-expressions  Expected an assignment or function call and instead saw an expression
  path/to/test.spec.js:62:9
          expect(await proxy[ID_APPARECCHIO]).to.not.be.undefined
           ^


✘ 1 problem (1 error, 0 warnings)


Errors:
  1  http://eslint.org/docs/rules/no-unused-expressions

the solution is a copy & paste from Eslint docs

some chai tests may trigger the eslint no-used-expressions
```
  ✘  http://eslint.org/docs/rules/no-unused-expressions  Expected an assignment or function call and instead saw an expression
  path/to/test.spec.js:62:9
          expect(await proxy[ID_APPARECCHIO]).to.not.be.undefined
           ^


✘ 1 problem (1 error, 0 warnings)


Errors:
  1  http://eslint.org/docs/rules/no-unused-expressions
```
the solution is a copy & paste from [Eslint docs](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files)
Copy link
Collaborator

@XanderLuciano XanderLuciano left a comment

Choose a reason for hiding this comment

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

Hmm this is an interesting situation. While your solution does fix the issue, I'm not sure if it's the best option available. After doing some quick research there are a few different ways to address this issue. For instance there is an es lint plugin that correctly fixes this issue for the just the expressions affected.

https://www.npmjs.com/package/eslint-plugin-chai-friendly

[This] overrides the default no-unused-expressions rule and makes it friendly towards chai. The modified rule ignores the expect and should statements while keeping default behavior for everything else.

This could then be combined with your proposal to only use this plugin on test files:

// .eslintrc.js
module.exports = {
  // ...
  plugins: ['chai-friendly'],
  overrides: [{
    files: ['*-test.js', '*.spec.js'],
    rules: {
      'no-unused-expressions': 'off',
      'chai-friendly/no-unused-expressions': 'off',
    },
  }],
  // ...
}

Note: we still disable no-unused-expressions per chai-friendly's documentation.

sourced from: https://stackoverflow.com/questions/37558795/nice-way-to-get-rid-of-no-unused-expressions-linter-error-with-chai

@lysz210
Copy link
Author

lysz210 commented Sep 24, 2018

@XanderLuciano I like the plugin solution and.
we may try to add also:

{
 ...
 env: {
  ...,
  mocha: process.env.NODE_ENV !== 'production'
 }
}

It's suggested by Pierre-Adrien Builsson in the post you linked.

@XanderLuciano XanderLuciano self-assigned this Oct 1, 2018
@XanderLuciano XanderLuciano merged commit 8213afd into SimulatedGREG:dev Oct 3, 2018
@XanderLuciano
Copy link
Collaborator

Verified template still functions and passes test, merged PR.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants