Skip to content
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

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Jan 7, 2021

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 using gatsby-plugin-eslint and using it. It likely might not work when eslint-loader is added to webpack differently (as in it will add second instance of eslint-loader), but given that gatsby-plugin-eslint looks like "go-to" approach, it might be fine to leave as is

[ch22490]

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 7, 2021
@pieh pieh added topic: hot reloading* and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jan 7, 2021
@pieh pieh force-pushed the fast-refresh/merge-eslint-rules-with-custom-ones branch from 5c4170d to 479af2c Compare January 7, 2021 16:11
@pieh pieh marked this pull request as ready for review January 10, 2021 10:58
Copy link
Contributor

@pvdz pvdz left a 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.

Comment on lines +39 to +41
if (existingOptions.baseConfig.extends) {
if (
Array.isArray(existingOptions.baseConfig.extends) &&
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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`)
Copy link
Contributor

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?

Copy link
Contributor Author

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 :(

Copy link
Contributor

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.

Copy link
Contributor Author

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 to eslint-loader (no includes)
  • loader has some resolved path (so either eslint-loader/index.js or eslint-loader/dist/cjs.js) - then I can do includes or regex matching those

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants