-
Notifications
You must be signed in to change notification settings - Fork 4.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
WIP - Add an eslint rule for detecting package level side effects #14135
Conversation
f7c01c3
to
14753be
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.
Very interesting!! 🤯
|
||
// Function calls can introduce side effects when the return value is not used. | ||
window.addEventListener( 'resize', handleResize ); | ||
registerStore( store ); |
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.
This is the same example as above.
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.
Yep, was trying to illustrate that adding the file to the sideEffects property resolves the issue, but I need to make it clearer. Will rewrite.
It might be helpful to have this rule to catch which packages have side-effects but I don't expect this would be bullet-proof. I think we have maybe a handful of packages which don't have side-effects and they are very low-level like:
and maybe a few more which I didn't explore in depth. For sure this PR contains a few false positives like |
@gziolo Thanks for taking a look. Do you have an example of where I'm looking for other patterns that could be added to this rule, but as you say it'd be hard to make anything bullet-proof. I think if a rule can help manage those side-effects it'd still be beneficial to making it a completely manual process, and should also help alert devs to the need to think about side effects. |
14753be
to
5c0045f
Compare
Sure, a related line for I might be wrong about |
…ly top-level function calls that are not part of an assignment
…les instead of condition within rule.
516a048
to
9eea50b
Compare
Closing this as it has lain dormant for some time and there's a bit more thought that needs to go into it. |
Do you still think, we should we at least pick some of the packages manually and apply this magic field to those which are all pure? |
Fixes #13910
Description
This checks for violations of the package.json
sideEffects
property. At the moment there are a couple of particular patterns it checks for:When it detects these patterns and the file has not been added to the package.json
sideEffects
property it warns the developer to do so.Other patterns that I've thought about:
Patterns that are hard to lint for:
function initializeModule() { window.addEventListener( // ... ); }
, it's hard to catch since I'd have to trace back to the callsite.How has this been tested?
Screenshots
Types of changes
Checklist: