Skip to content

Commit b57bafd

Browse files
authored
Fixed the parser and the config to accept the extension .json5. (#5)
1 parent 2a44c39 commit b57bafd

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

lib/configs/auto-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export = {
66
extends: [baseExtend],
77
overrides: [
88
{
9-
files: ["*.json"],
9+
files: ["*.json", "*.json5"],
1010
processor: "jsonc/auto-config",
1111
},
1212
],

lib/configs/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export = {
22
plugins: ["jsonc"],
33
overrides: [
44
{
5-
files: ["*.json"],
5+
files: ["*.json", "*.json5"],
66
parser: require.resolve("../parser/json-eslint-parser"),
77
},
88
],

lib/parser/json-eslint-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "./convert"
2020
import { JSONProgram } from "./ast"
2121

22+
const KNOWN_JSON_EXT = new Set<string>([".json", ".json5"])
2223
const KNOWN_NON_JSON_EXT = new Set<string>([
2324
".js",
2425
".jsx",
@@ -98,7 +99,7 @@ function isJSONFile(code: string, options: any): boolean {
9899
const filePath = options.filePath as string | undefined
99100
if (filePath) {
100101
const ext = path.extname(filePath.toLowerCase())
101-
if (ext === ".json") {
102+
if (KNOWN_JSON_EXT.has(ext)) {
102103
return true
103104
}
104105
if (KNOWN_NON_JSON_EXT.has(ext)) {

0 commit comments

Comments
 (0)