Description
I have a VSCode workspace with multiple folders in it. One of them is my frontend, the others are a backend and other stuff. My eslint-plugin-svelte3
version is 3.1.2.
In the frontend, there is an ESLint config file which sets 'svelte3/ignore-styles': () => true
because otherwise I keep getting syntax errors inside my <style lang="scss">
tags.
The issue is, this only works sometimes. Reloading the VSCode window seems to "reroll the die", sometimes it requires several attempts to get it to work.
I was trying to debug it by adding some console log output to node_modules/eslint-plugin-svelte3/index.js
and I think I have an idea of what's happening. What's important for this explanation, I added ESLINT SVELTE3
at the top of the file, LINTER VERIFY CALLED
inside the monkey-patched version of Linter.prototype.verify
and IGNORE STYLES
inside the if (processor_options.ignore_styles)
block.
If VSCode first lints a file of my frontend and later a file of my backend, then it works and the ESLint log looks like this:
[Info - 11:29:10 AM] ESLint server is starting
[Info - 11:29:11 AM] ESLint server running in node v12.18.3
[Info - 11:29:11 AM] ESLint server is running.
[Info - 11:29:13 AM] ESLint library loaded from: /.../frontend/node_modules/eslint/lib/api.js
ESLINT SVELTE3
LINTER VERIFY CALLED
IGNORE STYLES
[Info - 11:29:36 AM] ESLint library loaded from: /.../server/node_modules/eslint/lib/api.js
[Info - 11:29:36 AM] No ESLint configuration found in /.../server/models.
If, however, VSCode first lints a file of my backend and later a file of my frontend, then it doesn't work and the ESLint log looks like this:
[Info - 11:38:01 AM] ESLint server is starting
[Info - 11:38:02 AM] ESLint server running in node v12.18.3
[Info - 11:38:02 AM] ESLint server is running.
[Info - 11:38:03 AM] ESLint library loaded from: /.../server/node_modules/eslint/lib/api.js
[Info - 11:38:03 AM] No ESLint configuration found in /.../server/models.
[Info - 11:38:15 AM] ESLint library loaded from: /.../frontend/node_modules/eslint/lib/api.js
ESLINT SVELTE3
Note how there isn't any LINTER VERIFY CALLED
in the log (and subsequently no IGNORE STYLES
either).
So, I assume what's happening is that in the second case, the Linter.prototype.verify
function is already called before your module is loaded and monkey-patches it and then it's never called again, and since that's the only point at which you load your config, the config is never loaded then. So you might have to rethink your approach of loading the configuration.
So, I assume what's happening is that the second instance (frontend) is just re-patching the eslint
module of my server folder because you just look for /eslint/lib/linter/linter.js
in the require cache and take the first one, ignoring the rest of the path.
Now that I know this, I also know that I can control this by making sure a file of my frontend is open and then reloading the window, waiting for ESLint to be ready and only then start opening backend files, but that's obviously just a workaround.