syntastic-react icon indicating copy to clipboard operation
syntastic-react copied to clipboard

ES6/Babel support

Open derekdowling opened this issue 10 years ago • 18 comments

Is there a process for enabling ES6/Babel for jshint/jsxhint via this plugin? I know jsxhint --babel src/**/* works for Jsxhint if that's any help.

derekdowling avatar Mar 19 '15 19:03 derekdowling

I wonder what happens internally for that. I suspect it runs JSX and then lints the JSX converted, ES6 code. Should be doable, though

jaxbot avatar Mar 19 '15 21:03 jaxbot

Can you give me a case where this plugin doesn't do what you want it to in regards to Babel? I added some ES6 syntax to my file and JSX handled it fine and passed the converted code over the jshint correctly.

jaxbot avatar Mar 20 '15 03:03 jaxbot

I think I tried:

import 'Module' from './my_module';

and that managed to break it.

derekdowling avatar Mar 20 '15 14:03 derekdowling

+1 Yeah when I enable this, I get Illegal import declaration errors anytime I use the new ES6 module syntax.

adamalbrecht avatar Mar 23 '15 19:03 adamalbrecht

Yeah it looks like JSX doesn't support the new import syntax. That's problematic because we pipe code through JSX before jshint-ing it. Looking in to this

jaxbot avatar Mar 23 '15 19:03 jaxbot

Related: https://github.com/babel/babel/issues/825

jaxbot avatar Mar 23 '15 19:03 jaxbot

Alright, dug into it. Basically it looks like JSX should support this but it's bleeding edge. I couldn't get it to work, but you can try npm install -g react-tools to update jsx and see if that works.

If not, I'm adding the option to use Babel instead of JSX. In the future, it looks like ESLint will be a good candidate to replace this project altogether, but I get the same illegal import declaration error in that aswell, so my understanding of the syntax isn't really clear I guess

jaxbot avatar Mar 24 '15 02:03 jaxbot

Yeah I discovered ESLint today and it works great.

adamalbrecht avatar Mar 24 '15 03:03 adamalbrecht

When I use ESLint I get the same illegal declaration error, and it doesn't parse my JSX. Any tips on that?

jaxbot avatar Mar 24 '15 03:03 jaxbot

First, I installed eslint and babel-eslint. Then, in my vimrc, I added the following:

let g:syntastic_javascript_checkers = ['eslint']]

I'm not quite sure how to configure it globally (it's probably here somewhere), but in my current project, I added the following to my package.json:

esLintConfig: {
  "parser": "babel-eslint",
  // rules, etc
}

adamalbrecht avatar Mar 24 '15 12:03 adamalbrecht

Awesome, got that working. Do you think this could replace this project altogether?

Also, OT but what rules are you using? My eslint throws an error that require, React, etc., aren't defined. Bah!

jaxbot avatar Mar 26 '15 02:03 jaxbot

Also, eslint seems to suffer the same issue as jsxhint where React issues like sibling elements don't transform and instead throw errors like "Unterminated regular expression".

jaxbot avatar Mar 26 '15 02:03 jaxbot

Oh I forgot to mention one thing - you need to enable jsx and es6 under "settings". Here is my config so far:

  "eslintConfig": {
    "parser": "babel-eslint",
    "env": {
      "browser": true,
      "node": true
    },
    "settings": {
      "ecmascript": 6,
      "jsx": true
    },
    "rules": {
      "strict": 0,
      "quotes": 0,
      "no-unused-vars": 0,
      "camelcase": 0,
      "no-underscore-dangle": 0
    }

adamalbrecht avatar Mar 26 '15 13:03 adamalbrecht

And I don't know much about the merits of JSHint vs ESLint, but yeah I think it could probably replace this project. It works great for me so far.

adamalbrecht avatar Mar 26 '15 13:03 adamalbrecht

I also just discovered this to make it even more useful: https://github.com/yannickcr/eslint-plugin-react

adamalbrecht avatar Mar 26 '15 15:03 adamalbrecht

Wow, this is pretty awesome! I'm in favor of deprecating this and just supplying instructions on setting up that system.

jaxbot avatar Mar 29 '15 02:03 jaxbot

I've updated the project readme with instructions for the ESLint way. Does this resolve this issue?

jaxbot avatar Mar 31 '15 01:03 jaxbot

Strange ... it doesnt' work for me; using the plugin does work.

ghost avatar Nov 27 '15 13:11 ghost