-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
jsx-indent rule autofixer #830
Conversation
Can you explain more about why you can't autofix to tabs? |
Let's say we have "\t" and we want to replace "\t" with 4 spaces. In order to do so we have to run fixer.replace(). Unfortunately fixer.replace() won't let you increase number of characters. |
@eelyafi does that mean it's impossible to have a fixer for |
@ljharb, after additional debugging I found that replaceTextRange will let you replace text. The actual reason why it won't replace one type of spacing with another is in getNodeIndent function. |
Ping :) |
I'm very hesitant to merge an autofixer that doesn't fix all forms of the rule. If we can't support tabs, we shouldn't support spaces, and vice versa. |
In reality many existing autofixers are far away from perfection. This autofixer will cover most of the cases and won't break code. |
@@ -69,6 +69,30 @@ module.exports = { | |||
} | |||
} | |||
|
|||
var indentChar = indentType === 'space' ? ' ' : '\u0009'; |
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.
Can this just be '\t'
instead of the character code?
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.
sure
@@ -39,7 +39,7 @@ module.exports = { | |||
category: 'Stylistic Issues', | |||
recommended: false | |||
}, | |||
|
|||
fixable: 'whitespace', |
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.
can we add a comment here detailing what cases are not covered? Ideally we'd also add skipped/commented-out test cases for that future work.
Addressed the comments |
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.
LGTM pending a rebase
6cbc157
to
1db64d8
Compare
Rebased |
@ljharb is it good to merge ? |
@eelyafi I'm waiting for one of the other contributors to review it. |
It would be good to note the limitations of the autofixer in the documentation, and also open an issue to improve it. Otherwise LGTM. |
Due to limitations of the RuleFixer class there is no way to safely fix these two cases:
Even with these limitations the autofixer found to be very useful and was already used on Pinterest codebase.