-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby): add required eslint rules even if user has custom eslint config #28911
feat(gatsby): add required eslint rules even if user has custom eslint config #28911
Conversation
5c4170d
to
479af2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So complex. Wish this could be simplified.
if (existingOptions.baseConfig.extends) { | ||
if ( | ||
Array.isArray(existingOptions.baseConfig.extends) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if .extends
exists but is not an array then the eslintRequirePreset
part is silently dropped? Smells like a bit like a footgun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I thought extends
only accept arrays but it also accept just strings, so I will add handling for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added handling for single string case in f5ad45a + some tests for it
// and adjust it to add the rule or append new loader with required rule | ||
const rule = config.module.rules.find(rule => { | ||
if (typeof rule.loader === `string`) { | ||
return rule.loader.includes(`eslint-loader`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Includes? No risk of false positives here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I can keep includes('eslint-loader')
as "precheck" and if those are satisfied do a deeper check (i.e. read package.json of imported package and see if package actually is eslint-loader
), but no matter how I slice it - it will be hacky :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think filename based validation is fine here. But a substr check seems a little too much of a shortcut, that's all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, so do you have any advice on what would good to do here?
I can cover maybe few specific scenario:
loader
is defined by package name (not fully resolved) - so for this I would do strict comparison toeslint-loader
(no includes)loader
has some resolved path (so eithereslint-loader/index.js
oreslint-loader/dist/cjs.js
) - then I can do includes or regex matching those
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added hopefully more strict checks in f477549 which I don't particularly like (but neither I did includes('eslint-loader')
) as it's hacky no matter how I slice it
Description
Change building on #28689 (so targeting that branch and not
master
.This should ensure fast-refresh related rules are included even if user have custom config or disable set of builtin rules. Those required rules are warnings only so they will not block building webpack bundle.
Note - this was tested when adding local
.eslintrc
file in 2 variants: without usinggatsby-plugin-eslint
and using it. It likely might not work wheneslint-loader
is added to webpack differently (as in it will add second instance ofeslint-loader
), but given thatgatsby-plugin-eslint
looks like "go-to" approach, it might be fine to leave as is[ch22490]