Skip to content

Commit

Permalink
Added ESLint v9 flat config support (#34)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ihordiachenko and brettz9 authored May 23, 2024
1 parent 4a33848 commit 7321fbc
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 266 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

45 changes: 33 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
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
Expand Up @@ -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;
Loading

0 comments on commit 7321fbc

Please sign in to comment.