Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby extend ESLint rules overwrites original ESLint

Tags:

eslint

gatsby

I am following the directions in the documentation https://www.gatsbyjs.org/docs/eslint/, and would like to overwite one of the rules, but not affect the others, what I did is create an .eslintrc.js file.

This is the content of the file

module.exports = {
  globals: {
    __PATH_PREFIX__: true,
  },
  extends: `react-app`,
  "rules": {
    'jsx-a11y/no-static-element-interactions': [
      'error',
      {
        handlers: [
          'onClick',
          'onMouseDown',
          'onMouseUp',
          'onKeyPress',
          'onKeyDown',
          'onKeyUp',
        ],
      },
    ],
  }
}

but the rest of the rules are now ignored, like it was not an extension

like image 646
user3808307 Avatar asked Sep 14 '25 02:09

user3808307


2 Answers

While the answer above is correct, it is a bit incomplete. The thing is eslint can be integrated both in builds and editors.

When you start using a custom .eslintrc.js you will lose the integration on build and output in the terminal based on those rule. That's because the built-in eslint-loader is disabled when you use a custom file. It actually says so on the documentation page but it is a bit unclear.

To get that back, you will need to integrate it in the webpack build. The easiest way is using the plugin mentioned on the doc page: gatsby-plugin-eslint.

I filed an issue to make custom integrations easier.

like image 138
Albert Skibinski Avatar answered Sep 15 '25 20:09

Albert Skibinski


From the Gatsby docs you linked to:

When you include a custom .eslintrc file, Gatsby gives you full control over the ESLint configuration. This means that it will override the built-in eslint-loader and you need to enable any and all rules yourself. One way to do this is to use the Community plugin gatsby-eslint-plugin. This also means that the default ESLint config Gatsby ships with will be entirely overwritten. If you would still like to take advantage of those rules, you’ll need to copy them to your local file.

So it looks like as soon as your create a .eslintrc.js file, you need to build your rules up from the bottom again. It overwrites, it doesn't extend.

like image 45
luc Avatar answered Sep 15 '25 21:09

luc