I'm getting ESLint warnings in a file that doesn't seem to exist when adding and configuring ESLint using https://www.gatsbyjs.org/packages/gatsby-plugin-eslint/ and https://www.npmjs.com/package/eslint-plugin-react-app.
warn ESLintError:
/Users/mrseanbaines/projects/gatsby-eslint/_this_is_virtual_fs_path_/$virtual/sync-requires.js
4:30 warning Unexpected mix of '&&' and '||' no-mixed-operators
4:43 warning Unexpected mix of '&&' and '||' no-mixed-operators

npx gatsby new gatsby-eslint
cd gatsby-eslint
yarn add -D gatsby-plugin-eslint eslint-loader eslint eslint-plugin-react-app
touch .eslintrc
Add the following to .eslintrc:
{
"extends": ["plugin:react-app/recommended"]
}
Add the plugin to gatsby-config.js:
plugins: [
+ `gatsby-plugin-eslint`,
...
yarn start
Minimal Reproduction: https://github.com/mrseanbaines/gatsby-eslint
No ESLint warnings for files that don't exist
ESLint warnings in file that doesn't exist
System:
OS: macOS 10.15.6
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.17.0 - ~/.nvm/versions/node/v12.17.0/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v12.17.0/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 84.0.4147.105
Firefox: 78.0.2
Safari: 13.1.2
npmPackages:
gatsby: ^2.24.26 => 2.24.26
gatsby-image: ^2.4.14 => 2.4.14
gatsby-plugin-eslint: ^2.0.8 => 2.0.8
gatsby-plugin-manifest: ^2.4.21 => 2.4.21
gatsby-plugin-offline: ^3.2.21 => 3.2.21
gatsby-plugin-react-helmet: ^3.3.10 => 3.3.10
gatsby-plugin-sharp: ^2.6.24 => 2.6.24
gatsby-source-filesystem: ^2.3.23 => 2.3.23
gatsby-transformer-sharp: ^2.5.12 => 2.5.12
I've got this too but in my case it is an existing project since last year and just upgraded outdated packages to the latest version. Here is my log:
ERROR #98123 WEBPACK
Generating development JavaScript bundle failed
/home/.../_this_is_virtual_fs_path_/$virtual/sync-requires.js
1:25 error 'react-hot-loader' should be listed in the project's dependencies. Run 'npm i -S react-hot-loader' to add it import/no-extraneous-dependencies
1:25 error Strings must use singlequote quotes
1:49 error Missing semicolon semi
4:23 error Expected parentheses around arrow function argument arrow-parens
4:30 warning Unexpected mix of '&&' and '||' no-mixed-operators
4:43 warning Unexpected mix of '&&' and '||' no-mixed-operators
4:47 error Missing semicolon semi
6:1 error More than 1 blank line not allowed no-multiple-empty-lines
8:3 error Strings must use singlequote quotes
8:66 error Do not import modules using an absolute path import/no-absolute-path
8:66 error Strings must use singlequote quotes
9:3 error Strings must use singlequote quotes
9:61 error Do not import modules using an absolute path import/no-absolute-path
9:61 error Strings must use singlequote quotes
10:3 error Strings must use singlequote
...
My workaround, for now, is to ignore that file in .eslintrc:
{
...,
ignorePatterns: ["sync-requires.js", "**/_this_is_virtual_fs_path_/**/*.js"]
}
Oof! This ecosystem is _wide_, it's so hard to predict and protect against all of these integrations.
Let's cc @sidharthachatterjee who has implemented the virtual requires stuff recently.
In the meantime @bluenex workaround seems helpful
Opened https://github.com/gatsbyjs/gatsby/pull/26356 to fix this the no-mixed-operators problem. Thank you very much @mrseanbaines for the reproduction showcasing the issue.
I do think that using "ignore" options is better overall (as the more custom eslint rules can still cause more warnings/errors as showcased by logs from @bluenex). Seeing that gatsby-plugin-eslint does set some default exclude ( https://github.com/mongkuen/gatsby-plugin-eslint/blob/master/src/gatsby-node.js ), I might either create pull request in the plugin ... or adjust the "virtual" file path to contain .cache which should restore behaviours before the switch to virtual modules
Fixed and published in [email protected] courtesy of @pieh
I'll reopen the issue, as the just published hot-fix handles one specific instance of it, but didn't fix it for all cases (second comment). So this need more involved follow up.
I opened https://github.com/gatsbyjs/gatsby/pull/26396 with more proper fix. While there are some comments that prevent me from merging it into stable it yet - I released canary version with that change (gatsby@virtual-modules-in-dot-cache) - if you could test it (while removing ignorePatterns additions in eslint config - I would be much more confident in this fix
Thanks @pieh - seems to be resolved now after upgrading to the latest version of gatsby (2.24.46) 馃挭
Most helpful comment
Opened https://github.com/gatsbyjs/gatsby/pull/26356 to fix this the
no-mixed-operatorsproblem. Thank you very much @mrseanbaines for the reproduction showcasing the issue.I do think that using "ignore" options is better overall (as the more custom eslint rules can still cause more warnings/errors as showcased by logs from @bluenex). Seeing that
gatsby-plugin-eslintdoes set some defaultexclude( https://github.com/mongkuen/gatsby-plugin-eslint/blob/master/src/gatsby-node.js ), I might either create pull request in the plugin ... or adjust the "virtual" file path to contain.cachewhich should restore behaviours before the switch to virtual modules