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: ihordiachenko/eslint-plugin-chai-friendly
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.7.4
Choose a base ref
...
head repository: ihordiachenko/eslint-plugin-chai-friendly
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.8.0
Choose a head ref
  • 4 commits
  • 10 files changed
  • 4 contributors

Commits on Mar 15, 2024

  1. Use "files" instead of .npmignore (#24)

    Fixes the fact that eg. `.nyc_output` gets published to npm.
    
    Reason why `.nyc_output` is currently published to npm is that `.npmignore` _replaces_ `.gitignore`, rather than extends it.
    voxpelli authored Mar 15, 2024
    Copy the full SHA
    3055947 View commit details

Commits on May 19, 2024

  1. Copy the full SHA
    4a33848 View commit details

Commits on May 23, 2024

  1. Added ESLint v9 flat config support (#34)

    * make the entrypoint compatible with eslint v9
    
    * Add a local test
    
    * Updated readme
    
    * Added a flat config compatibility check
    
    * Use eslint 9 for local development
    
    * Fix unit tests
    
    * Remove ESLint ignore
    
    * Update README.md
    
    Co-authored-by: Brett Zamir <brettz9@yahoo.com>
    
    ---------
    
    Co-authored-by: Brett Zamir <brettz9@yahoo.com>
    ihordiachenko and brettz9 authored May 23, 2024
    Copy the full SHA
    7321fbc View commit details
  2. 0.8.0

    ihordiachenko committed May 23, 2024
    Copy the full SHA
    3ab221e View commit details
Showing with 384 additions and 272 deletions.
  1. +0 −2 .eslintignore
  2. +0 −1 .npmignore
  3. +33 −12 README.md
  4. +10 −0 eslint.config.js
  5. +9 −0 examples/test.js
  6. +24 −10 lib/index.js
  7. +6 −2 lib/rules/no-unused-expressions.js
  8. +219 −170 package-lock.json
  9. +8 −3 package.json
  10. +75 −72 tests/lib/rules/no-unused-expressions.js
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

45 changes: 33 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -32,31 +32,52 @@ npm install eslint-plugin-chai-friendly --save-dev

## Usage

Add `chai-friendly` to the plugins section of your `.eslintrc.*` configuration file. You can omit the `eslint-plugin-` prefix:
Add `chai-friendly` to the plugins section of your ESLint configuration file. Then disable original `no-unused-expressions` rule and configure chai-friendly replacement under the rules section.

```json
{
"plugins": [
"chai-friendly"
]
}
```
ESLint 9 flat config format:

```js
import pluginChaiFriendly from 'eslint-plugin-chai-friendly';

export default {
plugins: {'chai-friendly': pluginChaiFriendly},
rules: {
"no-unused-expressions": "off", // disable original rule
"chai-friendly/no-unused-expressions": "error"
},
};
```

Then disable original `no-unused-expressions` rule and configure chai-friendly replacement under the rules section.
Legacy `.eslintrc` format:

```json
{
"plugins": [
"chai-friendly" // you can omit the eslint-plugin- prefix
],
"rules": {
"no-unused-expressions": 0,
"no-unused-expressions": 0, // disable original rule
"chai-friendly/no-unused-expressions": 2
}
}
```

If you don't need to tweak the above rule settings, you can instead
just add the following to your config file's `extends` and the above
will be applied automatically:
extend the provided recommended configuration.

ESLint 9 flat config format:

```js
const pluginChaiFriendly = require("eslint-plugin-chai-friendly");

module.exports = [
pluginChaiFriendly.configs.recommended,
// other configurations
]
```

Legacy `.eslintrc` format:


```json
{
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";

const pluginChaiFriendly = require("./lib");

module.exports = [
pluginChaiFriendly.configs.recommended,
{
ignores: ["node_modules", "!.eslintrc.js", "examples"],
}
]
9 changes: 9 additions & 0 deletions examples/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { expect } = require('chai');

// these are valid chai expect statement that should not cause any linter errors
expect(true).to.be.true;
foo.should.be.true;

// this should cause unused expression error
const foo = {bar: 'baz'};
foo.bar;
34 changes: 24 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -3,17 +3,31 @@
* @author Ihor Diachenko
*/

module.exports = {
configs: {
recommended: {
plugins: ['chai-friendly'],
rules: {
'chai-friendly/no-unused-expressions': 'error',
'no-unused-expressions': 'off'
}
}
const pjs = require('../package.json');

const plugin = {
meta: {
name: pjs.name,
version: pjs.version,
},
rules: {
'no-unused-expressions': require('./rules/no-unused-expressions')
}
},
processors: {},
configs: {}
};

// assign configs here so we can reference `plugin`
Object.assign(plugin.configs, {
recommended: {
plugins: {
'chai-friendly': plugin
},
rules: {
'chai-friendly/no-unused-expressions': 'error',
'no-unused-expressions': 'off'
}
}
},)

module.exports = plugin;
8 changes: 6 additions & 2 deletions lib/rules/no-unused-expressions.js
Original file line number Diff line number Diff line change
@@ -255,11 +255,15 @@ module.exports = {
return null;
}


const sourceCode = context.sourceCode ?? context.getSourceCode();
return {
ExpressionStatement: function(node) {
var valid = !Checker.isDisallowed(node.expression)
|| isDirective(node, context.getAncestors())
|| isDirective(node,
(sourceCode.getAncestors
? sourceCode.getAncestors(node)
: context.getAncestors()
))
|| isChaiExpectCall(node)
|| isChaiShouldCall(node);
if (!valid) {
Loading