@eslint/json 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.js +1 -1
- package/dist/rules/no-unnormalized-keys.js +17 -4
- package/dist/rules/sort-keys.js +34 -0
- package/dist/types.d.ts +1 -1
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -294,9 +294,9 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
|
|
294
294
|
|
|
295
295
|
<h3>Platinum Sponsors</h3>
|
|
296
296
|
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a></p><h3>Gold Sponsors</h3>
|
|
297
|
-
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a
|
|
297
|
+
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a></p><h3>Silver Sponsors</h3>
|
|
298
298
|
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
|
299
|
-
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" height="32"></a> <a href="https://www.n-ix.com/"><img src="https://images.opencollective.com/n-ix-ltd/575a7a5/logo.png" alt="N-iX Ltd" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
|
299
|
+
<p><a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" height="32"></a> <a href="https://www.n-ix.com/"><img src="https://images.opencollective.com/n-ix-ltd/575a7a5/logo.png" alt="N-iX Ltd" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
|
300
300
|
<h3>Technology Sponsors</h3>
|
|
301
301
|
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
|
302
302
|
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
//-----------------------------------------------------------------------------
|
|
6
6
|
// Imports
|
|
7
7
|
//-----------------------------------------------------------------------------
|
|
8
|
-
import { getKey } from "../util.js";
|
|
8
|
+
import { getKey, getRawKey } from "../util.js";
|
|
9
9
|
//-----------------------------------------------------------------------------
|
|
10
10
|
// Type Definitions
|
|
11
11
|
//-----------------------------------------------------------------------------
|
|
@@ -22,6 +22,7 @@ import { getKey } from "../util.js";
|
|
|
22
22
|
const rule = {
|
|
23
23
|
meta: {
|
|
24
24
|
type: "problem",
|
|
25
|
+
fixable: "code",
|
|
25
26
|
docs: {
|
|
26
27
|
recommended: true,
|
|
27
28
|
description: "Disallow JSON keys that are not normalized",
|
|
@@ -52,12 +53,24 @@ const rule = {
|
|
|
52
53
|
return {
|
|
53
54
|
Member(node) {
|
|
54
55
|
const key = getKey(node);
|
|
55
|
-
|
|
56
|
+
const rawKey = getRawKey(node, context.sourceCode);
|
|
57
|
+
const normalizedKey = key.normalize(form);
|
|
58
|
+
if (normalizedKey !== key) {
|
|
59
|
+
const { name } = node;
|
|
56
60
|
context.report({
|
|
57
|
-
loc:
|
|
61
|
+
loc: name.loc,
|
|
58
62
|
messageId: "unnormalizedKey",
|
|
59
63
|
data: {
|
|
60
|
-
key,
|
|
64
|
+
key: rawKey,
|
|
65
|
+
},
|
|
66
|
+
fix(fixer) {
|
|
67
|
+
if (key !== rawKey) {
|
|
68
|
+
// Do not perform auto-fix when the raw key contains escape sequences.
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return fixer.replaceTextRange(name.type === "String"
|
|
72
|
+
? [name.range[0] + 1, name.range[1] - 1]
|
|
73
|
+
: name.range, normalizedKey);
|
|
61
74
|
},
|
|
62
75
|
});
|
|
63
76
|
}
|
package/dist/rules/sort-keys.js
CHANGED
|
@@ -33,6 +33,7 @@ import { getKey, getRawKey } from "../util.js";
|
|
|
33
33
|
// Helpers
|
|
34
34
|
//-----------------------------------------------------------------------------
|
|
35
35
|
const hasNonWhitespace = /\S/u;
|
|
36
|
+
const commentTypes = new Set(["LineComment", "BlockComment"]);
|
|
36
37
|
/** @type {ComparatorMap} */
|
|
37
38
|
const comparators = {
|
|
38
39
|
ascending: {
|
|
@@ -63,6 +64,7 @@ const comparators = {
|
|
|
63
64
|
const rule = {
|
|
64
65
|
meta: {
|
|
65
66
|
type: "suggestion",
|
|
67
|
+
fixable: "code",
|
|
66
68
|
defaultOptions: [
|
|
67
69
|
"asc",
|
|
68
70
|
{
|
|
@@ -144,6 +146,25 @@ const rule = {
|
|
|
144
146
|
}
|
|
145
147
|
return false;
|
|
146
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Checks if a member has a comment before or after it.
|
|
151
|
+
* @param {MemberNode} member The member to check.
|
|
152
|
+
* @returns {boolean} True if a comment is adjacent to the member.
|
|
153
|
+
*/
|
|
154
|
+
function hasAdjacentComment(member) {
|
|
155
|
+
const before = sourceCode.getTokenBefore(member, {
|
|
156
|
+
includeComments: true,
|
|
157
|
+
});
|
|
158
|
+
let after = sourceCode.getTokenAfter(member, {
|
|
159
|
+
includeComments: true,
|
|
160
|
+
});
|
|
161
|
+
if (after.type === "Comma") {
|
|
162
|
+
after = sourceCode.getTokenAfter(after, {
|
|
163
|
+
includeComments: true,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return (commentTypes.has(before.type) || commentTypes.has(after.type));
|
|
167
|
+
}
|
|
147
168
|
return {
|
|
148
169
|
Object(node) {
|
|
149
170
|
/** @type {MemberNode} */
|
|
@@ -158,6 +179,9 @@ const rule = {
|
|
|
158
179
|
for (const member of node.members) {
|
|
159
180
|
const thisName = getKey(member);
|
|
160
181
|
const thisRawName = getRawKey(member, sourceCode);
|
|
182
|
+
// Capture `prevMember` for this iteration so the fixer closure uses the
|
|
183
|
+
// intended node even though `prevMember` is reassigned in the loop.
|
|
184
|
+
const prevMemberNode = prevMember;
|
|
161
185
|
if (prevMember &&
|
|
162
186
|
!isValidOrder(prevName, thisName) &&
|
|
163
187
|
(!allowLineSeparatedGroups ||
|
|
@@ -172,6 +196,16 @@ const rule = {
|
|
|
172
196
|
sensitivity,
|
|
173
197
|
sortName,
|
|
174
198
|
},
|
|
199
|
+
fix(fixer) {
|
|
200
|
+
if (hasAdjacentComment(member) ||
|
|
201
|
+
hasAdjacentComment(prevMemberNode)) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
return [
|
|
205
|
+
fixer.replaceText(member, sourceCode.getText(prevMemberNode)),
|
|
206
|
+
fixer.replaceText(prevMemberNode, sourceCode.getText(member)),
|
|
207
|
+
];
|
|
208
|
+
},
|
|
175
209
|
});
|
|
176
210
|
}
|
|
177
211
|
prevMember = member;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint/json",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "JSON linting plugin for ESLint",
|
|
5
5
|
"author": "Nicholas C. Zakas",
|
|
6
6
|
"type": "module",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"lint": "eslint",
|
|
51
51
|
"lint:fix": "eslint --fix",
|
|
52
52
|
"lint:types": "attw --pack --profile esm-only",
|
|
53
|
+
"lint:unused": "knip",
|
|
53
54
|
"fmt": "prettier --write .",
|
|
54
55
|
"fmt:check": "prettier --check .",
|
|
55
56
|
"test": "mocha \"tests/**/*.test.js\"",
|
|
@@ -66,24 +67,26 @@
|
|
|
66
67
|
],
|
|
67
68
|
"license": "Apache-2.0",
|
|
68
69
|
"dependencies": {
|
|
69
|
-
"@eslint/core": "^1.1.
|
|
70
|
-
"@eslint/plugin-kit": "^0.6.
|
|
70
|
+
"@eslint/core": "^1.1.1",
|
|
71
|
+
"@eslint/plugin-kit": "^0.6.1",
|
|
71
72
|
"@humanwhocodes/momoa": "^3.3.10",
|
|
72
73
|
"natural-compare": "^1.4.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
76
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
76
|
-
"
|
|
77
|
+
"@types/node": "^20.19.0",
|
|
78
|
+
"c8": "^11.0.0",
|
|
77
79
|
"dedent": "^1.5.3",
|
|
78
|
-
"eslint": "^
|
|
79
|
-
"eslint-config-eslint": "^
|
|
80
|
-
"eslint-plugin-eslint-plugin": "^
|
|
80
|
+
"eslint": "^10.0.0",
|
|
81
|
+
"eslint-config-eslint": "^14.0.0",
|
|
82
|
+
"eslint-plugin-eslint-plugin": "^7.3.2",
|
|
81
83
|
"globals": "^17.0.0",
|
|
84
|
+
"knip": "^5.82.1",
|
|
82
85
|
"lint-staged": "^16.0.0",
|
|
83
86
|
"mdast-util-from-markdown": "^2.0.2",
|
|
84
87
|
"mocha": "^11.3.0",
|
|
85
88
|
"prettier": "3.8.1",
|
|
86
|
-
"typescript": "^5.9.
|
|
89
|
+
"typescript": "^5.9.3",
|
|
87
90
|
"yorkie": "^2.0.0"
|
|
88
91
|
},
|
|
89
92
|
"engines": {
|