Skip to content

Add package-json-lint rules and configuration for ESLint plugin#73328

Open
dkjensen wants to merge 4 commits intoWordPress:trunkfrom
dkjensen:add/eslint-plugin-pkg-json-lint
Open

Add package-json-lint rules and configuration for ESLint plugin#73328
dkjensen wants to merge 4 commits intoWordPress:trunkfrom
dkjensen:add/eslint-plugin-pkg-json-lint

Conversation

@dkjensen
Copy link
Copy Markdown

@dkjensen dkjensen commented Nov 16, 2025

What?

Adds a new ESLint rule @wordpress/validate-package-json that validates package.json files using the WordPress npm-package-json-lint configuration.

Why?

Currently, @wordpress/scripts provides a lint-pkg-json command that validates package.json files, but it has limitations:

  • Not integrated with ESLint - runs as a separate command (wp-scripts lint-pkg-json)
  • No editor integration - developers don't see errors in real-time while editing
  • Manual execution required - easy to forget to run before committing

This leads to:

  • Inconsistent property ordering across packages
  • Unsorted dependencies making diffs harder to review
  • Missing required fields like homepage, keywords, etc.
  • License value inconsistencies

By integrating npm-package-json-lint into ESLint, developers get:

Immediate feedback in their editor as they type

  • Auto-fix capabilities for ordering issues (eslint --fix)
  • Single linting workflow - same tool for both code and package.json
  • Consistent enforcement across all packages without manual intervention
  • Better DX - errors appear inline with other ESLint diagnostics

How?

New ESLint Rule:

  • Created validate-package-json rule that wraps npm-package-json-lint
  • Integrates with @wordpress/npm-package-json-lint-config
  • Supports auto-fixing for:
    • Property ordering (prefer-property-order)
    • Alphabetical dependency sorting (all dependency types)

Features:

  • Reports all npm-package-json-lint issues as ESLint diagnostics
  • Highlights specific properties in error locations
  • Configurable via rules option to disable/override specific checks

New Config Preset:

  • Added package-json-lint preset: plugin:@wordpress/eslint-plugin/package-json-lint
  • Automatically applies to all package.json files

Testing Instructions

Sample eslint configuration:

{
	"extends": [
		"plugin:@wordpress/eslint-plugin/package-json-lint",
		"plugin:@wordpress/eslint-plugin/recommended-with-formatting"
	],
	// Necessary if using other rules for JS/TS files in addition to package.json rules
	"overrides": [
		{
			"files": ["package.json"],
			"parser": "jsonc-eslint-parser"
		}
	]
}

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 16, 2025
@github-actions
Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @dkjensen! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@dkjensen dkjensen force-pushed the add/eslint-plugin-pkg-json-lint branch 2 times, most recently from ee5092f to c38e7c5 Compare November 17, 2025 13:12
@dkjensen dkjensen force-pushed the add/eslint-plugin-pkg-json-lint branch from c38e7c5 to b4c174e Compare November 17, 2025 13:13
@dkjensen dkjensen closed this Nov 18, 2025
@dkjensen dkjensen reopened this Nov 18, 2025
@dkjensen dkjensen marked this pull request as ready for review November 18, 2025 16:43
@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: First-time Contributor.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dkjensen <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: First-time Contributor.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

1 similar comment
@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: First-time Contributor.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant