Skip to content

JSHint: Exclude minified plugin files more effectively. - #13573

Closed
afercia wants to merge 2 commits into
WordPress:trunkfrom
afercia:jshint-exclude-minified-files-with-no-min-filename-suffix
Closed

afercia wants to merge 2 commits into
WordPress:trunkfrom
afercia:jshint-exclude-minified-files-with-no-min-filename-suffix

Conversation

@afercia

@afercia afercia commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/66123

Exclude minified files from the grunt jshint:plugins task by checking the JS files line length.
The assumption is that when a JS file contains lines with a length that is longer than 500 characters, then it is considered a minified file and it will be skipped.

Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): Claude Haiku 4.5
Used for: Initial research and suggestions; final implementation and tests were reviewed and edited by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Sep 17, 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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props afercia, westonruter.

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

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@afercia
afercia force-pushed the jshint-exclude-minified-files-with-no-min-filename-suffix branch 2 times, most recently from bde0cfc to 909ba30 Compare September 17, 2026 08:53
@afercia
afercia requested a review from westonruter September 20, 2026 11:08
@afercia
afercia force-pushed the jshint-exclude-minified-files-with-no-min-filename-suffix branch from 909ba30 to 8354c5a Compare September 21, 2026 17:31
Comment thread Gruntfile.js Outdated
Comment thread Gruntfile.js Outdated
Comment on lines +1126 to +1128
for ( var i = 0; i < Math.min( lines.length, 5 ); i++ ) {
// Exclude files with lines longer than 500 characters.
if ( lines[i].length > 500 ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be simplified:

Suggested change
for ( var i = 0; i < Math.min( lines.length, 5 ); i++ ) {
// Exclude files with lines longer than 500 characters.
if ( lines[i].length > 500 ) {
for ( const line of lines.slice( 0, 5 ) ) {
// Exclude files with lines longer than 500 characters.
if ( line.length > 500 ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This would create a new array, right? A negligible overhead though, fine with it.

Comment thread Gruntfile.js Outdated
@@ -1086,25 +1086,53 @@ module.exports = function(grunt) {
/*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that this was not a docblock, just a block comment. Now that we add param and return tags, it needs to use a double asterisk.

@afercia
afercia force-pushed the jshint-exclude-minified-files-with-no-min-filename-suffix branch from 8354c5a to 8d31caf Compare September 21, 2026 19:06
@westonruter
westonruter requested a lite review from Copilot September 21, 2026 19:51
@afercia afercia added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Sep 21, 2026
@github-actions github-actions Bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Sep 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The path resolution currently causes failures, and the scan does not inspect the entire file.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Updates grunt jshint:plugins to exclude minified JavaScript files based on line length.

Changes:

  • Adds minified-file detection.
  • Preserves directory filtering.
  • Improves documentation and logging.
File Summary
Gruntfile.js Updates plugin JSHint filtering and minified-file detection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Gruntfile.js
Comment on lines +1100 to +1102
// Bypasses folder targets so fs.readFileSync doesn't throw errors.
if ( ! fs.lstatSync( dirpath ).isFile() ) {
return false;
Comment thread Gruntfile.js
var lines = content.split( '\n' );

// Cap the maximum number of iterations at 5 lines.
for ( const line of lines.slice( 0, 5 ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes sense to me. Iterating over all lines in an an array is extremely fast, especially as the lines are already in memory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't have to aim for perfection.
Also I'd like to remind that in https://core.trac.wordpress.org/ticket/65950 I'm asking to consider whether jshint:plugins is still useful to some extend in the first place.
Honestly, I think it is not really used by developers to check their own plugins as today more modern and efficient tools are in use. I would consider to just remove this task.

wporg-sync pushed a commit that referenced this pull request Sep 21, 2026
…more effectively.

Follow-up to [63364]. Prevents `grunt jshint:plugins` from scanning minified JavaScript files that don't use a `.min` suffix in their filename. Assumes that JavaScript files that contain lines with a length that is longer than 500 characters are minified file and skips them.

Developed in #13573

Props afercia, westonruter.
Fixes #66123.


git-svn-id: https://develop.svn.wordpress.org/trunk@63783 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Sep 21, 2026
…more effectively.

Follow-up to [63364]. Prevents `grunt jshint:plugins` from scanning minified JavaScript files that don't use a `.min` suffix in their filename. Assumes that JavaScript files that contain lines with a length that is longer than 500 characters are minified file and skips them.

Developed in WordPress/wordpress-develop#13573

Props afercia, westonruter.
Fixes #66123.

Built from https://develop.svn.wordpress.org/trunk@63783


git-svn-id: http://core.svn.wordpress.org/trunk@62955 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@afercia

afercia commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@afercia afercia closed this Sep 21, 2026
@afercia
afercia deleted the jshint-exclude-minified-files-with-no-min-filename-suffix branch September 21, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants