Skip to content

build(lint): enforce JS/SCSS/PHP lint via husky pre-commit hook#299

Open
jason10lee wants to merge 11 commits into
mainfrom
build/nppm-290-precommit-lint
Open

build(lint): enforce JS/SCSS/PHP lint via husky pre-commit hook#299
jason10lee wants to merge 11 commits into
mainfrom
build/nppm-290-precommit-lint

Conversation

@jason10lee

@jason10lee jason10lee commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

This PR restores the client-side lint gate that was lost when the plugins and themes moved into the monorepo.

The separate repos used cghooks for pre-commit SCSS lint. However, husky was already in the monorepo's root devDependencies but never activated; in the interest of following that example, we wired this up.

On every git commit, a husky pre-commit hook runs lint-staged against the staged files and blocks the commit on any lint violation (check only, same as the separate repos):

  • JS / TS → ESLint
  • SCSS → Stylelint
  • PHPcomposer phpcs (the shared root phpcs.xml, the same ruleset CI uses)

A single root config (.lintstagedrc.json, forced via lint-staged --config) lints every package uniformly, depending only on a root pnpm install + composer install rather than per-package installs. Husky activation is non-fatal, so it can never break the build:packages prepare step in CI, .git-less, or production installs. git commit --no-verify bypasses the hook.

While these lints only apply to diffs, activating SCSS lint repo-wide carries the risk of blocking commits on uncaught lint errors. Contributors have been exceedingly careful about their commits, though, and a test lint only flagged a couple of potential errors. We'll follow up with a separate PR to either squash those as bugs or identify them as necessary exemptions.

This--the client-side lint--is Phase 1 of 2 for NPPM-290. Phase 2 will add the repo-wide CI SCSS gate.

Part of NPPM-290: Theme linting: PHP & CSS.

How to test the changes in this Pull Request:

  1. Check out the branch and run pnpm install at the workspace root (this activates husky via the prepare script), then composer install at the root (installs the WP coding standards the PHP check needs).
  2. In any plugin or theme, create a .scss file containing a lint error (e.g. an empty block .x { }), git add it, and git commit → the commit is blocked with a Stylelint block-no-empty error.
  3. Repeat with a broken .php file (e.g. $x=1 ;) → blocked by composer phpcs; and a .js file with an unused variable → blocked by ESLint.
  4. Stage a clean change and git commit → the commit passes.
  5. Stage a broken file again and run git commit --no-verify → the hook is bypassed and the commit succeeds.
  6. Confirm only staged files are linted: with a committed lint error in one file, editing and committing a different, clean file in the same package still passes.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Notes for reviewers

  • eslint is now an explicit root devDependency (alongside stylelint / postcss-scss), so the hook's JS lint doesn't rely on pnpm's implicit *eslint* hoist.
  • PHP lint now shows an actionable hint (bin/precommit-phpcs.sh): if root composer install hasn't been run, it prints "run composer install" instead of raw phpcs/composer errors.
  • pnpm-lock.yaml churn is benign formatting. The ~226 added tarball: lines are pnpm 10.33's resolution-URL normalization (the repo's packageManager and CI both pin pnpm@10.33.0); only eslint, stylelint, and postcss-scss are real dependency additions.

Copilot AI review requested due to automatic review settings June 12, 2026 22:53
@jason10lee jason10lee self-assigned this Jun 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reinstates a repo-wide client-side lint gate by wiring up Husky + lint-staged at the workspace root, so staged JS/TS, SCSS, and PHP are linted on every git commit and commits are blocked on violations.

Changes:

  • Activates Husky via the root prepare script and adds a pre-commit hook that runs lint-staged with a single root config.
  • Introduces a root .lintstagedrc.json that runs ESLint (JS/TS), Stylelint (SCSS), and composer phpcs (PHP) on staged files.
  • Adds required root devDependencies (e.g., stylelint, postcss-scss) and updates documentation in AGENTS.md.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pnpm-lock.yaml Locks newly added linting-related dependencies (e.g., Stylelint, postcss-scss).
package.json Runs Husky during prepare and centralizes tooling devDependencies; removes inline lint-staged config.
AGENTS.md Documents the new Husky + lint-staged pre-commit lint gate behavior and requirements.
.lintstagedrc.json Defines the staged-file lint commands for JS/TS, SCSS, and PHP.
.husky/pre-commit Adds the pre-commit hook that invokes lint-staged with the root config.

Comment thread package.json Outdated
Comment thread .husky/pre-commit

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.

Comment thread AGENTS.md Outdated
Comment thread package.json

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.

Comment thread .husky/pre-commit
@jason10lee jason10lee marked this pull request as ready for review June 13, 2026 01:03
@jason10lee jason10lee requested a review from a team as a code owner June 13, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants