-
Notifications
You must be signed in to change notification settings - Fork 53
JSX + inline JS indentation bug #34
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
Comments
@drywolf - can you confirm which version of |
It's 1.2.0 |
Please try And to be really sure you have a 'clean' install of For the history on why, please see #30 |
I updated to 2.0.0, but the formatting is still the same as from above. |
I did some more tests and I think the formatting issue is not related to the inlined JavaScript but just with the JSX indentation in general. For example I tried to create an artificially wrong format like this...
which turned into this after formatting...
The behavior seems to be that every closing tag is indented one level deeper than its matching opening tag. |
Also every JSX opening tag that is not at the root level of the file will never change its indentation, as well as any javascript code that is wrapped in those tags. I had a look at the TypeScript code that does the formatting and it looks like JSX formatting is not really implemented by the typescript formatting service at all ?! |
@drywolf I just tried the code you supplied in your original post: // test.tsx
export function TestFormat(): JSX.Element {
return (
<div ref="menu" style={[Style.control, style_override]}>
<ul ref="menu" style={[Style.ul, style_override]}>
{menu_items}
</ul>
</div>
);
}
|
@myitcv Thanks for testing. After debugging the issue, I figured out that when I ran tsfmt from my IDE + npm scripts, it was using an older version (1.7.5) of TypeScript in the project's node_modules folder, rather than the globally installed TypeScript version. Once I updated the TypeScript version in the node_modules of the project to Thanks for your help. |
The following is a piece of JSX code after formatting it with tsfmt:
I replaced the spaces with dots so it is more clear what the result of the formatting is.
It looks like after some JS-code node that is inlined in the JSX, the formatter does not recognize that it should unindent at this point. After that, every following line will have one indent that is too much from what should be there.
PS: thanks for this awesome tool 😁
The text was updated successfully, but these errors were encountered: