Skip to content
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

Merged
merged 1 commit into from
Nov 1, 2016

Conversation

jayphelps
Copy link
Contributor

@jayphelps jayphelps commented May 20, 2016

Everything seems correct except for the very last test.

The real output is:

function App() {
  return (
    <App>
  <Foo />
</App>
  );
}

But I would expect the output to be:

function App() {
  return (
    <App>
        <Foo />
    </App>
  );
}

Anyone have any ideas what I'm doing wrong or if somehow this is indeed expected behavior?

'</App>',
' );',
'}'
].join('\n'),
Copy link
Contributor Author

@jayphelps jayphelps May 20, 2016

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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?

@coveralls
Copy link

coveralls commented May 20, 2016

Coverage Status

Coverage increased (+0.002%) to 96.771% when pulling f4d0ad4 on jayphelps:jsx-indent-fix into 82b3aa9 on yannickcr:master.

@CiGit
Copy link

CiGit commented May 26, 2016

In this case, only the <App> tag is an error so the fix function only applies to it.

Test case

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

@zouxuoz
Copy link

zouxuoz commented Oct 11, 2016

@jayphelps @CiGit How can I help to merge this PR?

@jayphelps
Copy link
Contributor Author

jayphelps commented Oct 27, 2016

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 💃

@jayphelps jayphelps closed this Oct 27, 2016
@ljharb ljharb reopened this Oct 27, 2016
Copy link
Member

@ljharb ljharb left a 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
Copy link
Contributor Author

@ljharb oooo when I tried to rebase, I discovered it appears this has already been added in #830. Our two implementation seem mutually exclusive. Do you know if there is something this fixes that #830 did not?

@mmiller42
Copy link

@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.)

@jayphelps
Copy link
Contributor Author

@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 fixer.replaceTextRange.

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.

@jayphelps
Copy link
Contributor Author

jayphelps commented Oct 27, 2016

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.

* @returns {Function} function to be executed by the fixer
* @private
*/
function getFixerFunction(node, needed, gotten) {
if (needed > gotten) {
var spaces = indentChar.repeat(needed - gotten);
Copy link
Contributor Author

@jayphelps jayphelps Oct 27, 2016

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.

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

@ljharb ljharb left a 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!

@ljharb ljharb changed the title [WIP] Add auto fix for jsx-indent Autofix: jsx-indent: Add support for tabs Oct 27, 2016
@jayphelps
Copy link
Contributor Author

I'd rather leave the broken but correct test, and comment it out, than leave this incorrect test. Could we do that?

Done.

@jayphelps
Copy link
Contributor Author

lmk if there's anything else I missed 🎉

@yannickcr yannickcr merged commit 56f1777 into jsx-eslint:master Nov 1, 2016
@yannickcr
Copy link
Member

Merged, thanks! And sorry for the lack of responses.

@sassanh
Copy link

sassanh commented Nov 1, 2016

Is it released to npm? How can we use it?

@yannickcr
Copy link
Member

@sassanh yes, it's available in v6.5.0. You can use it with eslint --fix file.js (see ESLint documentation).

@sassanh
Copy link

sassanh commented Nov 2, 2016

That was fast. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

8 participants