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

fix(gatsby): use separate eslint-loader for rules that are always required #29317

Merged
merged 2 commits into from
Feb 3, 2021

Conversation

vladar
Copy link
Contributor

@vladar vladar commented Feb 3, 2021

Description

Fast-refresh as a hot-reloading mechanism has several constraints. And we need to enforce those constraints using eslint and custom eslint rules. Originally we've implemented this in #28911. And the idea was to merge those rules into a custom user eslint config.

This has caused several issues. This PR suggests a different approach by introducing a separate eslint-loader for fast-refresh rules that is completely isolated from the user custom eslint setup.

This loader is only added when there is a custom .eslintrc`. For default Gatsby eslint config we still have a single loader (and just add fast-refresh rules to it).

Documentation

https://www.gatsbyjs.com/docs/how-to/custom-configuration/eslint/

(this PR warrants updating those docs a bit)

Related Issues

An alternative approach to #28911

Fixes #29105
Fixes #29133

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 3, 2021
@vladar vladar removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 3, 2021
@vladar vladar closed this Feb 3, 2021
@vladar vladar reopened this Feb 3, 2021
Comment on lines +350 to +355
if (
isCustomEslint &&
process.env.GATSBY_HOT_LOADER === `fast-refresh`
) {
configRules = configRules.concat([rules.eslintRequired()])
}
Copy link
Contributor Author

@vladar vladar Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the main piece. We add another minimal loader only when there is user-defined eslint config. When there is no custom config - we still use a single default Gatsby loader (with fast-refresh rules added to it)

@vladar vladar marked this pull request as ready for review February 3, 2021 12:34
@pieh pieh self-assigned this Feb 3, 2021
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried testing as much combinations from reports as possible - with gatsby-plugin-eslint - both v2 (that use eslint-loader) and v3 (that use eslint-webpack-plugin) and without

using optional chaining (for old parser), using eslint-disable with "not existing rules" and from what I can tell I had expected results, so let's merge this - at very least this will fix known issues.

Huge thanks!

@pieh pieh merged commit a1543bf into master Feb 3, 2021
@pieh pieh deleted the vladar/gh-29133 branch February 3, 2021 20:29
vladar added a commit that referenced this pull request Feb 4, 2021
…uired (#29317)

* fix(gatsby): use separate eslint-loader for rules that are always required

* Add the second loader only when custom eslint config is set

(cherry picked from commit a1543bf)
vladar added a commit that referenced this pull request Feb 4, 2021
…uired (#29317) (#29327)

* fix(gatsby): use separate eslint-loader for rules that are always required

* Add the second loader only when custom eslint config is set

(cherry picked from commit a1543bf)

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
@vladar
Copy link
Contributor Author

vladar commented Feb 4, 2021

Published in gatsby@2.32.1

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