-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.js
98 lines (91 loc) · 2.31 KB
/
json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import jsoncPlugin from "eslint-plugin-jsonc";
import jsoncParser from "jsonc-eslint-parser";
import tseslint from "typescript-eslint";
export function json(options = {}) {
const config = tseslint.config(
{
// JSON files
files: [`**/*.{json,jsonc}`],
ignores: [`package-lock.json`],
languageOptions: {
parser: jsoncParser,
},
plugins: { jsonc: jsoncPlugin },
rules: {
...jsoncPlugin.configs[`recommended-with-json`].rules,
...jsoncPlugin.configs.prettier.rules,
"jsonc/sort-keys": `error`, // Specify per-file orders as needed (below)
},
},
{
// These allow comments (a.k.a. JSONC files)
files: [
`**/global.json`,
`**/tsconfig*.json`,
`**/turbo.json`,
`**/*.jsonc`,
],
rules: { "jsonc/no-comments": `off` },
},
);
if (options.packageJson) {
config.push({
// Special rules for package.json
files: [`**/package.json`],
rules: {
"jsonc/sort-keys": [
`warn`, // warn because nothing is “wrong” and this config may change often
{
// Defines order of root properties
order: [
`name`,
`version`,
`description`,
`private`,
// Additional publish info
`keywords`,
`homepage`,
`bugs`,
`license`,
`author`,
`repository`,
`publishConfig`,
// End publish info
`type`,
`engines`, // Often used for ESM, so relates to `type`
`engineStrict`,
// Export fields
`bin`,
`directories`,
`files`,
`main`,
`types`,
`exports`,
// End export fields
`scripts`,
// Tool-specific directly after scripts, alphabetical
`browserslist`,
`eslint`,
`lint-staged`,
// End tool-specific
// Dependency related, specific order
`overrides`, // Overrides before dependencies to emphasize their existence
`optionalDependencies`,
`peerDependencies`,
`peerDependenciesMeta`,
`dependencies`,
`devDependencies`,
// End dependency related
`workspaces`,
{ order: { type: `desc` } }, // Force other properties to go last
],
pathPattern: `^$`,
},
// Reinstate normal order for non-root properties
{ order: { type: `asc` }, pathPattern: `.*` },
],
},
});
}
return config;
}