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

Fixes #80: Support ESLint's flat configuration format #82

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@
"bracketSpacing": false
}],
"no-console": "error"
}
},
"overrides": [
{
"files": "*.mjs",
"parserOptions": {
"sourceType": "module"
}
}
]
}
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- run: npm ci
- run: npm run lint
- run: npm run test
- run: npm run integration ci 7 8 # eslint versions
- run: npm run integration test 7 8 # eslint versions
- run: npm run integration ci 7-legacy 8-legacy 8 # eslint versions
- run: npm run integration test 7-legacy 8-legacy 8 # eslint versions
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
Expand Down
57 changes: 52 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,31 @@ $ yarn add --dev eslint eslint-plugin-json

## Usage

### Basic configuration
### Basic configuration (Flat Config ESLint Format)

The `json` plugin ship with two recommended config you can use to easily activate it via the `extends` key.
It comes in two flavor: one strict (`recommended`) and one allowing comments `recommended-with-comments`.


```js
{
export default [
{
files: ["**/*.json"],
...json.configs["recommended"],
];
}
```
### Basic configuration (Legacy ESLint Format)
The `json` plugin ship with two recommended config you can use to easily activate it via the `extends` key.
It comes in two flavor: one strict (`recommended-legacy`) and one allowing comments `recommended-with-comments-legacy`.
```json
{
"extends": ["plugin:json/recommended"]
"extends": ["plugin:json/recommended-legacy"]
}
```
Expand All @@ -43,14 +59,45 @@ eslint . --ext .json,.js
eslint example.json
```
### Custom Configuration
### Custom Configuration (Flat Config ESLint Format)
If you want more granular control over which rules, and which severity you want.
If you want more granular control over which rules, and wich severity you want
If you want them all, add the `json/json` rule (or its alias `json/*`). (this is what the `recommended` config does)
#### Global rules
The global rules (`json/json` or its alias `json/*`) activate all the rules.
Note it can be configured to ignore errors cause by comments.
To do so, add option `'allowComments'` or `{allowComments: true}`
For instance:
```js
{
import json from "eslint-plugin-json";
export default [
{
files: ["**/*.json"],
plugins: { json },
processor: "json/json"
"rules": {
"json/*": ["error", "allowComments"],
// or the equivalent:
"json/*": ["error", {"allowComments": true}]
}
},
];
}
```
### Custom Configuration (Legacy ESLint Format)
If you want more granular control over which rules, and which severity you want.
Add `json` to the list of plugins (You can omit the `eslint-plugin-` prefix)
Then pick your rules.
If you want them all, add the `json/json` rule (or its alias `json/*`). (this is what the `recommended` config does)
If you want them all, add the `json/json` rule (or its alias `json/*`). (this is what the `recommended-legacy` config does)
#### Global rules
The global rules (`json/json` or its alias `json/*`) activate all the rules.
Expand Down
Loading
Loading