jscs-dev/node-jscs

Supporting ES7/Babel

hzoo opened this issue ยท 29 comments

hzoo commented

For #1352, #1344, #1270.

My plan is to make babel a possible parser to use in the esprima option.
I could do a repo for this so you can do "esprima": "babel-jscs" or something like that.
Nothing would need to be changed in jscs itself.
babel-jscs would modify the acorn parser to output into an esprima format and patch estraverse (just modifying babel-eslint somewhat).

I got it working on an es7 code snippet (the issues linked) and a small project but running it with more rules leads to some errors that still need to be fixed.

hzoo commented

Almost ready to do an initial version - can someone give thoughts on the change in #1369?

Just ran all the rules/ tests (the other ones failed but shouldn't matter) and the only failing ones left are for validate-quote-marks. Seems to lose quote information.

hzoo commented

@moroshko, @olanod, @ben-ng - If you want to try it out, I created https://github.com/hzoo/babel-jscs for testing (no npm package yet).

Will wait for the next release and then move to https://github.com/jscs-dev/babel-jscs - (or should I just do that now?).

You'll need to update package.json and your .jscsrc to "esprima": "./node_modules/babel-jscs"

{
  "node-jscs": "jscs-dev/node-jscs#master",
  "babel-jscs": "hzoo/babel-jscs#master"
}

Does it work with our tests? We can intergrate this in our CI-runs, if it pass, i think we could do the npm package and push to jscs-dev org repo

hzoo commented

I still have to figure out how to run the tests (git submodule?) not sure yet. I ran it manually before and got a few issues regarding cli, and quotes (babel infers the quotes will always output the same one).

It seems babel-jscs has support for jsx?

hzoo commented

Yeah it will parse anything babel supports itself since it will be an option for esprima - "esprima": "babel-jscs" (es6, es7, jsx, flow) - mostly through acorn-to-esprima transformation and some other stuff

So is there anything preventing us from dropping esprima-harmony-jscs dep and using babel-jscs for esnext option?

hzoo commented

For me it would be that it hasn't been tested as much yet and not all the tests pass (at the moment) but that shouldn't be too hard to fix.

Well, we described this esnext option as experimental, although, i fear about esprimaOptions param.

Otherwise jsx and more extensive es6 supports does it for me.

@mikesherov, @zxqfox, @mrjoelkemp, @mdevils thoughts?

qfox commented

@markelog ๐Ÿ‘ for jsx as a plugin for esprima ast. And I'm not sure we need this when we'll support esprima 2.x. Since there I'm not against using it for another library. But it's a revolution, and need to hear @mikesherov about it.

@hzoo thank you!! ๐Ÿ™ I was trying to set up jscs on a project that uses babel (es6) + flow, and couldn't find any parser that could accommodate both. your package made everything magically work. hope you keep developing it ๐Ÿ‘

Just added this feature to 2.0 roadmap, i hope you don't mind

As for me, there is a strange situation around esprima right now.

  • esprima supports ES6, but it does not support ES5 without ES6 (it does not support enabling/disabling features). It also does not support JSX and doesn't have plugin interface to write a JSX plugin. esprima-fb is not planned to be supported.
  • estraverse supports both ES5 and ES6. And it can be configured to support JSX.
  • escodegen only supports ES5 (no ES6 and JSX support).
  • escope supports both ES5 and ES6, but does not support JSX.

I hope someone can share his picture on acorn/babel.

Nice list

esprima supports ES6

Not fully, plugin interface will come right after full support of the ES6.

but it does not support ES5 without ES6

ES6 is back-compat, so i don't see an issue there.

Acorn supports es6 and written on es6-dialect also has plugin for jsx, you forgot the espree btw :-).

Answer for babel is kinda obvious :-), but it also has support for ES7 features, like if someone mention possible extension on TC-meeting. But not proposed but only mentioned! It probably be added into the babel for the community response, which scary cool and dangerous at the same time.

In any case, i put all my money on babel-jscs here.

Hey @hzoo, do you have time to provide pr for this?

hzoo commented

What would I need to do for the pr?

Basically, pr that proposes to use babel-jscs instead of esprima-fb

@hzoo where should I file issues? here:
https://github.com/hzoo/babel-jscs
I tried your branch seems buggy on the validatequotemarks. Its changing my single quotes to double quotes when I use -f

hzoo commented

@deezahyn Um yeah just file it at https://github.com/hzoo/babel-jscs there until I move it to https://github.com/jscs-dev/babel-jscs. I guess we can just do it whenever.

However for that particular issue about quote marks I documented in the readme already. Not sure what we can do about it @sebmck?

Rules related to quotes won't work: validateQuoteMarks (Babel infers and transforms quotes to be consistent so you'll need to find another way to enforce this or turn off the parser and run it.)

@hzoo

Babel infers and transforms quotes to be consistent so you'll need to find another way to enforce this or turn off the parser and run it.

This is completely unrelated to the parser and is done in the code generator (which babel-jscs and babel-eslint don't use) so this isn't the cause of the issue.

hzoo commented

@sebmck Ah ok. I didn't do enough research then xd.

@deezahyn Yeah you can make an issue for it in the repo or I'l do it later (added in hzoo/babel-jscs/issues/1)

@markelog Ok shouldn't be too hard to just replace the parser for esnext.

Seems like it's just

this._esprima = options.esprima || (options.esnext ? babelJscs : defaultEsprima);

Yeah :-)

Why not publish an beta version(npm publish . --tag beta), so that we can install with a beta tag.

Install from github, sometimes will be too slow.

hzoo commented

Sounds like a good idea (would be good so people can test and find any big issues). I think we're going to release "soon" though ๐Ÿ˜„

@hzoo That great. Waiting for you beta release.

I'm trying to enable es7 decorator rules in jscs. Will this help me out?

Now you just need to use esnext: true