Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the JavaScript linting infrastructure by replacing gulp-eslint with the native eslint library and upgrading to ESLint v9. It introduces a shared runESLint function that supports auto-fixing, customizable error handling, and file filtering.
Changes:
- Upgraded from ESLint v6 to v9 and removed the deprecated
gulp-eslintdependency - Implemented a reusable
runESLintfunction with support for--fix,--fail-on-lint-errors, and--show-filesflags - Added new config options for overriding ESLint config files and excluding specific files from linting
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tasks/lint.js | Introduces runESLint function and refactors lintJsTask to use native ESLint API with flag support |
| tasks/decaffeinate.js | Updates decaffeination task to use shared runESLint function instead of gulp-eslint |
| package.json | Upgrades eslint to v9.39.2, adds @eslint/js and eslint-plugin-jsdoc, removes gulp-eslint |
| lib/lintfiles/.eslintrc.js | Replaces old config with new ESLint v9 flat config format including JSDoc rules |
| lib/lintfiles/.eslintrc | Removes deprecated ESLint config file that extended @skyverge/eslint-config |
| lib/config.js | Adds eslint.configFile and eslint.excludeFiles configuration options |
| helpers/arguments.js | New helper module providing functions to check for command-line flags |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/lintfiles/.eslintrc.js
Outdated
| files: ["**/*.js"], | ||
| plugins: { | ||
| js, | ||
| jsdoc, | ||
| }, | ||
| extends: ["js/recommended"], |
There was a problem hiding this comment.
The extends property is not supported in ESLint v9's flat config format. You should spread the recommended config instead: ...js.configs.recommended, at the top level of the config object.
| files: ["**/*.js"], | |
| plugins: { | |
| js, | |
| jsdoc, | |
| }, | |
| extends: ["js/recommended"], | |
| ...js.configs.recommended, | |
| files: ["**/*.js"], | |
| plugins: { | |
| js, | |
| jsdoc, | |
| }, |
There was a problem hiding this comment.
Docs indicate it works fine: https://www.npmjs.com/package/@eslint/js
Their example is exactly what we're doing here.
There was a problem hiding this comment.
@agibson-godaddy yeah ESLint v9 docs confirm this use of extends key: https://eslint.org/docs/latest/use/configure/combine-configs
That said, v9 also migrates to a flat eslint.config.js file by default with .eslintrc being deprecated and scheduled for complete removal in v10
Would it make sense for us to make that switch while we're migrating here, or should that be an additional step?
Ah sorry, I was thrown off by the naming, but I see that we're explicitly passing the new flat config when initializing, which also allows us to account for plugin overrides - nice work 👍
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
nikolas4175-godaddy
left a comment
There was a problem hiding this comment.
Approving with one minor note below. Ran QA on Memberships and also confirmed configFile and excludeFiles work as expected 🚀
✅ QA
- From the plugin directory, run
sake lint:js --show-files- It outputs a list of files with errors, but not the errors themselves
- Run
sake lint:js- You get lint errors outputted
- Run
sake lint:js --fix- Errors are fixed
- Run
git diffto inspect changes- Changes look reasonable, as per defined rules
- Run
sake decaffeinate- Success without errors
- You end up with converted js files
- JS files retain same directory structure as coffee files
| if (errorCount > 0 && failOnErrors) { | ||
| throw new Error(`${taskName} found ${errorCount} error(s) and ${warningCount} warning(s). Build halted due to failOnErrors setting.`); | ||
| } else if (errorCount > 0) { | ||
| log.info(`ℹ ${taskName} found ${errorCount} error(s) and ${warningCount} warning(s), but continuing build. Use --fail-on-lint-errors to halt on errors.`); |
There was a problem hiding this comment.
Bit of an odd output here: https://share.zight.com/geuX9K5k
This line logs at the end of linting even if that's the only task being run. Could we move this to the build task after linting is done and check for errors there?
Issue: https://godaddy-corp.atlassian.net/browse/MWC-19073
Summary
gulp-eslintin favour ofeslintdirectlyeslintversion. Current one committed pulls in most of the rules from the old config--fixflag (e.g.npx sake lint:js --fix)Flags:
--fixflag to auto fix errors (note: some errors cannot be fixed automatically)--show-filesflag just to list out files that have errors, without listing the errors themselves (useful for debugging which files are being linted to sanity check you're not linting vendor files)--fail-on-lint-errorsto halt the entire process if errors are encountered (i.e. if you're runningnpx sake deployand want to completely halt if there are lint errors)Config Options
There are two new config options:
tasks.lint.eslint.configFile-- to override the entire config file; value is a path relative to root plugin directorytasks.lint.eslint.excludeFiles-- array of files to exclude from linting. handy if you don't want to override the whole config but want to exclude some filesExample:
Exclude bundled jquery timepicker from linting:
QA
woocommerce-membershipssake lint:js --show-filessake lint:jssake lint:js --fixgit diffto inspect changessake decaffinateAfter merge