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

single attribute breaks jsx beautification #834

Closed
zenyr opened this issue Dec 20, 2015 · 8 comments
Closed

single attribute breaks jsx beautification #834

zenyr opened this issue Dec 20, 2015 · 8 comments
Milestone

Comments

@zenyr
Copy link

zenyr commented Dec 20, 2015

Thanks for your hard work. Apart from infamous one-lining {foo:'bar'} issue (wink wink), I'm having some different issue here. Possibly duplicate issue, but don't know the specific keyword to search here, so I'm submitting one.

Problem

single attribute breaks jsx beautification. If I either put out someAttr or replace to someAttr={true} from the repro case below, it works as expected.

Edit: Also it seems like only happening at the out-most jsx tag.

Environment: atom-beautify, jsbeautifier.org

Repro

Input

export default class TestCase extends React.Component {
  render() {
    return ( <div className={this.props.className} someAttr>
      <div>Smth</div>
    </div> );
  }
}

Expected

(Untouched from Input)

Output

export default class TestCase extends React.Component {
    render() {
      return ( < div className = {
          this.props.className
        }
        someAttr >
        <div>Smth</div> < /div> );
      }
    }
@bitwiseman
Copy link
Member

Yeah, I didn't know <div someAttr>val</div> is a valid attribute. I thought attributes needed at least someAttr=''

http://stackoverflow.com/questions/6926442/is-an-xml-attribute-without-a-value-valid
http://www.w3.org/TR/2006/REC-xml11-20060816/#sec-starttags

Is this a JSX thing?
Or are you just saying, "Hey, the beautifier shouldn't 'splode my code if I give it less than perfect xml syntax" ?

@zenyr
Copy link
Author

zenyr commented Dec 22, 2015

Pretty sure this is a jsx thing. <CamelCaseTagName such={{double:'curlybraces'}} {...with.props.spread} /> , which is a plain everyday jsx convention is definitely NOT a valid XML ;D

@phuna
Copy link

phuna commented Jan 1, 2016

I got same problem today with JSX. I'm using Atom editor with atom-beautify package. I need to change beautifier for .js file to Pretty Diff.

@luckyyang
Copy link

luckyyang commented Nov 25, 2016

I still got the error, is this bug fixed?

still got this error:

<Component {...newProps} />
will into:

      < Component {...newProps }
      />

if do format for the entire file, will get:

<
      Component {...newProps }
      />

@c-gargi
Copy link

c-gargi commented Jun 21, 2017

Input : <MenuItem data-id={org.value} onClick={self.changeMenuState} />

Out put : < MenuItem data - id = { org.value } onClick = { self.changeMenuState } />

The space between data - id causing parsing error. Please help me with that.

@bitwiseman
Copy link
Member

@c-gargi Did you turn on e4x?

@c-gargi
Copy link

c-gargi commented Jun 21, 2017

Yes I did @bitwiseman

@bitwiseman
Copy link
Member

@c-gargi When I use e4x enabled on http://jsbeautifier.org/ the input remains unchanged. Disabled, gets the output you saw. Seems likely there's a settings or versioning issue in your environment.

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

No branches or pull requests

5 participants