I had to do a little RTFMing today, and so I thought I'd post about it.
First of all, this is how you set up PhpStorm to use ES6 eslint settings. You may find it useful
Is the linter getting in your way? The first way to override an eslint setting is inline, disabling it on a one-off basis.
If you truly need a new .eslintrc.json
file, then you should probably extend the one from Drupal core.
Here's how the linter looks for eslint files. TL;DR: like .gitignore
files.
Finally, here's how the extends
property of eslintrc.json
. Basically, you point it to a file. Properties you specify in your file will not clobber the branch object that was previously specified, only leaves. Or at least that's what seems to happen and seems to be documented. I.e., in the below, defining rules: {import/no-extraneous-dependencies: error}
doesn't overwrite the rules
object entirely.
Here's what I ended up with at themes/custom/mytheme/.eslintrc.json
:
{ "extends": "../../../core/.eslintrc.json", "rules": { // We aren't using a package.json file for imports, so turn this off. "import/no-extraneous-dependencies": { "error": { "devDependencies": false, "optionalDependencies": false, "peerDependencies": false } }, // We want to specify .js and .jsx file extensions. "import/extensions": ["error", "always", { "js": "always", "jsx": "always" }], // Warn, don't error, for unresolved import paths. "import/no-unresolved": "warn" } } }
And here's a list of all the rules you can override. You may want to check out the actual eslint-config-airbnb
to see the values they're using. I have just been searching the codebase at /core/node_modules
for the specific eslint rule after running npm install
from the /core
directory to get all the nodejs dependencies (including, of course, eslint-config-airbnb
).
- Disabling linting inline: https://eslint.org/docs/user-guide/configuring.html#configuring-rules
- How eslint looks for config files: https://eslint.org/docs/user-guide/configuring#configuration-cascading-a...
- Extends property of
eslintrc.json
: https://eslint.org/docs/user-guide/configuring#extending-configuration-f... - Eslint rules: https://eslint.org/docs/rules/