-
Notifications
You must be signed in to change notification settings - Fork 213
Reducing the potential for confusion if configuring ESLint outside of Neutrino #382
Comments
It's hard to take sides since I just can't see any reason to write eslintrc files. Even in a migration scenario, it would be just as easy to incorporate the eslintrc as it is to enable eslintrc. So, I'm in favor of failing hard in case |
We can change nothing in existing core modules and add a new preset just for purposes when you need to use Preview: neutrino.use(require('neutrino-middleware-eslint'))
neutrino.config.module.rule('lint').use('eslint').options({ useEslintrc: true }) |
I don't think that would work - several of the other options are needed when using CLIEngine, since they can't be set via an RC file. |
@constgen, I guess the question to ask is: what is your use-case for using a separate .eslintrc rather than setting the config via neutrino? |
No problem. We can leave some of them. Use caseYou really don't have a ready Neutrino preset with rules for your project. Libraries may use quite different rules. NodeJS too. I understand if we are not going to make it a part of the Core. We can put it on community shoulders. I am ready to support such preset. |
To clarify slightly - this isn't about Neutrino just not wanting to support the standard that is .eslintrc. It's that it's very hard (if not impossible) to come up with a way of making ESLint configuration consistent, unless everything is run through Neutrino. As mentioned in the "Background" section of the OP above, the way ESLint is invoked is different between each of |
If it's just that you'd like to have the ESLint rules in a different file, then have you tried requiring such a file in your |
I thought about this but didn't do for a reason. I have to duplicate the logic of config searching from ESLint |
Been gathering my thoughts, here goes: I think if you are using eslint middleware, you should configure via That's a divergence from the stance we have taken with supporting eslintrc so far, but I think it's the best to maintain going forward. You can continue to use eslintrc.js for editor hints, etc., but modifying linting from there just isn't sustainable. If you want to use the eslintrc file, you probably shouldn't be using the eslint middleware. You can configure linting yourself in this case. That said, I still don't know if we should be forcing people away from eslintrc, so I think adding a visible, clear warning in the console may be the right thing to do. It should also mention that changing ESLint configuration outside of neutrinorc is not supported. Thoughts? |
Yeah I agree, though can't decide warning vs blocking |
In trying to implement this, I think we are kinda stuck. The changes we made to the API to load middleware outside the I think we are going to have to relegate this to documentation. |
The biggest problem here IMO was when people use "alternative A" from the OP. Unlike "B", this can be detected via the API, and prevented (or warned about) rather than being docs-only, should we wish :-) ie:
@eliperelman, do any of those sound appealing? |
(Happy to close again if we think the docs addition is fine, but reopened so this doesn't get lost) |
Ohhhhhhh, now I see! 👀 This is my preference:
Let's do both! |
I want to raise this discussion again. Since we now encourage the use of |
Yeah now that we're using ESLint's CLI for However to fully support it, we need to stop setting our own options when In addition whilst looking into this, I see that there are a few issues with the way that
Changing the |
* Adds option validation to `@neutrinojs/eslint`, so that it now throws when passed options that are not supported by eslint-loader. * The eslintrc conversion now correctly handles all supported options under `baseConfig` rather than silently ignoring some of them. * The eslintrc conversion no longer looks for settings in locations that are invalid for eslint-loader (such as top-level `settings`, `extends`, `root` or `overrides` options). * The eslintrc conversion now no longer errors if passed options that were previously missing from the `omit()` list, such as `ignore` and `reportUnusedDisableDirectives`. * The custom lint `merge()` function has been replaced with ESLint's own merging function, which correctly handles several cases that were broken before. * All non-loader related configuration has now been moved under the `baseConfig` key, since the options under it more closely relate to the options that users will have previously seen in `.eslintrc` files, thereby reducing user-confusion and making it possible to copy and paste the contents of the `baseConfig` section to a static `.eslintrc.*`. * Support has been added for projects that want to use their own non-generated `.eslintrc.*` file. They now only need to set `useEslintrc` to `true`, which will make the linting presets only set the loader-related options, preventing conflicts with the options set in their static `.eslintrc.*` file. * The `@neutrinojs/loader-merge` middleware has been removed, since its functionality was not sufficient for merging lint configuration correctly, and was not used for any other purpose. Fixes #1181. Fixes #382.
Summary
As seen in #380, users sometimes don't follow the docs recommendations, and store eslint configuration outside of Neutrino. As part of this, they may also override
neutrino-middleware-eslint
's default ofuseEslintrc: false
, which can cause a few problems.Background
For linting, the Neutrino docs recommended:
.neutrinorc.js
(or middleware called from there).neutrino lint
over calling eslint manually..eslintrc.js
which does nothing more than call the Neutrino API to generate a config that's equivalent to the one used byneutrino lint
.There are then three ways linting is used:
neutrino lint
commandneutrino {build,start,...}
commands.eslintrc*
files (of which there are several supported formats/filenames: docs)..eslintrc.js
and it's set up as recommended by the Neutrino docs, it exports a mostly equivalent config (with some keys filtered out, since the RC format differs slightly from that accepted byCLIEngine
).Alternative approaches users might take
For users that don't follow the approach recommended by the docs, I can think of a few possible variations they might use:
(A) Using an alternate ESLint RC file and
useEslintrc: true
:For example (from #380)...
The problem with this approach is that:
.eslintrc
to match exactly the generated config).eslintrc
to match the generated config, since (a) there are a lot of options already set inneutrino-middleware-eslint
(plus other middleware), and (b) the generated config takes precedence rather than vice versa (I've filed Documenting configuration hierarchy for CLIEngine options and 'useEslintrc: true' eslint/eslint#9526 for clarifying this in the ESLint docs).ie: One ends up in a confusing situation where neither the
.eslintrc
nor the Neutrino configuration is the source of truth.(B) Using an
.eslintrc.js
that calls the Neutrino API, but defines rules outside of.neutrinorc.js
:For example:
This is actually suggested in the docs as an alternative, however this approach will cause differences in what's reported between the eslint CLI/editors and the neutrino commands. Is this really a use-case that should be mentioned in the docs? (Or even supported at all?)
I guess perhaps some users might want to disable or enable certain rules in their editor only? (eg make the editor warn about things that shouldn't yet fail the build, since a project is slowly trying to fix old cases before enabling the rule for real)
Worth noting, is that if the user takes this approach and also sets
useEslintrc: true
in their.neutrinorc.js
, then the Neutrino eslint config will get generated twice. Perhaps Neutrino should fail hard in getEslintRcConfig() if that's the case?Proposal
IMO we should do one of:
useEslintrc: true
entirely (what are the use-cases for using the JSON format.eslintrc
instead of Neutrino generated config?)useEslintrc: true
, butneutrino-middleware-eslint
should then not setparserOptions
itself (ie the middleware does only the bare minimum, leaving the user to manually configure everything else in.eslintrc
, so at least the RC file then ends up being much closer to the source of truth)useEslintrc: true
, but output a warning about the problems / emphasise the problems in the docs and source commentsNote: If we don't forbid
useEslintrc: true
, then we should still make getEslintRcConfig() (used by the.eslintrc.js
API call only) fail hard if it's set, since as mentioned in (B) this case results in double configuration and is clearly not what the user would want.Thoughts?
The text was updated successfully, but these errors were encountered: