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

Breaking up HTML tags in JSX upon save #452

Closed
CosmonautJones opened this issue May 10, 2018 · 28 comments
Closed

Breaking up HTML tags in JSX upon save #452

CosmonautJones opened this issue May 10, 2018 · 28 comments
Labels
locked Please open a new issue and fill out the template instead of commenting.

Comments

@CosmonautJones
Copy link

CosmonautJones commented May 10, 2018

Hey guys, I've been using prettier for about 6 months now and never had an issue. but I recently updated VSCode and I ran into this problem today with it breaking out my HTML tags in my JSX and spacing it all wildly.
Example follows:
Before save:

return (
    <div className="input-group mb-3">
      <div className="input-group-prepend">
        <span className="input-group-text">
          <i className={icon} />
        </span>
    </div>
    <input
      className={classnames("form-control form-control-lg", {
        "is-invalid": error
      })}
      placeholder={placeholder}
      name={name}
      value={value}
      onChange={onChange}
    />
      {error && <div className="invalid-feedback">{error}</div>}
    </div>
  );
}; 

After save

return ( <
      div className = "input-group mb-3" >
      <
      div className = "input-group-prepend" >
      <
      span className = "input-group-text" >
      <
      i className = {
        icon
      }
      /> <
      /span> <
      /div> <
      input className = {
        classnames("form-control form-control-lg", {
          "is-invalid": error
        })
      }
      placeholder = {
        placeholder
      }
      name = {
        name
      }
      value = {
        value
      }
      onChange = {
        onChange
      }
      /> {
        error && < div className = "invalid-feedback" > {
            error
          } < /div>} <
          /div>
      );
    }; 

I can provide additional info if needed. Such as my settings, etc.

UPDATE 6/4/18: Resolved by disabling Beautify, which was causing issues with Prettier.

@CosmonautJones
Copy link
Author

Images just for completeness sake
beforesave
aftersave

@sonbuiGFD
Copy link

I have the same issue after update VScode today.

@jtbandes
Copy link

jtbandes commented May 10, 2018

I'm having a similar problem but sometimes it seems to format the document correctly. If I Format Document repeatedly, it seems to alternate between correctly and incorrectly formatted, as if it's sometimes using prettier + its config from my repo, and sometimes using a different formatter or prettier with the wrong configuration. Adding "javascript.format.enable": false in my settings doesn't help...

@jtbandes
Copy link

I narrowed this down to the clang-format extension. Adding this to my settings fixes the problem:

    "clang-format.language.javascript.enable": false

@Greenie10
Copy link

I was experiencing the same problem, even though I didn't have the clang-format extension installed. Installed it, and added the false setting suggested by @jtbandes above, and all is now well. Seems a bit mad though.

@jtbandes
Copy link

I'm not sure but I just updated to 1.23.1 and I think the issue has gone away.

@nielskrijger
Copy link

nielskrijger commented May 12, 2018

Having had the same issue yesterday, it does appears to work better with 1.23.1.

One issue remains though;

import objectMapper, { getKeyValue } from 'object-mapper';

is transformed into:

import objectMapper, {
  getKeyValue
} from 'object-mapper';

Where before it would keep the oneliner. Enabling/disabling prettier and reloading the editor fixed it for me (not sure if it lasts yet though [edit]no, it is back again[/edit])

@jlibman
Copy link

jlibman commented May 13, 2018

Updating to 1.23.1 did not work for me.

@jtbandes
Copy link

jtbandes commented May 13, 2018

Yeah, I think I spoke too soon — still having issues in some cases, but with clang-format installed and "clang-format.language.javascript.enable": false it hasn't been a problem.

I kinda suspect this is a VSCode issue (not this extension's fault) since it seems like it involves multiple extensions interacting with each other. I would encourage someone to file an issue at https://github.com/Microsoft/vscode/issues if you can come up with exact steps to reproduce the problem, and link back here for context. (I'm not at the right computer to do this at the moment.) I suppose it might also be related to microsoft/vscode#49708

@ctrlplusb
Copy link

Oh, thank the heavens, the linked issue at jsbeautify solved it for me. Disabled the Beautify plugin on my vscode and all is well.

@sonbuiGFD
Copy link

sonbuiGFD commented May 17, 2018

@jtbandes Thank you so much 👍
FYI:
it conflicts with beautify so we add:

"beautify.ignore": [
        "**/*.js",
        "**/*.jsx"
    ]

and it fixed =))

@CiGit CiGit closed this as completed Aug 6, 2018
@DevAbas
Copy link

DevAbas commented Dec 8, 2018

After ignore beautify everything went ok.
"beautify.ignore": [ "**/*.js", "**/*.jsx" ]
This code fix the problem.

@noargs
Copy link

noargs commented Dec 23, 2018

mandem works like a charm 👍
"beautify.ignore": [ "/*.js", "/*.jsx" ]

@shyamsha
Copy link

thanks man

@kajangid
Copy link

kajangid commented Mar 9, 2019

thank you man............ @lipis

@lipis
Copy link
Member

lipis commented Mar 13, 2019

@kajangid you are welcome, but what have I done to deserve the "thank you"?

@AMINEDGE
Copy link

AMINEDGE commented Apr 7, 2019

I've suddenly encountered this weird problem, and the thing is that I did nothing with configs and extensions between the last time that it was okay and now, could it be a vscode bug? any suggestions

@Aarbel
Copy link

Aarbel commented Apr 7, 2019

me too

@yukriss
Copy link

yukriss commented Apr 16, 2019

Thanks you I had the same problem. I disabled Beautify extension and all works flawlessly

@yukriss
Copy link

yukriss commented Apr 16, 2019

beautify seems to be the culprit disabled it =>reloaded and everything works flawlessly.
Thank you.

@bibek-magar
Copy link

Oh, thank the heavens, the linked issue at jsbeautify solved it for me. Disabled the Beautify plugin on my vscode and all is well.

JUst uninstall beautify extension still not work on mine

@Aarbel
Copy link

Aarbel commented May 12, 2019

reload vs code and remove other beautifying extensions

@victorbf
Copy link

I uninstall beautifying and it works!

@largo87
Copy link

largo87 commented Oct 10, 2019

"files.associations": {
"*.js": "javascriptreact"
}
it works for me

@Rodrigoandfamily
Copy link

it worked thanks get back to coding

@soriasayer
Copy link

Put the following code in settings.json and as well as in .prettierrc files.
"beautify.ignore": [ "/.js", "/.jsx" ]
it works for me.

@Mecca757
Copy link

Mecca757 commented Apr 1, 2020

Resolved by disabling Beautify, which was causing issues with Prettier.

What if you don't have beautify installed?

@mdrizwanalam
Copy link

Thanks man,,its just worked for me after uninstalling Beautify and reloaded again

@prettier prettier locked as resolved and limited conversation to collaborators Apr 14, 2020
@ntotten ntotten added the locked Please open a new issue and fill out the template instead of commenting. label Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests