Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 423dbb7

Browse files
feat: add eslint-plugin-jsonc (#160)
Co-authored-by: Julien <[email protected]>
1 parent d2bf20f commit 423dbb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1621
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"eslint-plugin-import": "~2.26.0",
6868
"eslint-plugin-inclusive-language": "~2.2.0",
6969
"eslint-plugin-jsdoc": "~39.6.4",
70+
"eslint-plugin-jsonc": "~2.5.0",
7071
"eslint-plugin-mdx": "~2.0.5",
7172
"eslint-plugin-n": "~15.6.0",
7273
"eslint-plugin-node": "~11.1.0",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-rule-files/src/plugins-map.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as eslintPluginDeprecation from 'eslint-plugin-deprecation';
44
import * as eslintPluginImport from 'eslint-plugin-import';
55
// @ts-expect-error
66
import eslintPluginJSDoc from 'eslint-plugin-jsdoc';
7+
import eslintPluginJsonc from 'eslint-plugin-jsonc';
78
import * as eslintPluginMdx from 'eslint-plugin-mdx';
89
// @ts-expect-error
910
import eslintPluginNode from 'eslint-plugin-node';
@@ -51,6 +52,13 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
5152
prefix: 'jsdoc',
5253
rules: (eslintPluginJSDoc as Plugin).rules,
5354
},
55+
jsonc: {
56+
name: 'Jsonc',
57+
prefix: 'jsonc',
58+
rules:
59+
// @ts-expect-error: throw error when plugin successfully updated their type defs
60+
eslintPluginJsonc.rules as Plugin['rules'],
61+
},
5462
mdx: {
5563
name: 'Mdx',
5664
rules: eslintPluginMdx.rules,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Eslint Jsonc extensions.
3+
*
4+
* @see [Eslint Jsonc extensions](https://github.com/ota-meshi/eslint-plugin-jsonc#configuration)
5+
*/
6+
export type JsoncExtensions =
7+
| 'plugin:jsdoc/base'
8+
| 'plugin:jsdoc/recommended'
9+
| 'plugin:jsonc/recommended-with-json'
10+
| 'plugin:jsonc/recommended-with-jsonc'
11+
| 'plugin:jsonc/recommended-with-json5'
12+
| 'plugin:jsonc/prettier'
13+
| 'plugin:jsonc/all';

src/config/extends/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { LiteralUnion } from '../../utility-types';
22
import type { EslintExtensions } from './eslint';
33
import type { ImportExtensions } from './eslint-plugin-import';
44
import type { JsdocExtensions } from './eslint-plugin-jsdoc';
5+
import type { JsoncExtensions } from './eslint-plugin-jsonc';
56
import type { MdxExtensions } from './eslint-plugin-mdx';
67
import type { NExtensions } from './eslint-plugin-n';
78
import type { NodeExtensions } from './eslint-plugin-node';
@@ -20,6 +21,7 @@ export type KnownExtensions = LiteralUnion<
2021
| ImportExtensions
2122
| IntlifyVueI18nExtensions
2223
| JsdocExtensions
24+
| JsoncExtensions
2325
| MdxExtensions
2426
| NExtensions
2527
| NodeExtensions

src/parser-options.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ export type DebugLevel =
134134

135135
/** Parser. */
136136
export type Parser = LiteralUnion<
137-
'babel-eslint' | '@typescript-eslint/parser' | 'vue-eslint-parser'
137+
| 'babel-eslint'
138+
| '@typescript-eslint/parser'
139+
| 'jsonc-eslint-parser'
140+
| 'vue-eslint-parser'
138141
>;
139142

140143
/**

src/rules/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { DeprecationRules } from './deprecation';
22
import type { EslintRules } from './eslint';
33
import type { ImportRules } from './import';
44
import type { JSDocRules } from './jsdoc';
5+
import type { JsoncRules } from './jsonc';
56
import type { NRules } from './n';
67
import type { NodeRules } from './node';
78
import type { RuleConfig } from './rule-config';
@@ -22,6 +23,7 @@ export type Rules = Partial<
2223
EslintRules &
2324
ImportRules &
2425
JSDocRules &
26+
JsoncRules &
2527
NodeRules &
2628
NRules &
2729
SpellcheckRules &
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type ArrayBracketNewlineOption =
7+
| ('always' | 'never' | 'consistent')
8+
| {
9+
multiline?: boolean;
10+
minItems?: number | null;
11+
};
12+
13+
/**
14+
* Options.
15+
*/
16+
export type ArrayBracketNewlineOptions = [ArrayBracketNewlineOption?];
17+
18+
/**
19+
* Enforce line breaks after opening and before closing array brackets.
20+
*
21+
* @see [array-bracket-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-newline.html)
22+
*/
23+
export type ArrayBracketNewlineRuleConfig =
24+
RuleConfig<ArrayBracketNewlineOptions>;
25+
26+
/**
27+
* Enforce line breaks after opening and before closing array brackets.
28+
*
29+
* @see [array-bracket-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-newline.html)
30+
*/
31+
export interface ArrayBracketNewlineRule {
32+
/**
33+
* Enforce line breaks after opening and before closing array brackets.
34+
*
35+
* @see [array-bracket-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-newline.html)
36+
*/
37+
'jsonc/array-bracket-newline': ArrayBracketNewlineRuleConfig;
38+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Config.
5+
*/
6+
export interface ArrayBracketSpacingConfig {
7+
singleValue?: boolean;
8+
objectsInArrays?: boolean;
9+
arraysInArrays?: boolean;
10+
}
11+
12+
/**
13+
* Option.
14+
*/
15+
export type ArrayBracketSpacingOption = 'always' | 'never';
16+
17+
/**
18+
* Options.
19+
*/
20+
export type ArrayBracketSpacingOptions = [
21+
ArrayBracketSpacingOption?,
22+
ArrayBracketSpacingConfig?,
23+
];
24+
25+
/**
26+
* Disallow or enforce spaces inside of brackets.
27+
*
28+
* @see [array-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-spacing.html)
29+
*/
30+
export type ArrayBracketSpacingRuleConfig =
31+
RuleConfig<ArrayBracketSpacingOptions>;
32+
33+
/**
34+
* Disallow or enforce spaces inside of brackets.
35+
*
36+
* @see [array-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-spacing.html)
37+
*/
38+
export interface ArrayBracketSpacingRule {
39+
/**
40+
* Disallow or enforce spaces inside of brackets.
41+
*
42+
* @see [array-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-spacing.html)
43+
*/
44+
'jsonc/array-bracket-spacing': ArrayBracketSpacingRuleConfig;
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type ArrayElementNewlineOption =
7+
| []
8+
| [
9+
| BasicConfig
10+
| {
11+
ArrayExpression?: BasicConfig;
12+
ArrayPattern?: BasicConfig;
13+
},
14+
];
15+
export type BasicConfig =
16+
| ('always' | 'never' | 'consistent')
17+
| {
18+
multiline?: boolean;
19+
minItems?: number | null;
20+
};
21+
22+
/**
23+
* Options.
24+
*/
25+
export type ArrayElementNewlineOptions = ArrayElementNewlineOption;
26+
27+
/**
28+
* Enforce line breaks between array elements.
29+
*
30+
* @see [array-element-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-element-newline.html)
31+
*/
32+
export type ArrayElementNewlineRuleConfig =
33+
RuleConfig<ArrayElementNewlineOptions>;
34+
35+
/**
36+
* Enforce line breaks between array elements.
37+
*
38+
* @see [array-element-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-element-newline.html)
39+
*/
40+
export interface ArrayElementNewlineRule {
41+
/**
42+
* Enforce line breaks between array elements.
43+
*
44+
* @see [array-element-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-element-newline.html)
45+
*/
46+
'jsonc/array-element-newline': ArrayElementNewlineRuleConfig;
47+
}

0 commit comments

Comments
 (0)