-
-
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
Autofix: jsx-indent
: Add support for tabs
#608
Conversation
'</App>', | ||
' );', | ||
'}' | ||
].join('\n'), |
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 would expect the output to be
function App() {
return (
<App>
<Foo />
</App>
);
}
Why is it not?
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 agree - let's not merge this without the fix for 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.
@ljharb a fix included in this PR or a fix elsewhere?
@CiGit had said this:
To have the output you (and I) expect, the way errors are computed should be changed. ie JSXElement's indentation compared to something like ROOT - 1line, not to its direct parent / opening tag.
IMO that's an other issue
If I understand correctly, this will require detection logic changes. I unfortunately don't have cycles to dig that deep into the internals at the moment. If anyone else does, feel free to continue--I don't need commit "credit" hehe
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'd rather leave the broken but correct test, and comment it out, than leave this incorrect test. Could we do that?
In this case, only the To have the output you (and I) expect, the way errors are computed should be changed. IMO that's an other issue |
@jayphelps @CiGit How can I help to merge this PR? |
Abandoning due to lack of response from maintainers. Edit: I didn't mean this in a "fuck you guys for not responding" way. I PR'd this in May and hadn't received a response from any of the maintainers; and I don't have cycles to revisit in-depth at the moment. There are crazy number of perfectly valid reasons someone didn't respond, I'm not judging. Don't read into more than that 💃 |
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.
Sorry for the delay. Looks like this needs a rebase, plus a test change.
@jayphelps I know of one -- I don't think #830 doesn't support tabs. That could be filed as a separate bug. (Currently it counts the number of characters in the indent and inserts spaces, I believe.) |
f4d0ad4
to
afc35c8
Compare
@mmiller42 oh! my PR takes a different approach that does support that. Instead of trying to insert or remove indention, it just always just replaces the indention entirely using I've rebased and updated my PR, uncommented the tests which weren't working in #830 but now are. Seems OK, but it's been a while since I've looked at this code so definitely have a critical eye. |
Note that I have not fixed the pre-existing issue of the previously mentioned odd output in the test: function App() {
return (
<App>
<Foo />
</App>
);
} Presumably, #830 just didn't catch that. |
afc35c8
to
224c5ba
Compare
* @returns {Function} function to be executed by the fixer | ||
* @private | ||
*/ | ||
function getFixerFunction(node, needed, gotten) { | ||
if (needed > gotten) { | ||
var spaces = indentChar.repeat(needed - gotten); |
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 previous code used String.prototype.repeat()
which is ES2015. I can switch back to using that instead of the join()
trick I used, if it's a safe to assume repeat is supported.
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.
Alternatively you can just bring in a dep like https://www.npmjs.com/package/string-repeat
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.
just let me know which way you'd like. to me it seems silly to bring in a lib since the join trick is short, simple, and I think fairly obvious what it does. 😏 aka left-pad
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.
In general, left-pad
in no way changes that more deps is better. left-pad
was only a problem for people that were already ignoring a decade of best practices and depending on third-party registries for their dependencies.
In this case, keeping your join trick is fine too.
224c5ba
to
4e577d2
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.
Thanks, this is a strict improvement on #830 and the added test cases are great!
I've got this one comment, plus potentially using a "repeat" package instead of the join trick, and then this should be good to go!
jsx-indent
: Add support for tabs
4e577d2
to
2b832cd
Compare
Done. |
lmk if there's anything else I missed 🎉 |
Merged, thanks! And sorry for the lack of responses. |
Is it released to npm? How can we use it? |
@sassanh yes, it's available in v6.5.0. You can use it with |
That was fast. Thanks. |
Everything seems correct except for the very last test.
The real output is:
But I would expect the output to be:
Anyone have any ideas what I'm doing wrong or if somehow this is indeed expected behavior?