Add JSHint configuration scoped to the repo to avoid ancestor-config false positives#2544
Merged
Conversation
When this repo is checked out inside a wordpress-develop checkout, IDE JSHint inspections fall through to wordpress-develop's ancestor `.jshintrc`, which assumes a browser environment, an older ECMAScript version, and WP-core's operator-at-line-end style. That produces false positives across this repo's Prettier-formatted, modern, mixed Node/browser JavaScript. Add a local JSHint configuration that shadows the ancestor: - `.jshintrc` (root): Node environment for the root config files, `bin/`, and `tools/` tooling; enables `laxbreak` (Prettier puts `?`/`:` at line starts), `loopfunc`, and the `fetch`/`AbortController` globals Node 18+ provides. - `plugins/.jshintrc`: browser environment for the shipped client scripts, with `devel` plus the modern globals the stale `browser` set omits (ResizeObserver, requestIdleCallback/cancelIdleCallback, structuredClone, CompressionStream, crypto) and `name` so the ES-module `export const name` stops tripping the read-only-global redefinition warning. - `.jshintignore`: skip generated/minified output (build/, dist/, *.min.js) and vendored/installed dependencies. The auto-sizes Playwright spec is a Node CommonJS test living under the browser-oriented `plugins/` tree, so it gets an inline `/* jshint node: true */` directive to layer the Node globals on top of the browser config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Member
Author
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.


Summary
When this repo is checked out inside a
wordpress-developcheckout (a common local setup), the IDE's JSHint inspection has no.jshintrcin this repo to anchor on, so it walks up the directory tree and falls through to wordpress-develop's ancestor.jshintrc. That ancestor config assumes a browser environment, an older ECMAScript version, and WP-core's operator-at-line-end style — none of which match this repo's Prettier-formatted, modern, mixed Node/browser JavaScript. The result is a stream of false-positive JSHint warnings across the repo's JS files.This PR adds a JSHint configuration scoped to this repo that shadows the ancestor and silences those false positives, while still doing real linting (genuinely undefined globals and unused vars are still flagged).
This is purely IDE/tooling configuration — this repo uses ESLint (
@wordpress/scripts) for its actual JS linting and does not run JSHint in CI. The configuration simply mirrors, in JSHint terms, the Node-vs-browser split thateslint.config.jsalready encodes.What's included
.jshintrc(root) — Node environment for the root config files,bin/, andtools/tooling. Enableslaxbreak(Prettier puts?/:at line starts),loopfunc, and thefetch/AbortControllerglobals Node 18+ provides but JSHint's stalenodeset omits.plugins/.jshintrc— Browser environment for the shipped client scripts. Addsdevel(console) plus the modern globals the stalebrowserset omits:ResizeObserver,requestIdleCallback/cancelIdleCallback,structuredClone,CompressionStream,crypto— andname, so the ES-moduleexport const namestops tripping the read-only-global redefinition warning..jshintignore— Skips generated/minified output (build/,dist/,**/*.min.js) and vendored/installed dependencies.plugins/auto-sizes/tests/e2e/specs/improve-calculate-sizes.spec.js— Gets an inline/* jshint node: true */directive because it's a Node CommonJS Playwright test living under the browser-orientedplugins/tree, so it needs the Node globals layered on top of the browser config.Testing
Ran JSHint (via the wordpress-develop checkout's
node_modules/.bin/jshint, auto-discovering these configs) across all tracked, non-generated JS files in the repo: 0 warnings. A probe confirmed the new configs are the ones being applied — JSHint recognizes the added globals (e.g.ResizeObserver) yet still flags genuinely undefined identifiers and unused variables, so linting integrity is preserved.🤖 Generated with Claude Code