Skip to content

Commit

Permalink
feat: add eslint-plugin-jsonc (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien <julien@ripouteau.com>
  • Loading branch information
Shinigami92 and Julien-R44 committed Jan 2, 2023
1 parent d2bf20f commit 423dbb7
Show file tree
Hide file tree
Showing 52 changed files with 1,621 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -67,6 +67,7 @@
"eslint-plugin-import": "~2.26.0",
"eslint-plugin-inclusive-language": "~2.2.0",
"eslint-plugin-jsdoc": "~39.6.4",
"eslint-plugin-jsonc": "~2.5.0",
"eslint-plugin-mdx": "~2.0.5",
"eslint-plugin-n": "~15.6.0",
"eslint-plugin-node": "~11.1.0",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions scripts/generate-rule-files/src/plugins-map.ts
Expand Up @@ -4,6 +4,7 @@ import * as eslintPluginDeprecation from 'eslint-plugin-deprecation';
import * as eslintPluginImport from 'eslint-plugin-import';
// @ts-expect-error
import eslintPluginJSDoc from 'eslint-plugin-jsdoc';
import eslintPluginJsonc from 'eslint-plugin-jsonc';
import * as eslintPluginMdx from 'eslint-plugin-mdx';
// @ts-expect-error
import eslintPluginNode from 'eslint-plugin-node';
Expand Down Expand Up @@ -51,6 +52,13 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
prefix: 'jsdoc',
rules: (eslintPluginJSDoc as Plugin).rules,
},
jsonc: {
name: 'Jsonc',
prefix: 'jsonc',
rules:
// @ts-expect-error: throw error when plugin successfully updated their type defs
eslintPluginJsonc.rules as Plugin['rules'],
},
mdx: {
name: 'Mdx',
rules: eslintPluginMdx.rules,
Expand Down
13 changes: 13 additions & 0 deletions src/config/extends/eslint-plugin-jsonc.d.ts
@@ -0,0 +1,13 @@
/**
* Eslint Jsonc extensions.
*
* @see [Eslint Jsonc extensions](https://github.com/ota-meshi/eslint-plugin-jsonc#configuration)
*/
export type JsoncExtensions =
| 'plugin:jsdoc/base'
| 'plugin:jsdoc/recommended'
| 'plugin:jsonc/recommended-with-json'
| 'plugin:jsonc/recommended-with-jsonc'
| 'plugin:jsonc/recommended-with-json5'
| 'plugin:jsonc/prettier'
| 'plugin:jsonc/all';
2 changes: 2 additions & 0 deletions src/config/extends/index.d.ts
Expand Up @@ -2,6 +2,7 @@ import type { LiteralUnion } from '../../utility-types';
import type { EslintExtensions } from './eslint';
import type { ImportExtensions } from './eslint-plugin-import';
import type { JsdocExtensions } from './eslint-plugin-jsdoc';
import type { JsoncExtensions } from './eslint-plugin-jsonc';
import type { MdxExtensions } from './eslint-plugin-mdx';
import type { NExtensions } from './eslint-plugin-n';
import type { NodeExtensions } from './eslint-plugin-node';
Expand All @@ -20,6 +21,7 @@ export type KnownExtensions = LiteralUnion<
| ImportExtensions
| IntlifyVueI18nExtensions
| JsdocExtensions
| JsoncExtensions
| MdxExtensions
| NExtensions
| NodeExtensions
Expand Down
5 changes: 4 additions & 1 deletion src/parser-options.d.ts
Expand Up @@ -134,7 +134,10 @@ export type DebugLevel =

/** Parser. */
export type Parser = LiteralUnion<
'babel-eslint' | '@typescript-eslint/parser' | 'vue-eslint-parser'
| 'babel-eslint'
| '@typescript-eslint/parser'
| 'jsonc-eslint-parser'
| 'vue-eslint-parser'
>;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/rules/index.d.ts
Expand Up @@ -2,6 +2,7 @@ import type { DeprecationRules } from './deprecation';
import type { EslintRules } from './eslint';
import type { ImportRules } from './import';
import type { JSDocRules } from './jsdoc';
import type { JsoncRules } from './jsonc';
import type { NRules } from './n';
import type { NodeRules } from './node';
import type { RuleConfig } from './rule-config';
Expand All @@ -22,6 +23,7 @@ export type Rules = Partial<
EslintRules &
ImportRules &
JSDocRules &
JsoncRules &
NodeRules &
NRules &
SpellcheckRules &
Expand Down
38 changes: 38 additions & 0 deletions src/rules/jsonc/array-bracket-newline.d.ts
@@ -0,0 +1,38 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export type ArrayBracketNewlineOption =
| ('always' | 'never' | 'consistent')
| {
multiline?: boolean;
minItems?: number | null;
};

/**
* Options.
*/
export type ArrayBracketNewlineOptions = [ArrayBracketNewlineOption?];

/**
* Enforce line breaks after opening and before closing array brackets.
*
* @see [array-bracket-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-newline.html)
*/
export type ArrayBracketNewlineRuleConfig =
RuleConfig<ArrayBracketNewlineOptions>;

/**
* Enforce line breaks after opening and before closing array brackets.
*
* @see [array-bracket-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-newline.html)
*/
export interface ArrayBracketNewlineRule {
/**
* Enforce line breaks after opening and before closing array brackets.
*
* @see [array-bracket-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-newline.html)
*/
'jsonc/array-bracket-newline': ArrayBracketNewlineRuleConfig;
}
45 changes: 45 additions & 0 deletions src/rules/jsonc/array-bracket-spacing.d.ts
@@ -0,0 +1,45 @@
import type { RuleConfig } from '../rule-config';

/**
* Config.
*/
export interface ArrayBracketSpacingConfig {
singleValue?: boolean;
objectsInArrays?: boolean;
arraysInArrays?: boolean;
}

/**
* Option.
*/
export type ArrayBracketSpacingOption = 'always' | 'never';

/**
* Options.
*/
export type ArrayBracketSpacingOptions = [
ArrayBracketSpacingOption?,
ArrayBracketSpacingConfig?,
];

/**
* Disallow or enforce spaces inside of brackets.
*
* @see [array-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-spacing.html)
*/
export type ArrayBracketSpacingRuleConfig =
RuleConfig<ArrayBracketSpacingOptions>;

/**
* Disallow or enforce spaces inside of brackets.
*
* @see [array-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-spacing.html)
*/
export interface ArrayBracketSpacingRule {
/**
* Disallow or enforce spaces inside of brackets.
*
* @see [array-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-bracket-spacing.html)
*/
'jsonc/array-bracket-spacing': ArrayBracketSpacingRuleConfig;
}
47 changes: 47 additions & 0 deletions src/rules/jsonc/array-element-newline.d.ts
@@ -0,0 +1,47 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export type ArrayElementNewlineOption =
| []
| [
| BasicConfig
| {
ArrayExpression?: BasicConfig;
ArrayPattern?: BasicConfig;
},
];
export type BasicConfig =
| ('always' | 'never' | 'consistent')
| {
multiline?: boolean;
minItems?: number | null;
};

/**
* Options.
*/
export type ArrayElementNewlineOptions = ArrayElementNewlineOption;

/**
* Enforce line breaks between array elements.
*
* @see [array-element-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-element-newline.html)
*/
export type ArrayElementNewlineRuleConfig =
RuleConfig<ArrayElementNewlineOptions>;

/**
* Enforce line breaks between array elements.
*
* @see [array-element-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-element-newline.html)
*/
export interface ArrayElementNewlineRule {
/**
* Enforce line breaks between array elements.
*
* @see [array-element-newline](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/array-element-newline.html)
*/
'jsonc/array-element-newline': ArrayElementNewlineRuleConfig;
}
22 changes: 22 additions & 0 deletions src/rules/jsonc/auto.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Apply jsonc rules similar to your configured ESLint core rules.
*
* @see [auto](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/auto.html)
*/
export type AutoRuleConfig = RuleConfig<[]>;

/**
* Apply jsonc rules similar to your configured ESLint core rules.
*
* @see [auto](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/auto.html)
*/
export interface AutoRule {
/**
* Apply jsonc rules similar to your configured ESLint core rules.
*
* @see [auto](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/auto.html)
*/
'jsonc/auto': AutoRuleConfig;
}
50 changes: 50 additions & 0 deletions src/rules/jsonc/comma-dangle.d.ts
@@ -0,0 +1,50 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export type CommaDangleOption =
| []
| [
| Value
| {
arrays?: ValueWithIgnore;
objects?: ValueWithIgnore;
imports?: ValueWithIgnore;
exports?: ValueWithIgnore;
functions?: ValueWithIgnore;
},
];
export type Value = 'always-multiline' | 'always' | 'never' | 'only-multiline';
export type ValueWithIgnore =
| 'always-multiline'
| 'always'
| 'ignore'
| 'never'
| 'only-multiline';

/**
* Options.
*/
export type CommaDangleOptions = CommaDangleOption;

/**
* Require or disallow trailing commas.
*
* @see [comma-dangle](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/comma-dangle.html)
*/
export type CommaDangleRuleConfig = RuleConfig<CommaDangleOptions>;

/**
* Require or disallow trailing commas.
*
* @see [comma-dangle](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/comma-dangle.html)
*/
export interface CommaDangleRule {
/**
* Require or disallow trailing commas.
*
* @see [comma-dangle](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/comma-dangle.html)
*/
'jsonc/comma-dangle': CommaDangleRuleConfig;
}
41 changes: 41 additions & 0 deletions src/rules/jsonc/comma-style.d.ts
@@ -0,0 +1,41 @@
import type { RuleConfig } from '../rule-config';

/**
* Config.
*/
export interface CommaStyleConfig {
exceptions?: {
[k: string]: boolean;
};
}

/**
* Option.
*/
export type CommaStyleOption = 'first' | 'last';

/**
* Options.
*/
export type CommaStyleOptions = [CommaStyleOption?, CommaStyleConfig?];

/**
* Enforce consistent comma style.
*
* @see [comma-style](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/comma-style.html)
*/
export type CommaStyleRuleConfig = RuleConfig<CommaStyleOptions>;

/**
* Enforce consistent comma style.
*
* @see [comma-style](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/comma-style.html)
*/
export interface CommaStyleRule {
/**
* Enforce consistent comma style.
*
* @see [comma-style](https://ota-meshi.github.io/eslint-plugin-jsonc/rules/comma-style.html)
*/
'jsonc/comma-style': CommaStyleRuleConfig;
}

0 comments on commit 423dbb7

Please sign in to comment.