Skip to content

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

Closed
drywolf opened this issue Feb 11, 2016 · 8 comments
Closed

JSX + inline JS indentation bug #34

drywolf opened this issue Feb 11, 2016 · 8 comments

Comments

@drywolf
Copy link

drywolf commented Feb 11, 2016

The following is a piece of JSX code after formatting it with tsfmt:

····return (
········<div ref="menu" style={[Style.control, style_override]}>
················<ul ref="menu" style={[Style.ul, style_override]}>
····················{menu_items}
····················</ul>
············</div>
····);

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 😁

@myitcv
Copy link
Contributor

myitcv commented Feb 11, 2016

@drywolf - can you confirm which version of typescript-formatter you are using?

@drywolf
Copy link
Author

drywolf commented Feb 11, 2016

It's 1.2.0

@myitcv
Copy link
Contributor

myitcv commented Feb 11, 2016

Please try v2.0.0.

And to be really sure you have a 'clean' install of v2.0.0, first npm uninstall --save-dev typescript-formatter then npm install --save-dev [email protected]

For the history on why, please see #30

@drywolf
Copy link
Author

drywolf commented Feb 11, 2016

I updated to 2.0.0, but the formatting is still the same as from above.

@drywolf
Copy link
Author

drywolf commented Feb 11, 2016

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

····<div ref="menu" style={[Style.control, style_override]}>
····<ul ref="menu" style={[Style.ul, style_override]}>
··</ul>
············</div>

which turned into this after formatting...

····<div ref="menu" style={[Style.control, style_override]}>
····<ul ref="menu" style={[Style.ul, style_override]}>
······</ul>
······</div>

The behavior seems to be that every closing tag is indented one level deeper than its matching opening tag.

@drywolf
Copy link
Author

drywolf commented Feb 12, 2016

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 ?!

@myitcv
Copy link
Contributor

myitcv commented Feb 16, 2016

@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>
    );
}
$ tsc --version
Version 1.9.0-dev.20160216
$ tsfmt --version
2.0.0

@drywolf
Copy link
Author

drywolf commented Feb 16, 2016

@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 @next, the issue was gone.

Thanks for your help.

@drywolf drywolf closed this as completed Feb 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants