Skip to content

Commit

Permalink
Add JSON plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 14, 2024
1 parent dce8db9 commit 6a547b5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
65 changes: 64 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import globals from 'globals';
import stylistic from '@stylistic/eslint-plugin';
import json from '@eslint/json';

const rules = {
'@stylistic/comma-dangle': [
Expand Down Expand Up @@ -697,6 +698,21 @@ const rules = {
],
};

const TYPESCRIPT_EXTENSION = [
'ts',
'tsx',
'mts',
'cts',
];

const DEFAULT_EXTENSION = [
'js',
'jsx',
'mjs',
'cjs',
...TYPESCRIPT_EXTENSION,
];

const config = {
languageOptions: {
globals: {
Expand All @@ -717,7 +733,54 @@ const config = {
plugins: {
'@stylistic': stylistic,
},
files: [
`**/*.{${DEFAULT_EXTENSION.join(',')}}`,
],
rules,
};

export default [config];
const jsonRules = {
'json/no-duplicate-keys': 'error',
'json/no-empty-keys': 'error',
};

const jsonConfig = {
plugins: {
json,
},
files: [
'**/*.json',
],
language: 'json/json',
rules: jsonRules,
};

const jsoncConfig = {
plugins: {
json,
},
files: [
'**/*.jsonc',
'.vscode/*.json',
],
language: 'json/jsonc',
rules: jsonRules,
};

const json5Config = {
plugins: {
json,
},
files: [
'**/*.json5',
],
language: 'json/json5',
rules: jsonRules,
};

export default [
config,
jsonConfig,
jsoncConfig,
json5Config,
];
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@
"simple"
],
"dependencies": {
"@eslint/json": "^0.5.0",
"@stylistic/eslint-plugin": "^2.6.1",
"confusing-browser-globals": "1.0.11",
"globals": "^15.3.0"
},
"devDependencies": {
"ava": "^6.1.3",
"eslint": "^9.8.0"
"eslint": "^9.12.0"
},
"peerDependencies": {
"eslint": ">=9.8.0"
Expand Down

0 comments on commit 6a547b5

Please sign in to comment.