bcomnes / sublime-standard-format

:sparkles: Runs standard --fix against the javascript in your ST3 window on save or manually.
https://packagecontrol.io/packages/StandardFormat
MIT License
60 stars 21 forks source link

not support react jsx? #47

Closed uinz closed 8 years ago

uinz commented 8 years ago

before

export default class Demo extends Component {
  render () {
    return (
      <div>
        haha
      </div>
    )
  }
}

after

export default class Demo extends Component {
  render () {
    return (
    <div>
      haha
    </div>
    )
  }
}
bcomnes commented 8 years ago

Hi @yinzSE this is the repo for the sublime plugin, and this is an issue with the actual node module maxogden/standard-format

Closing since its not an issue with the sublime side of things.

bcomnes commented 8 years ago

I hit return too soon! Woops

To answer you question, standard-format lacks support for JSX and ES6 currently. Its been a long running issue that nobody has stepped up to fix yet.

uinz commented 8 years ago

thanks much

konsumer commented 8 years ago

It appears to be solved upstream (I am using standard-format v2.2.1,) but when I put this in my user-settings, it doen't autoformat:

{
    "extensions":
    [
        "js",
        "jsx"
    ],
    "format_on_save": true
}

If I run it on the command-line (standard-format App.jsx), it works fine. It also works fine with .js files.

numbbbbb commented 6 years ago

I have the same problem and find this issue. After searching and testing for one hour, finally I find the solution.

Although this is an old issue, I think someone like me will come here through google. So maybe it's useful to write down my solution. By the way, @konsumer you can solve the problem if you still use this package now.

So the problem is, only add jsx to extensions is not enough, you also need to add the selector. Copy this to your user-settings:

{
  "extensions": ["js", "jsx"],
  "selectors": {
        "html": "source.js.embedded.html",
        "vue": "source.js.embedded.html",
        "jsx": "source.js.jsx",
    }
}

Also copy this to your user-settings if you use SublimeLinter:

// SublimeLinter Settings - User
{
  "syntax_map": {
        "html (django)": "html",
        "html (rails)": "html",
        "html 5": "html",
        "javascript (babel)": "javascript",
        "magicpython": "python",
        "php": "html",
        "python django": "python",
        "pythonimproved": "python",
        "jsx": "javascript"
    }
}

It should work now.

konsumer commented 6 years ago

It ended up just working when I set the default syntax for "javascript (babel)" for js files. I think maybe that accomplishes the same thing. I like your solution, though, as it's something I can easily save in a settings file when I migrate to a new system.