eslint-plugin-package-json 0.56.2 β†’ 0.56.3

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/CHANGELOG.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # Changelog
2
2
 
3
- ## [0.56.2](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.56.1...v0.56.2) (2025-09-04)
3
+ ## [0.56.3](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.56.2...v0.56.3) (2025-09-15)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **plugin:** update types to be compatible with `defineConfig` ([#1245](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1245)) ([861e5e1](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/861e5e129b3a5e3455b6b2a2a26d453086f20c14)), closes [#1242](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1242)
4
9
 
10
+ ## [0.56.2](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.56.1...v0.56.2) (2025-09-04)
5
11
 
6
12
  ### Bug Fixes
7
13
 
8
- * improve sort-collections docs and error messages ([#1250](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1250)) ([1864376](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/1864376039db3db690423051b0dd8a2104395aa4)), closes [#1243](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1243) [#1243](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1243)
14
+ - improve sort-collections docs and error messages ([#1250](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1250)) ([1864376](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commit/1864376039db3db690423051b0dd8a2104395aa4)), closes [#1243](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1243) [#1243](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/1243)
9
15
 
10
16
  ## [0.56.1](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/compare/v0.56.0...v0.56.1) (2025-08-31)
11
17
 
package/README.md CHANGED
@@ -249,7 +249,7 @@ Thanks! πŸ—‚
249
249
  <td align="center" valign="top" width="14.28%"><a href="https://davidlj95.com"><img src="https://avatars.githubusercontent.com/u/8050648?v=4?s=100" width="100px;" alt="David LJ"/><br /><sub><b>David LJ</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=davidlj95" title="Documentation">πŸ“–</a></td>
250
250
  <td align="center" valign="top" width="14.28%"><a href="http://lishaduck.github.io"><img src="https://avatars.githubusercontent.com/u/88557639?v=4?s=100" width="100px;" alt="Eli"/><br /><sub><b>Eli</b></sub></a><br /><a href="#ideas-lishaduck" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Alishaduck" title="Bug reports">πŸ›</a></td>
251
251
  <td align="center" valign="top" width="14.28%"><a href="http://heggria.site"><img src="https://avatars.githubusercontent.com/u/34475327?v=4?s=100" width="100px;" alt="Heggria"/><br /><sub><b>Heggria</b></sub></a><br /><a href="#ideas-heggria" title="Ideas, Planning, & Feedback">πŸ€”</a></td>
252
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/Zamiell"><img src="https://avatars.githubusercontent.com/u/5511220?v=4?s=100" width="100px;" alt="James"/><br /><sub><b>James</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=Zamiell" title="Code">πŸ’»</a> <a href="#ideas-Zamiell" title="Ideas, Planning, & Feedback">πŸ€”</a></td>
252
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Zamiell"><img src="https://avatars.githubusercontent.com/u/5511220?v=4?s=100" width="100px;" alt="James"/><br /><sub><b>James</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=Zamiell" title="Code">πŸ’»</a> <a href="#ideas-Zamiell" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3AZamiell" title="Bug reports">πŸ›</a></td>
253
253
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/zetlen"><img src="https://avatars.githubusercontent.com/u/1643758?v=4?s=100" width="100px;" alt="James Zetlen"/><br /><sub><b>James Zetlen</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=zetlen" title="Code">πŸ’»</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3Azetlen" title="Bug reports">πŸ›</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=zetlen" title="Documentation">πŸ“–</a> <a href="#infra-zetlen" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="#maintenance-zetlen" title="Maintenance">🚧</a> <a href="#tool-zetlen" title="Tools">πŸ”§</a></td>
254
254
  <td align="center" valign="top" width="14.28%"><a href="https://piranna.github.io/"><img src="https://avatars.githubusercontent.com/u/532414?v=4?s=100" width="100px;" alt="JesΓΊs LeganΓ©s-Combarro"/><br /><sub><b>JesΓΊs LeganΓ©s-Combarro</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=piranna" title="Code">πŸ’»</a></td>
255
255
  <td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com/"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg ✨"/><br /><sub><b>Josh Goldberg ✨</b></sub></a><br /><a href="#tool-JoshuaKGoldberg" title="Tools">πŸ”§</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">πŸ›</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=JoshuaKGoldberg" title="Code">πŸ’»</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/commits?author=JoshuaKGoldberg" title="Documentation">πŸ“–</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">🚧</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="#content-JoshuaKGoldberg" title="Content">πŸ–‹</a> <a href="#projectManagement-JoshuaKGoldberg" title="Project Management">πŸ“†</a></td>
@@ -1,4 +1,4 @@
1
- import { AST, RuleListener } from "jsonc-eslint-parser";
1
+ import { AST } from "jsonc-eslint-parser";
2
2
  import * as ESTree from "estree";
3
3
  import { AST as AST$1, Rule, SourceCode } from "eslint";
4
4
 
@@ -32,7 +32,7 @@ interface PackageJsonRuleContext<Options extends unknown[] = unknown[]> extends
32
32
  sourceCode: PackageJsonSourceCode;
33
33
  }
34
34
  interface PackageJsonRuleModule<Options extends unknown[] = unknown[]> {
35
- create(context: PackageJsonRuleContext<Options>): RuleListener;
35
+ create(context: PackageJsonRuleContext<Options>): Rule.NodeListener;
36
36
  meta: Rule.RuleMetaData;
37
37
  }
38
38
  interface PackageJsonSourceCode extends SourceCode {
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PackageJsonPluginSettings, PackageJsonRuleModule } from "./createRule.js";
2
2
  import { plugin } from "./plugin.js";
3
3
  import * as jsonc_eslint_parser0 from "jsonc-eslint-parser";
4
+ import * as eslint0 from "eslint";
4
5
 
5
6
  //#region src/index.d.ts
6
7
  declare const rules: Record<string, PackageJsonRuleModule<unknown[]>>;
@@ -20,14 +21,7 @@ declare const configs: {
20
21
  };
21
22
  name: string;
22
23
  plugins: {
23
- readonly "package-json": {
24
- configs: /*elided*/any;
25
- meta: {
26
- name: string;
27
- version: string;
28
- };
29
- rules: Record<string, PackageJsonRuleModule<unknown[]>>;
30
- };
24
+ readonly "package-json": eslint0.ESLint.Plugin;
31
25
  };
32
26
  rules: {
33
27
  "package-json/valid-package-definition": ["error", {
package/lib/plugin.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { PackageJsonRuleModule } from "./createRule.js";
2
2
  import * as parserJsonc from "jsonc-eslint-parser";
3
+ import { ESLint } from "eslint";
3
4
 
4
5
  //#region src/plugin.d.ts
5
6
  declare const plugin: {
@@ -19,7 +20,7 @@ declare const plugin: {
19
20
  };
20
21
  name: string;
21
22
  plugins: {
22
- readonly "package-json": /*elided*/any;
23
+ readonly "package-json": ESLint.Plugin;
23
24
  };
24
25
  rules: {
25
26
  "package-json/valid-package-definition": ["error", {
package/lib/plugin.js CHANGED
@@ -17,8 +17,7 @@ import { createRequire } from "node:module";
17
17
  import * as parserJsonc from "jsonc-eslint-parser";
18
18
 
19
19
  //#region src/plugin.ts
20
- const require = createRequire(import.meta.url);
21
- const { name, version } = require("../package.json");
20
+ const { name, version } = createRequire(import.meta.url)("../package.json");
22
21
  const rules$2 = {
23
22
  "no-empty-fields": rule,
24
23
  "no-redundant-files": rule$1,
@@ -73,8 +73,7 @@ const rule = createRule({
73
73
  messageId: "unnecessaryBin"
74
74
  }];
75
75
  for (const validation of validations) for (const fileToCheck of validation.files) for (const [index, fileEntry] of files.entries()) if (isNotNullish(fileEntry) && isJSONStringLiteral(fileEntry)) {
76
- const regex = getCachedLocalFileRegex(fileEntry.value);
77
- if (regex?.test(fileToCheck)) report(files, index, validation.messageId);
76
+ if (getCachedLocalFileRegex(fileEntry.value)?.test(fileToCheck)) report(files, index, validation.messageId);
78
77
  }
79
78
  }
80
79
  };
@@ -49,8 +49,7 @@ const rule = createRule({
49
49
  const orderedKeys = Object.keys(orderedSource);
50
50
  const { properties } = ast.body[0].expression;
51
51
  for (let i = 0; i < properties.length; i += 1) {
52
- const property = properties[i].key;
53
- const { value } = property;
52
+ const { value } = properties[i].key;
54
53
  if (value === orderedKeys[i]) continue;
55
54
  context.report({
56
55
  data: { property: value },
@@ -73,8 +73,7 @@ const capitalize = (str) => {
73
73
  const rule = createRule({
74
74
  create(context) {
75
75
  if (!context.options[0]) return {};
76
- const optionsProvided = Array.isArray(context.options[0]) ? [...context.options[0]].reverse() : [context.options[0]];
77
- const optionsArray = optionsProvided.map((option) => ({
76
+ const optionsArray = (Array.isArray(context.options[0]) ? [...context.options[0]].reverse() : [context.options[0]]).map((option) => ({
78
77
  ...option,
79
78
  forPackages: option.forPackages?.map((pattern) => new RegExp(pattern)),
80
79
  rangeTypes: Array.isArray(option.rangeType) ? option.rangeType : [option.rangeType]
@@ -93,8 +92,7 @@ const rule = createRule({
93
92
  for (const options of optionsArray) {
94
93
  if (options.forDependencyTypes && !options.forDependencyTypes.includes(dependencyType)) continue;
95
94
  if (options.forPackages) {
96
- const isMatch = options.forPackages.some((packageNameRegex) => packageNameRegex.test(name));
97
- if (!isMatch) continue;
95
+ if (!options.forPackages.some((packageNameRegex) => packageNameRegex.test(name))) continue;
98
96
  }
99
97
  if (options.forVersions && (/^workspace:[^~*]?$/.test(version) || version !== "*" && !semver.satisfies(version.replace(/(?:workspace:)?[^~]?/, ""), options.forVersions))) continue;
100
98
  const rangeTypes = options.rangeTypes;
@@ -106,14 +104,13 @@ const rule = createRule({
106
104
  });
107
105
  break;
108
106
  }
109
- const rangeTypeMatch = rangeTypes.find((rangeType) => {
107
+ if (!rangeTypes.find((rangeType) => {
110
108
  switch (rangeType) {
111
109
  case "caret": return isCaretRange;
112
110
  case "pin": return isPinned;
113
111
  case "tilde": return isTildeRange;
114
112
  }
115
- });
116
- if (!rangeTypeMatch) context.report({
113
+ })) context.report({
117
114
  data: { rangeTypes: rangeTypes.join(", ") },
118
115
  messageId: "wrongRangeType",
119
116
  node: property.value,
@@ -9,8 +9,7 @@ const linkRegex = /^link:/;
9
9
  const rule = createRule({
10
10
  create(context) {
11
11
  return { "Program:exit"() {
12
- const original = JSON.parse(context.sourceCode.text);
13
- const { dependencies, devDependencies, peerDependencies } = original;
12
+ const { dependencies, devDependencies, peerDependencies } = JSON.parse(context.sourceCode.text);
14
13
  const depObjs = [
15
14
  Object.entries(dependencies ?? {}),
16
15
  Object.entries(peerDependencies ?? {}),
@@ -12,8 +12,7 @@ const rule = createRule({
12
12
  create(context) {
13
13
  const ignoreProperties = context.options[0]?.ignoreProperties ?? [];
14
14
  return { "Program:exit"() {
15
- const validation = validate(context.sourceCode.text);
16
- const usableErrors = validation.errors?.filter((error) => {
15
+ const usableErrors = validate(context.sourceCode.text).errors?.filter((error) => {
17
16
  return isUsableError(error.message) && !ignoreProperties.includes(error.field);
18
17
  }) ?? [];
19
18
  for (const error of usableErrors) if (error.message) context.report({
@@ -10,39 +10,38 @@ import { isJSONStringLiteral } from "./predicates.js";
10
10
  */
11
11
  const createSimpleRequirePropertyRule = (propertyName, { ignorePrivateDefault = false, isRecommended } = {}) => {
12
12
  const ruleName = `require-${propertyName}`;
13
- const rule = createRule({
14
- create(context) {
15
- const enforceForPrivate = context.settings.packageJson?.enforceForPrivate;
16
- const ignorePrivate = context.options[0]?.ignorePrivate ?? (typeof enforceForPrivate === "boolean" ? !enforceForPrivate : ignorePrivateDefault);
17
- return { "Program > JSONExpressionStatement > JSONObjectExpression"(node) {
18
- if (ignorePrivate && node.properties.some((property) => isJSONStringLiteral(property.key) && property.key.value === "private" && property.value.type === "JSONLiteral" && property.value.value === true)) return;
19
- if (!node.properties.some((property) => isJSONStringLiteral(property.key) && property.key.value === propertyName)) context.report({
20
- data: { property: propertyName },
21
- messageId: "missing",
22
- node: context.sourceCode.ast
23
- });
24
- } };
25
- },
26
- meta: {
27
- docs: {
28
- description: `Requires the \`${propertyName}\` property to be present.`,
29
- recommended: isRecommended
30
- },
31
- messages: { missing: "Property '{{property}}' is required." },
32
- schema: [{
33
- additionalProperties: false,
34
- properties: { ignorePrivate: {
35
- default: ignorePrivateDefault,
36
- type: "boolean"
37
- } },
38
- type: "object"
39
- }],
40
- type: "suggestion"
41
- },
42
- name: ruleName
43
- });
44
13
  return {
45
- rule,
14
+ rule: createRule({
15
+ create(context) {
16
+ const enforceForPrivate = context.settings.packageJson?.enforceForPrivate;
17
+ const ignorePrivate = context.options[0]?.ignorePrivate ?? (typeof enforceForPrivate === "boolean" ? !enforceForPrivate : ignorePrivateDefault);
18
+ return { "Program > JSONExpressionStatement > JSONObjectExpression"(node) {
19
+ if (ignorePrivate && node.properties.some((property) => isJSONStringLiteral(property.key) && property.key.value === "private" && property.value.type === "JSONLiteral" && property.value.value === true)) return;
20
+ if (!node.properties.some((property) => isJSONStringLiteral(property.key) && property.key.value === propertyName)) context.report({
21
+ data: { property: propertyName },
22
+ messageId: "missing",
23
+ node: context.sourceCode.ast
24
+ });
25
+ } };
26
+ },
27
+ meta: {
28
+ docs: {
29
+ description: `Requires the \`${propertyName}\` property to be present.`,
30
+ recommended: isRecommended
31
+ },
32
+ messages: { missing: "Property '{{property}}' is required." },
33
+ schema: [{
34
+ additionalProperties: false,
35
+ properties: { ignorePrivate: {
36
+ default: ignorePrivateDefault,
37
+ type: "boolean"
38
+ } },
39
+ type: "object"
40
+ }],
41
+ type: "suggestion"
42
+ },
43
+ name: ruleName
44
+ }),
46
45
  ruleName
47
46
  };
48
47
  };
@@ -11,36 +11,35 @@ import { formatErrors } from "./formatErrors.js";
11
11
  const createSimpleValidPropertyRule = (propertyName, validationFunction, aliases = []) => {
12
12
  const ruleName = `valid-${propertyName}`;
13
13
  const propertyNames = [propertyName, ...aliases];
14
- const rule = createRule({
15
- create(context) {
16
- return propertyNames.reduce((acc, name) => {
17
- acc[`Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=${name}]`] = (node) => {
18
- const valueNode = node.value;
19
- const value = JSON.parse(context.sourceCode.getText(valueNode));
20
- const errors = validationFunction(value);
21
- if (errors.length) context.report({
22
- data: { errors: formatErrors(errors) },
23
- messageId: "validationError",
24
- node: valueNode
25
- });
26
- };
27
- return acc;
28
- }, {});
29
- },
30
- meta: {
31
- docs: {
32
- category: "Best Practices",
33
- description: `Enforce that the \`${propertyName}\`${aliases.length ? ` (also: ${aliases.map((alias) => `\`${alias}\``).join(", ")})` : ""} property is valid.`,
34
- recommended: true
35
- },
36
- messages: { validationError: `Invalid ${propertyName}: {{ errors }}` },
37
- schema: [],
38
- type: "problem"
39
- },
40
- name: ruleName
41
- });
42
14
  return {
43
- rule,
15
+ rule: createRule({
16
+ create(context) {
17
+ return propertyNames.reduce((acc, name) => {
18
+ acc[`Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty[key.value=${name}]`] = (node) => {
19
+ const valueNode = node.value;
20
+ const value = JSON.parse(context.sourceCode.getText(valueNode));
21
+ const errors = validationFunction(value);
22
+ if (errors.length) context.report({
23
+ data: { errors: formatErrors(errors) },
24
+ messageId: "validationError",
25
+ node: valueNode
26
+ });
27
+ };
28
+ return acc;
29
+ }, {});
30
+ },
31
+ meta: {
32
+ docs: {
33
+ category: "Best Practices",
34
+ description: `Enforce that the \`${propertyName}\`${aliases.length ? ` (also: ${aliases.map((alias) => `\`${alias}\``).join(", ")})` : ""} property is valid.`,
35
+ recommended: true
36
+ },
37
+ messages: { validationError: `Invalid ${propertyName}: {{ errors }}` },
38
+ schema: [],
39
+ type: "problem"
40
+ },
41
+ name: ruleName
42
+ }),
44
43
  ruleName
45
44
  };
46
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-package-json",
3
- "version": "0.56.2",
3
+ "version": "0.56.3",
4
4
  "description": "Rules for consistent, readable, and valid package.json files. πŸ—‚οΈ",
5
5
  "homepage": "https://github.com/JoshuaKGoldberg/eslint-plugin-package-json#readme",
6
6
  "bugs": {
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "@eslint-community/eslint-plugin-eslint-comments": "4.5.0",
60
- "@eslint/js": "9.34.0",
60
+ "@eslint/js": "9.35.0",
61
61
  "@release-it/conventional-changelog": "10.0.0",
62
62
  "@types/eslint-plugin-markdown": "2.0.2",
63
63
  "@types/estree": "1.0.7",
@@ -68,10 +68,10 @@
68
68
  "@vitest/coverage-v8": "3.2.0",
69
69
  "@vitest/eslint-plugin": "1.3.3",
70
70
  "console-fail-test": "0.5.0",
71
- "eslint": "9.34.0",
71
+ "eslint": "9.35.0",
72
72
  "eslint-doc-generator": "2.2.0",
73
73
  "eslint-plugin-eslint-plugin": "7.0.0",
74
- "eslint-plugin-jsdoc": "54.1.0",
74
+ "eslint-plugin-jsdoc": "54.5.0",
75
75
  "eslint-plugin-jsonc": "2.20.0",
76
76
  "eslint-plugin-markdown": "5.1.0",
77
77
  "eslint-plugin-n": "17.21.0",