Skip to content

Commit

Permalink
feat: add jsonc plugin for json, jsonc lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun committed Jun 26, 2024
1 parent 253ed96 commit edb6b81
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-zebras-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperse/eslint-config-hyperse": patch
---

add jsonc plugin for json, jsonc lint
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,21 @@ Once you have done. You probably want your editor to lint and fix for you.
}
}
```

## Notes

we need to disable vscode editor language formatter for `json, jsonc`

```json:settings.json
"[jsonc]": {
"editor.formatOnSave": false,
"editor.tabSize": 2,
"editor.insertSpaces": true
},
"[json]": {
"editor.formatOnSave": false,
"editor.tabSize": 2,
"editor.insertSpaces": true
}

```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"app-root-path": "^3.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-define-config": "^2.1.0",
"eslint-plugin-jsonc": "^2.16.0",
"eslint-plugin-mdx": "^3.1.5",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
Expand Down
2 changes: 2 additions & 0 deletions src/main/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineFlatConfig } from 'eslint-define-config';
import {
imports,
jsonc,
mdx,
prettier,
regexp,
Expand All @@ -16,5 +17,6 @@ export const base = defineFlatConfig([
...prettier,
...regexp,
...sonar,
...jsonc,
...mdx,
]);
1 change: 1 addition & 0 deletions src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './imports.js';
export * from './jsonc.js';
export * from './mdx.js';
export * from './next.js';
export * from './prettier.js';
Expand Down
12 changes: 12 additions & 0 deletions src/rules/jsonc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineFlatConfig } from 'eslint-define-config';
import pluginJsonc from 'eslint-plugin-jsonc';

export const jsonc = defineFlatConfig([
...pluginJsonc.configs['flat/recommended-with-jsonc'],
{
rules: {
// override/add rules settings here, such as:
// 'jsonc/rule-name': 'error'
},
},
]);
7 changes: 0 additions & 7 deletions src/rules/prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@ export const prettier = defineFlatConfig([
'prettier/prettier': ['error', prettierConfig],
},
},
{
files: ['**/*.json'],
rules: {
'prettier/prettier': ['error', prettierConfig],
'@typescript-eslint/no-unused-expressions': 'off',
},
},
]);
60 changes: 55 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ __metadata:
eslint: "npm:^9.5.0"
eslint-config-prettier: "npm:^9.1.0"
eslint-define-config: "npm:^2.1.0"
eslint-plugin-jsonc: "npm:^2.16.0"
eslint-plugin-mdx: "npm:^3.1.5"
eslint-plugin-prettier: "npm:^5.1.3"
eslint-plugin-react: "npm:^7.34.3"
Expand Down Expand Up @@ -1849,7 +1850,7 @@ __metadata:
languageName: node
linkType: hard

"acorn@npm:^8.0.0, acorn@npm:^8.11.3, acorn@npm:^8.9.0":
"acorn@npm:^8.0.0, acorn@npm:^8.11.3, acorn@npm:^8.5.0, acorn@npm:^8.9.0":
version: 8.12.0
resolution: "acorn@npm:8.12.0"
bin:
Expand Down Expand Up @@ -3401,6 +3402,17 @@ __metadata:
languageName: node
linkType: hard

"eslint-compat-utils@npm:^0.5.0":
version: 0.5.1
resolution: "eslint-compat-utils@npm:0.5.1"
dependencies:
semver: "npm:^7.5.4"
peerDependencies:
eslint: ">=6.0.0"
checksum: 10/ac65ac1c6107cf19f63f5fc17cea361c9cb1336be7356f23dbb0fac10979974b4622e13e950be43cbf431801f2c07f7dab448573181ccf6edc0b86d5b5304511
languageName: node
linkType: hard

"eslint-config-prettier@npm:^9.1.0":
version: 9.1.0
resolution: "eslint-config-prettier@npm:9.1.0"
Expand Down Expand Up @@ -3443,6 +3455,23 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-jsonc@npm:^2.16.0":
version: 2.16.0
resolution: "eslint-plugin-jsonc@npm:2.16.0"
dependencies:
"@eslint-community/eslint-utils": "npm:^4.2.0"
eslint-compat-utils: "npm:^0.5.0"
espree: "npm:^9.6.1"
graphemer: "npm:^1.4.0"
jsonc-eslint-parser: "npm:^2.0.4"
natural-compare: "npm:^1.4.0"
synckit: "npm:^0.6.0"
peerDependencies:
eslint: ">=6.0.0"
checksum: 10/bec880a4d6f0cd8ba37ae3a6528477d3161b41ca7b885ed43c34bed95d09b30fd1d277bfa9e487164f5a8aad265f3b075a4b479c20811fe0dd18c25b6835cf56
languageName: node
linkType: hard

"eslint-plugin-markdown@npm:^3.0.1":
version: 3.0.1
resolution: "eslint-plugin-markdown@npm:3.0.1"
Expand Down Expand Up @@ -3603,7 +3632,7 @@ __metadata:
languageName: node
linkType: hard

"eslint-visitor-keys@npm:^3.3.0, eslint-visitor-keys@npm:^3.4.1, eslint-visitor-keys@npm:^3.4.3":
"eslint-visitor-keys@npm:^3.0.0, eslint-visitor-keys@npm:^3.3.0, eslint-visitor-keys@npm:^3.4.1, eslint-visitor-keys@npm:^3.4.3":
version: 3.4.3
resolution: "eslint-visitor-keys@npm:3.4.3"
checksum: 10/3f357c554a9ea794b094a09bd4187e5eacd1bc0d0653c3adeb87962c548e6a1ab8f982b86963ae1337f5d976004146536dcee5d0e2806665b193fbfbf1a9231b
Expand Down Expand Up @@ -3672,7 +3701,7 @@ __metadata:
languageName: node
linkType: hard

"espree@npm:^9.6.1":
"espree@npm:^9.0.0, espree@npm:^9.6.1":
version: 9.6.1
resolution: "espree@npm:9.6.1"
dependencies:
Expand Down Expand Up @@ -5238,6 +5267,18 @@ __metadata:
languageName: node
linkType: hard

"jsonc-eslint-parser@npm:^2.0.4":
version: 2.4.0
resolution: "jsonc-eslint-parser@npm:2.4.0"
dependencies:
acorn: "npm:^8.5.0"
eslint-visitor-keys: "npm:^3.0.0"
espree: "npm:^9.0.0"
semver: "npm:^7.3.5"
checksum: 10/bd1d41c852c3488414605a1754617aa7c240ed6730a25a7fd7fb76473e92efdc5ba1728ad3f08f8069de3a19abf1fd275c2b145eb51e2f7f6ca293c8105e1ffe
languageName: node
linkType: hard

"jsonfile@npm:^4.0.0":
version: 4.0.0
resolution: "jsonfile@npm:4.0.0"
Expand Down Expand Up @@ -7671,7 +7712,7 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^7.3.5, semver@npm:^7.5.3, semver@npm:^7.6.0":
"semver@npm:^7.3.5, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0":
version: 7.6.2
resolution: "semver@npm:7.6.2"
bin:
Expand Down Expand Up @@ -8200,6 +8241,15 @@ __metadata:
languageName: node
linkType: hard

"synckit@npm:^0.6.0":
version: 0.6.2
resolution: "synckit@npm:0.6.2"
dependencies:
tslib: "npm:^2.3.1"
checksum: 10/9641f4a4f113b7d6a810c34870947c1f19b7a736b510211c0ea69b05aed530d9aa52cb4942f0988a72514ce9fda61011e913c52fa86c58ebf56901d54c2fe241
languageName: node
linkType: hard

"synckit@npm:^0.8.6":
version: 0.8.8
resolution: "synckit@npm:0.8.8"
Expand Down Expand Up @@ -8414,7 +8464,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^2.1.0, tslib@npm:^2.6.2":
"tslib@npm:^2.1.0, tslib@npm:^2.3.1, tslib@npm:^2.6.2":
version: 2.6.3
resolution: "tslib@npm:2.6.3"
checksum: 10/52109bb681f8133a2e58142f11a50e05476de4f075ca906d13b596ae5f7f12d30c482feb0bff167ae01cfc84c5803e575a307d47938999246f5a49d174fc558c
Expand Down

0 comments on commit edb6b81

Please sign in to comment.