Skip to content

Commit 60cfab9

Browse files
authored
Add config for prettier (#53)
* Add config for prettier * update * fix
1 parent c3a5b7d commit 60cfab9

38 files changed

+121
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ e.g. [eslint-plugin-json-files](https://www.npmjs.com/package/eslint-plugin-json
5959

6060
These plugins use the same AST as JavaScript for linting.
6161

62-
Since the plugin uses the same AST as JavaScript, it may not report syntax that is not available in JSON (e.g. `1 + 1`). Also, ESLint core rules and other plug-in rules can false positives (e.g. [quote-props](https://eslint.org/docs/rules/quote-props) rule reports quote on keys), which can complicate the configuration.
62+
Since the plugin uses the same AST as JavaScript, it may not report syntax that is not available in JSON (e.g. `1 + 1`). Also, ESLint core rules and other plugin rules can false positives (e.g. [quote-props](https://eslint.org/docs/rules/quote-props) rule reports quote on keys), which can complicate the configuration.
6363

6464
The AST used by **eslint-plugin-jsonc** is similar to JavaScript AST, but with a different node name. This will prevent false positives. This means that it can be easily used in combination with other plugins.
6565

@@ -113,6 +113,7 @@ This plugin provides configs:
113113
- `plugin:jsonc/recommended-with-json` ... Recommended configuration for JSON.
114114
- `plugin:jsonc/recommended-with-jsonc` ... Recommended configuration for JSONC.
115115
- `plugin:jsonc/recommended-with-json5` ... Recommended configuration for JSON5.
116+
- `plugin:jsonc/prettier` ... Turn off rules that may conflict with [Prettier](https://prettier.io/).
116117

117118
See [the rule list](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/) to get the `rules` that this plugin provides.
118119

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ e.g. [eslint-plugin-json-files](https://www.npmjs.com/package/eslint-plugin-json
5959

6060
These plugins use the same AST as JavaScript for linting.
6161

62-
Since the plugin uses the same AST as JavaScript, it may not report syntax that is not available in JSON (e.g. `1 + 1`). Also, ESLint core rules and other plug-in rules can false positives (e.g. [quote-props](https://eslint.org/docs/rules/quote-props) rule reports quote on keys), which can complicate the configuration.
62+
Since the plugin uses the same AST as JavaScript, it may not report syntax that is not available in JSON (e.g. `1 + 1`). Also, ESLint core rules and other plugin rules can false positives (e.g. [quote-props](https://eslint.org/docs/rules/quote-props) rule reports quote on keys), which can complicate the configuration.
6363

6464
The AST used by **eslint-plugin-jsonc** is similar to JavaScript AST, but with a different node name. This will prevent false positives. This means that it can be easily used in combination with other plugins.
6565

docs/user-guide/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ This plugin provides configs:
4242
- `plugin:jsonc/recommended-with-json` ... Recommended configuration for JSON.
4343
- `plugin:jsonc/recommended-with-jsonc` ... Recommended configuration for JSONC.
4444
- `plugin:jsonc/recommended-with-json5` ... Recommended configuration for JSON5.
45+
- `plugin:jsonc/prettier` ... Turn off rules that may conflict with [Prettier](https://prettier.io/).
4546

4647
See [the rule list](../rules/README.md) to get the `rules` that this plugin provides.
4748

lib/configs/prettier.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from "path"
2+
const base = require.resolve("./base")
3+
const baseExtend =
4+
path.extname(`${base}`) === ".ts" ? "plugin:jsonc/base" : base
5+
export = {
6+
extends: [baseExtend],
7+
rules: {
8+
// eslint-plugin-jsonc rules
9+
"jsonc/array-bracket-newline": "off",
10+
"jsonc/array-bracket-spacing": "off",
11+
"jsonc/array-element-newline": "off",
12+
"jsonc/comma-dangle": "off",
13+
"jsonc/comma-style": "off",
14+
"jsonc/indent": "off",
15+
"jsonc/key-spacing": "off",
16+
"jsonc/object-curly-newline": "off",
17+
"jsonc/object-curly-spacing": "off",
18+
"jsonc/object-property-newline": "off",
19+
"jsonc/quote-props": "off",
20+
"jsonc/quotes": "off",
21+
"jsonc/space-unary-ops": "off",
22+
},
23+
}

lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import autoConfig from "./configs/auto-config"
55
import recommendedWithJson from "./configs/recommended-with-json"
66
import recommendedWithJsonc from "./configs/recommended-with-jsonc"
77
import recommendedWithJson5 from "./configs/recommended-with-json5"
8+
import prettier from "./configs/prettier"
89
// backward compatibility
910
import {
1011
parseForESLint,
@@ -19,6 +20,7 @@ const configs = {
1920
"recommended-with-json": recommendedWithJson,
2021
"recommended-with-jsonc": recommendedWithJsonc,
2122
"recommended-with-json5": recommendedWithJson5,
23+
prettier,
2224
}
2325

2426
const rules = ruleList.reduce((obj, r) => {

lib/rules/array-bracket-newline.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default createRule("array-bracket-newline", {
88
"enforce line breaks after opening and before closing array brackets",
99
recommended: null,
1010
extensionRule: true,
11+
layout: true,
1112
},
1213
fixable: coreRule.meta?.fixable,
1314
schema: coreRule.meta!.schema!,

lib/rules/array-bracket-spacing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default createRule("array-bracket-spacing", {
77
description: "disallow or enforce spaces inside of brackets",
88
recommended: null,
99
extensionRule: true,
10+
layout: true,
1011
},
1112
fixable: coreRule.meta?.fixable,
1213
schema: coreRule.meta!.schema!,

lib/rules/array-element-newline.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default createRule("array-element-newline", {
77
description: "enforce line breaks between array elements",
88
recommended: null,
99
extensionRule: true,
10+
layout: true,
1011
},
1112
fixable: coreRule.meta?.fixable,
1213
schema: coreRule.meta!.schema!,

lib/rules/auto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default createRule("auto", {
99
"apply jsonc rules similar to your configured ESLint core rules",
1010
recommended: null,
1111
extensionRule: false,
12+
layout: false,
1213
},
1314
fixable: "code",
1415
schema: [],

lib/rules/comma-dangle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default createRule("comma-dangle", {
77
description: "require or disallow trailing commas",
88
recommended: ["json"],
99
extensionRule: true,
10+
layout: true,
1011
},
1112
fixable: coreRule.meta?.fixable,
1213
schema: coreRule.meta!.schema!,

0 commit comments

Comments
 (0)