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

Add config for prettier #53

Merged
merged 3 commits into from
Feb 25, 2021
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ e.g. [eslint-plugin-json-files](https://www.npmjs.com/package/eslint-plugin-json

These plugins use the same AST as JavaScript for linting.

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.
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.

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.

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ e.g. [eslint-plugin-json-files](https://www.npmjs.com/package/eslint-plugin-json

These plugins use the same AST as JavaScript for linting.

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.
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.

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.

Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ This plugin provides configs:
- `plugin:jsonc/recommended-with-json` ... Recommended configuration for JSON.
- `plugin:jsonc/recommended-with-jsonc` ... Recommended configuration for JSONC.
- `plugin:jsonc/recommended-with-json5` ... Recommended configuration for JSON5.
- `plugin:jsonc/prettier` ... Turn off rules that may conflict with [Prettier](https://prettier.io/).

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

Expand Down
23 changes: 23 additions & 0 deletions lib/configs/prettier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from "path"
const base = require.resolve("./base")
const baseExtend =
path.extname(`${base}`) === ".ts" ? "plugin:jsonc/base" : base
export = {
extends: [baseExtend],
rules: {
// eslint-plugin-jsonc rules
"jsonc/array-bracket-newline": "off",
"jsonc/array-bracket-spacing": "off",
"jsonc/array-element-newline": "off",
"jsonc/comma-dangle": "off",
"jsonc/comma-style": "off",
"jsonc/indent": "off",
"jsonc/key-spacing": "off",
"jsonc/object-curly-newline": "off",
"jsonc/object-curly-spacing": "off",
"jsonc/object-property-newline": "off",
"jsonc/quote-props": "off",
"jsonc/quotes": "off",
"jsonc/space-unary-ops": "off",
},
}
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import autoConfig from "./configs/auto-config"
import recommendedWithJson from "./configs/recommended-with-json"
import recommendedWithJsonc from "./configs/recommended-with-jsonc"
import recommendedWithJson5 from "./configs/recommended-with-json5"
import prettier from "./configs/prettier"
// backward compatibility
import {
parseForESLint,
Expand All @@ -19,6 +20,7 @@ const configs = {
"recommended-with-json": recommendedWithJson,
"recommended-with-jsonc": recommendedWithJsonc,
"recommended-with-json5": recommendedWithJson5,
prettier,
}

const rules = ruleList.reduce((obj, r) => {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/array-bracket-newline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default createRule("array-bracket-newline", {
"enforce line breaks after opening and before closing array brackets",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/array-bracket-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("array-bracket-spacing", {
description: "disallow or enforce spaces inside of brackets",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/array-element-newline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("array-element-newline", {
description: "enforce line breaks between array elements",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default createRule("auto", {
"apply jsonc rules similar to your configured ESLint core rules",
recommended: null,
extensionRule: false,
layout: false,
},
fixable: "code",
schema: [],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/comma-dangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("comma-dangle", {
description: "require or disallow trailing commas",
recommended: ["json"],
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/comma-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("comma-style", {
description: "enforce consistent comma style",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("indent", {
description: "enforce consistent indentation",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/key-name-casing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default createRule("key-name-casing", {
description: "enforce naming convention to property key names",
recommended: null,
extensionRule: false,
layout: false,
},
schema: [
{
Expand Down Expand Up @@ -60,7 +61,7 @@ export default createRule("key-name-casing", {
doesNotMatchFormat:
"Property name `{{name}}` must match one of the following formats: {{formats}}",
},
type: "layout",
type: "suggestion",
},
create(context) {
if (!context.parserServices.isJSON) {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/key-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default createRule("key-spacing", {
"enforce consistent spacing between keys and values in object literal properties",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-bigint-literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-bigint-literals", {
description: "disallow BigInt literals",
recommended: ["json", "jsonc", "json5"],
extensionRule: false,
layout: false,
},
schema: [],
messages: {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-comments", {
description: "disallow comments",
recommended: ["json"],
extensionRule: false,
layout: false,
},
schema: [],
messages: {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-dupe-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-dupe-keys", {
description: "disallow duplicate keys in object literals",
recommended: ["json", "jsonc", "json5"],
extensionRule: true,
layout: false,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-multi-str.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-multi-str", {
description: "disallow multiline strings",
recommended: ["json", "jsonc"],
extensionRule: true,
layout: false,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-number-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-number-props", {
description: "disallow number property keys",
recommended: ["json", "jsonc", "json5"],
extensionRule: false,
layout: false,
},
fixable: "code",
schema: [],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-numeric-separators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default createRule("no-numeric-separators", {
description: "disallow numeric separators",
recommended: ["json", "jsonc", "json5"],
extensionRule: false,
layout: false,
},
fixable: "code",
schema: [],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-octal-escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-octal-escape", {
description: "disallow octal escape sequences in string literals",
recommended: null,
extensionRule: true,
layout: false,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-regexp-literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-regexp-literals", {
description: "disallow RegExp literals",
recommended: ["json", "jsonc", "json5"],
extensionRule: false,
layout: false,
},
schema: [],
messages: {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-sparse-arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-sparse-arrays", {
description: "disallow sparse arrays",
recommended: ["json", "jsonc", "json5"],
extensionRule: true,
layout: false,
},
fixable: coreRule.meta!.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-template-literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-template-literals", {
description: "disallow template literals",
recommended: ["json", "jsonc", "json5"],
extensionRule: false,
layout: false,
},
fixable: "code",
schema: [],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-undefined-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default createRule("no-undefined-value", {
description: "disallow `undefined`",
recommended: ["json", "jsonc", "json5"],
extensionRule: false,
layout: false,
},
schema: [],
messages: {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-useless-escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("no-useless-escape", {
description: "disallow unnecessary escape usage",
recommended: ["json", "jsonc", "json5"],
extensionRule: true,
layout: false,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/object-curly-newline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("object-curly-newline", {
description: "enforce consistent line breaks inside braces",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/object-curly-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("object-curly-spacing", {
description: "enforce consistent spacing inside braces",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/object-property-newline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("object-property-newline", {
description: "enforce placing object properties on separate lines",
recommended: null,
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/quote-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("quote-props", {
description: "require quotes around object literal property names",
recommended: ["json", "jsonc"],
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("quotes", {
description: "enforce use of double or single quotes",
recommended: ["json", "jsonc"],
extensionRule: true,
layout: true,
},
fixable: coreRule.meta?.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/sort-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default createRule("sort-keys", {
description: "require object keys to be sorted",
recommended: null,
extensionRule: true,
layout: false,
},
fixable: "code",
schema: [
Expand Down
1 change: 1 addition & 0 deletions lib/rules/space-unary-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default createRule("space-unary-ops", {
description: "disallow spaces after unary operators",
recommended: ["json", "jsonc", "json5"],
extensionRule: true,
layout: true,
},
fixable: coreRule.meta!.fixable,
schema: coreRule.meta!.schema!,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/valid-json-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default createRule("valid-json-number", {
description: "disallow invalid number for JSON",
recommended: ["json", "jsonc"],
extensionRule: false,
layout: false,
},
fixable: "code",
schema: [],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/vue-custom-block/no-parsing-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default createRule("vue-custom-block/no-parsing-error", {
description: "disallow parsing errors in Vue custom blocks",
recommended: ["json", "json5", "jsonc"],
extensionRule: false,
layout: false,
},
schema: [],
messages: {},
Expand Down
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface RuleMetaData {
replacedBy?: []
default?: "error" | "warn"
extensionRule: boolean
layout: boolean
}
messages: { [messageId: string]: string }
fixable?: "code" | "whitespace"
Expand All @@ -43,6 +44,7 @@ export interface PartialRuleMetaData {
replacedBy?: []
default?: "error" | "warn"
extensionRule: boolean
layout: boolean
}
messages: { [messageId: string]: string }
fixable?: "code" | "whitespace"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"eslint": "^5.0.0 || >=6.0.0"
},
"devDependencies": {
"@ota-meshi/eslint-plugin": "^0.0.15",
"@ota-meshi/eslint-plugin": "^0.0.16",
"@types/eslint": "^7.2.0",
"@types/eslint-scope": "^3.7.0",
"@types/eslint-visitor-keys": "^1.0.0",
Expand Down
Loading