-
Notifications
You must be signed in to change notification settings - Fork 131
autofix for 'sort-styles' rule #222
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
autofix for 'sort-styles' rule #222
Conversation
tanhauhau
commented
Mar 13, 2019
- added autofix for 'sort-styles' rule.
According to the ESlint docs, we need to specify the
|
12bf72a
to
b5f116b
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.
Great job! This is very helpful. I have a couple of questions, though.
I'm curious about how comments would be treated. For instance, consider the following code:
const styles = StyleSheet.create({
container: {
margin: 20,
// Never EVER edit the next line!!!
alignItems: 'center',
}
})
If we end up flipping the margin
and alignItems
lines, but keeping the comment between them, the meaning of the comment would change, and that's not good. I suggest just ignoring cases like these, leaving it to the user to manually fix these cases.
Another thing is overlapping styles when mixing shorthand properties with their full-length ones. Example:
const styles = StyleSheet.create({
container: {
marginLeft: 20,
margin: 40,
}
})
If we sort the styles here, we would change the appearance of the container thing. I guess these cases should also be ignored. I guess some hard coding is needed to detect these cases?
lib/util/stylesheet.js
Outdated
node.expression.type === 'ArrayExpression' | ||
return ( | ||
node && | ||
Boolean( |
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 guess this is just a Prettier/ESLint formatting fix, but how about moving the Boolean
call up a level, like so:
return Boolean(
node &&
node.type === 'JSXExpressionContainer' &&
node.expression &&
node.expression.type === 'ArrayExpression'
)
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've reverted the formatting change, we probably should do this in another PR?
lib/util/stylesheet.js
Outdated
node.name && | ||
node.name.name && | ||
node.name.name.toLowerCase().includes('style') | ||
node.name && |
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.
Aren't these lines indented too far?
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.
reverted formatting changes
I can add some test case for this.. |
b5f116b
to
2006336
Compare
@draperunner these test cases should suffice for maintaining the comments? |
added test case for shorthands too |
The test cases for shorthand properties look good. Great job! Regarding comments, I think it's better to just not autofix a chunk if it contains comments. It's impossible to know what the comment means. Consider the case
If we just don't autofix this, but still report it as an error, the user will have to fix it manually. When we are not sure what the correct way to fix things is, it's better to ignore it than potentially break something. |
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 work!
Very nice! Sorry, I have been away for a bit, but I'll try to get out a release soonish! |
Any updates on this? |