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: prevent lint all files #77

Merged
merged 2 commits into from
Feb 12, 2021
Merged

fix: prevent lint all files #77

merged 2 commits into from
Feb 12, 2021

Conversation

ricardogobbosouza
Copy link
Collaborator

@ricardogobbosouza ricardogobbosouza commented Feb 5, 2021

This PR contains a:

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

Motivation / Use-Case

The goal is to group the changed files and execute lint only at the end

succeedModule its called for every file and watch mode just file changed
finishModules is called with all modules and is responsible for linting added files

Resolve #75

Breaking Changes

Additional Info

@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #77 (a0826cf) into master (be0391e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #77   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          251       251           
  Branches        71        71           
=========================================
  Hits           251       251           
Impacted Files Coverage Δ
src/index.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 be0391e...a0826cf. Read the comment docs.

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.

I think we need to look at better hook and logic here, but right now is good solution, let's return to this in future

Will be great to add test using mock

@watjurk
Copy link

watjurk commented Feb 5, 2021

I think that unfortunately this fix won't work after merging fix-cache-result-storage because files that aren't changed won't be linted:
-index.js (imports lintError.js)
-lintError.js

webpack reports errors from lintError.js
now let's change index js (still imports lintError.js)
webpack doesn't report errors from lintError.js because succeedModule in watch mode (after first run) is called only for changed files

I would suggest not merging this PR and creating global cache in linter.js and invalidating it with compiler.modifiedFiles and compiler.removedFiles.
Example implementation: https://github.com/watjurk/eslint-webpack-plugin/tree/fix-cache-result-storage

@ricardogobbosouza
Copy link
Collaborator Author

This will only be possible in v3 because compiler.modifiedFiles does not exist in webpack 4

@ricardogobbosouza
Copy link
Collaborator Author

In v3 version support for webpack 4 will be removed

@watjurk
Copy link

watjurk commented Feb 5, 2021

when v3 will be available, as beta or next ?

@watjurk
Copy link

watjurk commented Feb 5, 2021

I've learned about compiler.hooks.invalid, I think this is the solution here. I updated my implementation accordingly.

@ricardogobbosouza
Copy link
Collaborator Author

ricardogobbosouza commented Feb 5, 2021

@watjurk It looks good to me 😄

@watjurk
Copy link

watjurk commented Feb 5, 2021

Should I create PR to this repo ?

@ricardogobbosouza
Copy link
Collaborator Author

Do you want to create a pr or do you prefer me to do it?

@watjurk
Copy link

watjurk commented Feb 5, 2021

I think I prefer you to do this, maybe some day...

@wendyzhaogogo
Copy link

compiler.hooks.invalid

why compiler.hooks.invalid is ok? i find it's fs.watcher.once('change')

@watjurk
Copy link

watjurk commented Feb 6, 2021

Sorry but I don't understand your point, could you explain ?

@wendyzhaogogo
Copy link

I've learned about compiler.hooks.invalid, I think this is the solution here. I updated my implementation accordingly.

I just don't known the reason, why compiler.hooks.invalid is the solution.
Will invalid be triggered when any file be deleted?

@ricardogobbosouza
Copy link
Collaborator Author

According to the documentation, the invalid hook is called to the changed or removed file
https://webpack.js.org/api/compiler-hooks/#invalid

@wendyzhaogogo
Copy link

wendyzhaogogo commented Feb 6, 2021

According to the documentation, the invalid hook is called to the changed or removed file
https://webpack.js.org/api/compiler-hooks/#invalid
https://github.com/webpack/webpack/blob/fd056e27f477e364c16d1b09b39905fce28c13ca/lib/Watching.js#L252
image
image
but the source code of webpack v4 confused me

@watjurk
Copy link

watjurk commented Feb 6, 2021

Search for _done method in the Watching.js, and you will find:

process.nextTick(() => {
  if (!this.closed) {
    this.watch(
      compilation.fileDependencies,
      compilation.contextDependencies,
      compilation.missingDependencies
    );
  }
});

as you see this.watch is called every time webpack is done compiling, and this is why this.watcher.once i really "not once".

@wendyzhaogogo
Copy link

Search for _done method in the Watching.js, and you will find:

process.nextTick(() => {
  if (!this.closed) {
    this.watch(
      compilation.fileDependencies,
      compilation.contextDependencies,
      compilation.missingDependencies
    );
  }
});

as you see this.watch is called every time webpack is done compiling, and this is why this.watcher.once i really "not once".

Thank you ,so the name of this hook called 'invalid' is not strict ,is it ?

@watjurk
Copy link

watjurk commented Feb 6, 2021

What do you mean by saying it's not strict ? It's just called 'invalid' because it's called every time compilation is invalidated (something change), this is how I think about it.

@wendyzhaogogo
Copy link

What do you mean by saying it's not strict ? It's just called 'invalid' because it's called every time compilation is invalidated (something change), this is how I think about it.

yes , you are right.that's it, I have to learn webpack in detail.

@ricardogobbosouza
Copy link
Collaborator Author

This PR temporarily solves the performance problem ...
Waiting #79

@ricardogobbosouza ricardogobbosouza merged commit f57cb8e into master Feb 12, 2021
@ricardogobbosouza ricardogobbosouza deleted the fix-lint branch February 12, 2021 21:09
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.

All modules are linted in watch mode after changing only a single file
4 participants