packages/js/eslint-plugin/README.md
This is an ESLint plugin including configurations for WooCommerce development.
Note: This primarily extends the @wordpress/eslint-plugin/recommended ruleset and does not change any of the rules exposed on that plugin. As a base, all WooCommerce projects are expected to follow WordPress JavaScript Code Styles.
However, this ruleset does implement the following (which do not conflict with WordPress standards):
wp-prettier)import/orderparseInt.This package is Flat Config only. It requires:
^9.22.0 || ^10.0.0 (9.22 ships the eslint/config helpers this uses)prettier >=3 (WooCommerce uses wp-prettier@3)typescript >=5There is no .eslintrc support and no compatibility wrapper. If you are still on
ESLint 8, stay on @woocommerce/eslint-plugin@3.
Install the module
pnpm install @woocommerce/eslint-plugin --save-dev
Create an eslint.config.mjs at the root of your project and spread the
recommended config, which is a Flat Config array:
import woocommerce from '@woocommerce/eslint-plugin';
export default [ ...woocommerce.configs.recommended ];
Add your own configuration objects after it: Flat Config is last-wins, so later objects override earlier ones.
A root eslint.config.mjs already covers every file beneath it — ESLint searches
upward from each file for the nearest one, so most projects need only this. Add a
config to a subdirectory only when that subtree needs a different one. Note that
it replaces the ancestor rather than merging with it, so it has to spread
recommended itself.
import woocommerce from '@woocommerce/eslint-plugin';
export default [
{ ignores: [ 'build/**' ] },
...woocommerce.configs.recommended,
{
rules: {
'no-console': 'off',
},
},
];
Refer to the ESLint documentation on Flat Config for more information.
import or react yourselfeslint-plugin-import and eslint-plugin-react do not support ESLint v10.
recommended consumes them through the fixupPluginRules-wrapped instances that
@wordpress/eslint-plugin registers. If you register your own copy, its rules
will throw at lint time, and ESLint will report Cannot redefine plugin because
Flat Config keys plugins by object identity. Configure their rules on the
inherited plugins instead of re-registering them.
If you want to use prettier in your code editor, you'll need to create a .prettierrc.js file at the root of your project with the following:
module.exports = require( '@wordpress/prettier-config' );
The VS Code ESLint extension resolves Flat Config automatically from version
3.0.10 onwards. In a monorepo, set eslint.workingDirectories to [ { "mode": "auto" } ] so it resolves one config per package rather than from the window
root.
v3 exported an eslintrc config object and peered ESLint 8. v4 exports Flat
Config arrays and peers ESLint ^9.22 || ^10.
.eslintrc.js with eslint.config.mjs, and
extends: [ 'plugin:@woocommerce/eslint-plugin/recommended' ] with
...woocommerce.configs.recommended..eslintignore is not read by Flat Config. Move its patterns into an
ignores array.overrides entries become their own files-scoped config objects, and
excludedFiles becomes ignores alongside files in the same object.env becomes languageOptions.globals, most easily via the globals package.root: true has no equivalent and can be deleted.@woocommerce/dependency-group rule was removed in v3.1. Import grouping
is enforced by import/order, which no longer requires the
/* External dependencies */ comment blocks.