Description
After upgrading to a version of magento-coding-standard that uses ESLint 9,
the documented npm run eslint -- path/to/analyze command no longer works
when the package is installed as a vendor dependency via composer.
Root Cause
ESLint 9 introduced strict base path enforcement (flat config) - ESLint 9
sets its base path to the physical location of eslint.config.mjs. It
refuses to lint any files outside that folder.
Since eslint.config.mjs physically lives at:
vendor/magento/magento-coding-standard/eslint/eslint.config.mjs
And project files are at:
app/code/ or app/design/
ESLint refuses to lint them because they are outside the base path.
What Worked
1. Running the binary directly from project root
Instead of npm run eslint, run the binary directly from src/:
vendor/magento/magento-coding-standard/node_modules/.bin/eslint \
-c vendor/magento/magento-coding-standard/eslint/eslint.config.mjs \
app/code/
Running from src/ sets the working directory correctly so ESLint's base
path covers both app/code/ and app/design/ directories.
2. Handling ignore paths
Since ESLint 9 also removed support for .eslintignore, a wrapper
eslint.config.mjs was created at the project root (src/) to import
the magento config and add project specific ignore patterns:
import magentoConfig from "./vendor/magento/magento-coding-standard/eslint/eslint.config.mjs";
export default [
...magentoConfig,
{
ignores: [
// add your project specific ignore patterns here
'**/path/to/file-to-ignore.js',
],
}
];
This wrapper config at src/ level also allows running ESLint without
the -c flag, since ESLint will automatically find and use it by searching
upward from the target files:
vendor/magento/magento-coding-standard/node_modules/.bin/eslint app/code/
Suggested Fix
Update the README to document the correct usage for projects that install
this as a vendor dependency, including:
- Running the binary directly from the project root
- Creating a wrapper
eslint.config.mjs at project root level for ignore patterns
Description
After upgrading to a version of magento-coding-standard that uses ESLint 9,
the documented
npm run eslint -- path/to/analyzecommand no longer workswhen the package is installed as a vendor dependency via composer.
Root Cause
ESLint 9 introduced strict base path enforcement (flat config) - ESLint 9
sets its base path to the physical location of
eslint.config.mjs. Itrefuses to lint any files outside that folder.
Since
eslint.config.mjsphysically lives at:vendor/magento/magento-coding-standard/eslint/eslint.config.mjsAnd project files are at:
app/code/orapp/design/ESLint refuses to lint them because they are outside the base path.
What Worked
1. Running the binary directly from project root
Instead of
npm run eslint, run the binary directly fromsrc/:Running from
src/sets the working directory correctly so ESLint's basepath covers both
app/code/andapp/design/directories.2. Handling ignore paths
Since ESLint 9 also removed support for
.eslintignore, a wrappereslint.config.mjswas created at the project root (src/) to importthe magento config and add project specific ignore patterns:
This wrapper config at
src/level also allows running ESLint withoutthe
-cflag, since ESLint will automatically find and use it by searchingupward from the target files:
Suggested Fix
Update the README to document the correct usage for projects that install
this as a vendor dependency, including:
eslint.config.mjsat project root level for ignore patterns