@eslint/json 1.1.0 → 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 CHANGED
@@ -296,7 +296,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).
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
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
@@ -15,7 +15,7 @@ import rules from "./build/rules.js";
15
15
  const plugin = {
16
16
  meta: {
17
17
  name: "@eslint/json",
18
- version: "1.1.0", // x-release-please-version
18
+ version: "1.2.0", // x-release-please-version
19
19
  },
20
20
  languages: {
21
21
  json: new JSONLanguage({ mode: "json" }),
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/json",
3
- "version": "1.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\"",
@@ -73,17 +74,19 @@
73
74
  },
74
75
  "devDependencies": {
75
76
  "@arethetypeswrong/cli": "^0.18.2",
77
+ "@types/node": "^20.19.0",
76
78
  "c8": "^11.0.0",
77
79
  "dedent": "^1.5.3",
78
80
  "eslint": "^10.0.0",
79
81
  "eslint-config-eslint": "^14.0.0",
80
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.2",
89
+ "typescript": "^5.9.3",
87
90
  "yorkie": "^2.0.0"
88
91
  },
89
92
  "engines": {