Skip to content

Add JSHint configuration scoped to the repo to avoid ancestor-config false positives#2544

Merged
westonruter merged 1 commit into
trunkfrom
add/jshint-config
Jun 27, 2026
Merged

Add JSHint configuration scoped to the repo to avoid ancestor-config false positives#2544
westonruter merged 1 commit into
trunkfrom
add/jshint-config

Conversation

@westonruter

Copy link
Copy Markdown
Member

Summary

When this repo is checked out inside a wordpress-develop checkout (a common local setup), the IDE's JSHint inspection has no .jshintrc in 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 that eslint.config.js already encodes.

What's included

  • .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 but JSHint's stale node set omits.
  • plugins/.jshintrc — Browser environment for the shipped client scripts. Adds devel (console) 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 — 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-oriented plugins/ 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

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>
@github-actions

github-actions Bot commented Jun 20, 2026

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: westonruter <westonruter@git.wordpress.org>
Co-authored-by: b1ink0 <b1ink0@git.wordpress.org>

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

@github-actions github-actions Bot added the [Plugin] Enhanced Responsive Images Issues for the Enhanced Responsive Images plugin (formerly Auto Sizes) label Jun 20, 2026
@westonruter westonruter added Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release [Type] Enhancement A suggestion for improvement of an existing feature labels Jun 20, 2026
@westonruter

Copy link
Copy Markdown
Member Author

When you have the performance repo checked out in wordpress-develop at src/wp-content/plugins/performance, this prevents PhpStorm from surfacing errors like the following in bin/commands/versions.js:

image image

@westonruter westonruter requested a review from b1ink0 June 22, 2026 04:35

@b1ink0 b1ink0 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.

LGTM

@westonruter westonruter merged commit 730f1d5 into trunk Jun 27, 2026
18 of 22 checks passed
@westonruter westonruter deleted the add/jshint-config branch June 27, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release [Plugin] Enhanced Responsive Images Issues for the Enhanced Responsive Images plugin (formerly Auto Sizes) [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants