build(lint): enforce JS/SCSS/PHP lint via husky pre-commit hook#299
Open
jason10lee wants to merge 11 commits into
Open
build(lint): enforce JS/SCSS/PHP lint via husky pre-commit hook#299jason10lee wants to merge 11 commits into
jason10lee wants to merge 11 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
preparescript and adds apre-commithook that runslint-stagedwith a single root config. - Introduces a root
.lintstagedrc.jsonthat runs ESLint (JS/TS), Stylelint (SCSS), andcomposer phpcs(PHP) on staged files. - Adds required root devDependencies (e.g.,
stylelint,postcss-scss) and updates documentation inAGENTS.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. |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
cghooksfor pre-commit SCSS lint. However,huskywas already in the monorepo's rootdevDependenciesbut never activated; in the interest of following that example, we wired this up.On every
git commit, a husky pre-commit hook runslint-stagedagainst the staged files and blocks the commit on any lint violation (check only, same as the separate repos):composer phpcs(the shared rootphpcs.xml, the same ruleset CI uses)A single root config (
.lintstagedrc.json, forced vialint-staged --config) lints every package uniformly, depending only on a rootpnpm install+composer installrather than per-package installs. Husky activation is non-fatal, so it can never break thebuild:packagespreparestep in CI,.git-less, or production installs.git commit --no-verifybypasses 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:
pnpm installat the workspace root (this activates husky via thepreparescript), thencomposer installat the root (installs the WP coding standards the PHP check needs)..scssfile containing a lint error (e.g. an empty block.x { }),git addit, andgit commit→ the commit is blocked with a Stylelintblock-no-emptyerror..phpfile (e.g.$x=1 ;) → blocked bycomposer phpcs; and a.jsfile with an unused variable → blocked by ESLint.git commit→ the commit passes.git commit --no-verify→ the hook is bypassed and the commit succeeds.Other information:
Notes for reviewers
eslintis now an explicit root devDependency (alongsidestylelint/postcss-scss), so the hook's JS lint doesn't rely on pnpm's implicit*eslint*hoist.bin/precommit-phpcs.sh): if rootcomposer installhasn't been run, it prints "runcomposer install" instead of raw phpcs/composer errors.pnpm-lock.yamlchurn is benign formatting. The ~226 addedtarball:lines are pnpm 10.33's resolution-URL normalization (the repo'spackageManagerand CI both pinpnpm@10.33.0); onlyeslint,stylelint, andpostcss-scssare real dependency additions.