Make WordPress Core

Opened 3 months ago

Closed 2 months ago

#65923 closed defect (bug) (fixed)

Exclude node_modules and built files from Grunt jshint:plugins

Reported by: afercia Owned by: afercia
Priority: normal Milestone: 7.2
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch commit
Cc: Focuses: javascript

Description (last modified by afercia)

The Grunt task jshint:plugins was added in [28798] / #28464 to 'allow plugin developers easier access to JSHint and supports good coding standards'.

The task is excluded from grunt:precommit as it is only meant to be ran manually for plugin development. It also accepts a CLI flag with the plugin directory name to scan a single plugin.

grunt jshint:plugins
grunt jshint:plugins --dir=query-monitor

However, after 12 years, many plugin now have their own built / minified / uglified JavaScript files. Not to mention development versions with a node_module directory.

In these cases, the task fails by either throwing errors or by hanging indefinitely.

Assuming this task is still useful for plugin development, it should be configured in a way to skip any node_module directory. Also, it should skip directories that typically contain built files or third party scripts.

To reproduce:

Install these plugins:

From the terminal in the WordPress root directory of a wordpress-develop install run grunt jshint:plugins.

Observe the task takes a very long time or even hangs indefinitely.

Try to run the task with only one of the above plugins installed, one at a time. Observe for some plugins that have built / minified files the task fails.

Change History (6)

This ticket was mentioned in ​PR #13207 on ​WordPress/wordpress-develop by ​@afercia.


3 months ago
#1

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/65923#ticket

Adds an ignore property to the Grunt jshint:plugins to exclude any directory where the name contains:

  • build
  • dist
  • gutenberg
  • node_modules
  • packages
  • test
  • vendor

## Use of AI Tools

None

#2 @afercia
3 months ago

To test the linked PR ​https://github.com/WordPress/wordpress-develop/pull/13207

  • Install a few more plugins that contain some JS files e.g.: Classic editor.
  • Run grunt jshint:plugins.
  • Observe the task completes in a few seconds and reports its findings, as expected.

The PR just adds an ignore property to the task configuration, excluding some of the most common directory names that contain JS files that aren't supposed to be linted.

The exclusion list can be certainly adjusted, if necessary.

#3 @afercia
3 months ago

  • Description modified (diff)

#4 @afercia
3 months ago

  • Description modified (diff)

#5 @afercia
2 months ago

  • Keywords commit added
  • Milestone Awaiting Review → 7.2
  • Owner set to afercia
  • Status new → assigned

#6 @afercia
2 months ago

  • Resolution → fixed
  • Status assigned → closed

In 63364:

Build/Test Tools: Make Grunt jshint:plugins skip common dependency/build output directories.

The Grunt task jshint:plugins is meant to allow plugin developers easier access to JSHint and support good coding standards. Plugin developers can run it to lint their plugin JavaScript files.

The script can't handle built files though and it hangs indefinitely when scanning large dependency directories like node_modules that many modern plugins use.

Adds an ignore list to the jshint:plugins file expansion configuration intended to skip common build/dependency directories.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13207

Props afercia, westonruter.
Fixes #65923.

Note: See TracTickets for help on using tickets.