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

Lint only the imported files #28

Merged
merged 6 commits into from
Nov 4, 2020
Merged

Lint only the imported files #28

merged 6 commits into from
Nov 4, 2020

Conversation

jsg2021
Copy link
Contributor

@jsg2021 jsg2021 commented Oct 18, 2020

This is attempting to implement ideas in #23

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Allow the linter to run on only files imported into the module graph. Ignoring any other files.

Breaking Changes

None so far. However, this change will likely make the existing paradigm redundant.

Additional Info

I'm just opening this to get started on it. It's not done. Looking at the original implementation, this feature feels like a mental shift and may make sense to remove the existing "what to lint" logic to further simplify the configuration. idk, thoughts?

@jsg2021 jsg2021 changed the title WIP: Lint only the imported files, re: #23 WIP: Lint only the imported files Oct 18, 2020
@codecov
Copy link

codecov bot commented Oct 18, 2020

Codecov Report

Merging #28 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #28   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         7    -1     
  Lines          159       168    +9     
  Branches        39        41    +2     
=========================================
+ Hits           159       168    +9     
Impacted Files Coverage Δ
src/ESLintError.js 100.00% <ø> (ø)
src/options.js 100.00% <ø> (ø)
src/index.js 100.00% <100.00%> (ø)
src/linter.js 100.00% <100.00%> (ø)
src/utils.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c5aa19...1c7fcfc. Read the comment docs.

@jsg2021
Copy link
Contributor Author

jsg2021 commented Oct 18, 2020

I went ahead and just refactored this to run on the import graph. So, not running on all files in the project/context could be considered a breaking change.

@jsg2021 jsg2021 changed the title WIP: Lint only the imported files Lint only the imported files Oct 18, 2020
@ricardogobbosouza
Copy link
Collaborator

Hi @jsg2021
It looks incredible! This improves performance dramatically and I believe it solves #30

@ricardogobbosouza
Copy link
Collaborator

/cc @evilebottnawi

src/linter.js Outdated Show resolved Hide resolved
src/linter.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/linter.js Outdated Show resolved Hide resolved
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Reviewed, need some improvements

@jsg2021

This comment has been minimized.

package.json Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
// From my testing of compiler.watch() ... compiler.watching is always
// undefined (webpack 4 doesn't define it either) I'm leaving it out
// for now.
compiler.hooks.watchRun.tapPromise(ESLINT_PLUGIN, this.run);
Copy link
Member

Choose a reason for hiding this comment

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

/cc @ricardogobbosouza What do you think about improving it for auto detecting watch only on webpack@5?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@evilebottnawi Sorry, but I didn't understand your question lol

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Looks good, hope we don't break nothing

@ricardogobbosouza
Copy link
Collaborator

I'm going to do some tests on webpack 4 and 5

@alexander-akait
Copy link
Member

@ricardogobbosouza Feel free to ping me

@ricardogobbosouza
Copy link
Collaborator

ricardogobbosouza commented Oct 28, 2020

Hi @jsg2021
Both in webpack4 and webpack5 the logs duplicate with each change I make

Captura de Tela 2020-10-28 às 10 06 04

@jsg2021
Copy link
Contributor Author

jsg2021 commented Oct 28, 2020

@ricardogobbosouza huh, I didn't expect the that. I've added a test to reproduce it and fixed it.

This was caused because I assumed each run call from run/watchRun woud have fresh compiler.hooks.thisCompilation.taps... just like compilation.hooks.*... so each run added the tap again.

@jsg2021
Copy link
Contributor Author

jsg2021 commented Oct 28, 2020

Is there a tap option to remove after called? or a way to remove a tap? My current solution is okay, but idk, feels dirty.

@alexander-akait
Copy link
Member

alexander-akait commented Oct 29, 2020

Is there a tap option to remove after called? or a way to remove a tap? My current solution is okay, but idk, feels dirty.

yes should avoid it, it reduces performance

@jsg2021
Copy link
Contributor Author

jsg2021 commented Oct 29, 2020

Is there a tap option to remove after called? or a way to remove a tap? My current solution is okay, but idk, feels dirty.

yes should avoid it, it reduces performance

Is that true for once per-run? If I were to use it, I would only use it at the top so that each top-level run only had one use of this plugin. My current solution has the same effect. Its just a bit hacky in my opinion.

@ricardogobbosouza
Copy link
Collaborator

ricardogobbosouza commented Oct 30, 2020

@jsg2021 Apparently now works as expected 😄

@evilebottnawi I wonder if we have to have an option to linter all files and not just imported ones 🤔
On smaller projects it can be useful, WDYT?

@jsg2021
Copy link
Contributor Author

jsg2021 commented Oct 30, 2020

@evilebottnawi I wonder if we have to have an option to linter all files and not just imported ones 🤔

On smaller projects it can be useful, WDYT?

In my opinion, that's beyond the scope of webpack. Files not touched by the import graph shouldn't touched. If the user wants to lint the entire project then the linter itself can do that as a separate task.

@alexander-akait
Copy link
Member

@ricardogobbosouza

@evilebottnawi I wonder if we have to have an option to linter all files and not just imported ones thinking
On smaller projects it can be useful, WDYT?

Ideally yes, but it is edge case

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Let's try

@naulacambra
Copy link

Why is this merge blocked?
This new plugin really slowed my workflow, and this improvement is more than desired

@ricardogobbosouza
Copy link
Collaborator

Hi @naulacambra
This is not blocked, as it is a significant change I am doing more tests, I must launch today

@ricardogobbosouza ricardogobbosouza merged commit 47612f1 into webpack-contrib:master Nov 4, 2020
@jsg2021 jsg2021 deleted the graph branch November 4, 2020 17:22
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.

4 participants