-
Notifications
You must be signed in to change notification settings - Fork 309
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: add no-unused eslint rule to find unused styles #767
Conversation
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
apps/docs/.eslintrc.js
Outdated
@@ -13,6 +13,7 @@ module.exports = { | |||
// The Eslint rule still needs work, but you can | |||
// enable it to test things out. | |||
'@stylexjs/valid-styles': 'error', | |||
// '@stylexjs/no-unused' : 'warn', |
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.
you can leave this enabled.
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.
[update] after uncommenting, I notice the eslint error Definition for rule '@stylexjs/no-unused' was not found.
starting appearing again, but I am certain it was working before as I was able to test the rule&auto-fix inside the docs folder. I attempted to rebuild multiple times but currently still doesn't work...
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.
Great start so far!
Left a bunch of comments to complete the PR.
// of the file so we can look directly on Program and populate our set. | ||
node.body | ||
.filter(({ type }) => type === 'VariableDeclaration') | ||
.map(({ declarations }) => |
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.
You should also look for any top level consts so you can resolve objects passed into stylex.create
that uses a local const.
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.
I don't think I understand you completely, do you mean something like:
const field = {
backgroundColor: 'white',
};
const styles = stylex.create({
main: {
height: 4,
},
field,
});
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.
Yes. Something like that.
Or even the entire object that's passed into stylex.create
.
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.
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.
Yeah, we need to fix that rule too. We can punt on this for now.
a82cdf8
to
3f8ccdc
Compare
3f8ccdc
to
02612f8
Compare
…; added features: non-default export, used style as return, full import pattern support
02612f8
to
ea6aef4
Compare
@@ -13,6 +13,7 @@ module.exports = { | |||
// The Eslint rule still needs work, but you can | |||
// enable it to test things out. | |||
'@stylexjs/valid-styles': 'error', | |||
// '@stylexjs/no-unused': 'warn', |
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.
do we want to use warn
or error
here?
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.
If we follow the behavior in internal codebase, then this should be error; i agree we should change it to error(will update this after figuring out the definition not found error, @nmn is helping investigating this)
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.
I will enable this after this PR lands. There are some issues with dependencies where this doesn't always work consistently.
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 looks almost good enough to land. It needs one tiny change. I'll see if I can patch that and merge it if you can't update it in time.
What changed / motivation ?
Addresses task ESLint: find unused styles #702.
Identify all styles that 1) not used; 2) not exported. The feature also allow auto fix by removing fields that are unused.
Linked PR/Issues
fixes #702.
Additional Context
Created sets of tests in stylex-no-unused-test.js, all 5 tests passed; also conducted manual testing in
apps/docs/
folder.Pre-flight checklist
Contribution Guidelines