Skip to content

Commit

Permalink
Add flat config to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
BePo65 authored and Turbo87 committed Jun 13, 2024
1 parent 9cdc4da commit f185c29
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

ESLint plugin that checks for common chai.js `expect()` mistakes

> [!IMPORTANT]
> The `recommended` preset is for the ESLint legacy configuration system
> (`.eslintrc.json`). The `recommended-flat` configuration is for the new flat
> configuration system.
## Requirements

Expand All @@ -20,6 +24,8 @@ npm install --save-dev eslint-plugin-chai-expect

## Configuration

### Legacy ESLint Configuration Format (.eslintrc.json)

Add a `plugins` section and specify `chai-expect` as a plugin:

```json
Expand Down Expand Up @@ -52,6 +58,42 @@ and just extend the config:
}
```

### Flat ESLint Configuration Format (eslint.config.js)

Add a `plugins` section and specify `chai-expect` as a plugin and enable the rules that you would like to use:

```js
import chaiExpectPlugin from 'eslint-plugin-chai-expect';

export default [
{
"plugins": {
"chai-expect": chaiExpectPlugin
},
"rules": {
"chai-expect/no-inner-compare": 2,
"chai-expect/no-inner-literal": 2,
"chai-expect/missing-assertion": 2,
"chai-expect/terminating-properties": 2
}
}
];
```

Or, if you just want the above defaults, you can avoid all of the above
and just extend the config:

```js
import chaiExpectPlugin from 'eslint-plugin-chai-expect';

export default [
chaiExpectPlugin.configs["recommended-flat"],
{
// ...
},
];
```

## Rules

- `no-inner-compare` - Prevent using comparisons in the `expect()` argument
Expand Down
42 changes: 30 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
'use strict';

module.exports = {
configs: {
recommended: {
plugins: ['chai-expect'],
rules: {
'chai-expect/no-inner-compare': 'error',
'chai-expect/no-inner-literal': 'error',
'chai-expect/missing-assertion': 'error',
'chai-expect/terminating-properties': 'error'
}
}
const pkg = require('./package.json');

let recommendedRules = {
'chai-expect/no-inner-compare': 'error',
'chai-expect/no-inner-literal': 'error',
'chai-expect/missing-assertion': 'error',
'chai-expect/terminating-properties': 'error',
};

const plugin = {
meta: {
name: pkg.name,
version: pkg.version,
},
configs: {},
rules: {
'no-inner-compare': require('./lib/rules/no-inner-compare'),
'no-inner-literal': require('./lib/rules/no-inner-literal'),
'missing-assertion': require('./lib/rules/missing-assertion'),
'terminating-properties': require('./lib/rules/terminating-properties')
}
},
processors: {}
};

plugin.configs['recommended'] = {
plugins: ['chai-expect'],
rules: recommendedRules,
};

plugin.configs['recommended-flat'] = {
plugins: {
'chai-expect': plugin,
},
rules: recommendedRules,
};

module.exports = plugin;

0 comments on commit f185c29

Please sign in to comment.