uber / standard

JavaScript Standard Style — One Style to Rule Them All
MIT License
70 stars 8 forks source link

Experimental ES6 Support #20

Closed andrewdeandrade closed 9 years ago

andrewdeandrade commented 9 years ago

This diff adds experimental ES6 support.

Since ES6 is for all intents and purposes a different language (until all runtimes, frontend and backend, support it), is experimental and has not yet been supported yet at uber until now, es6 mode will be used as a testing ground for trying out rules that may be backported into es5 mode if they provide utility in removing footguns and making code more consistent.

i.e. if you want greater rule stability, choose es5 mode. If you're open to try out ES6, you're also opting in to being tolerant of trying out new rules to see if they provide greater code consistency between teams.

In an effort to ship ES6 mode to those who have been waiting, this PR will remain open for 24 hours after the first LGTM. Please look over the proposed rules and raise concerns now.

The rules specific to ES6 that I am curious to get people's opinion on are:

Rules specific to ES6 mode are:

Rules that are likely candidates to be ported to ES5 mode for the next major release are:

Rules that remain turned off for both ES5 and ES6 mode:

The no-restricted-modules mode will be evaluated separately for both environments and will be added in in a separate pull request.

All the rules can be found here: https://github.com/eslint/eslint/tree/master/docs/rules

FWIW, I want to eventually look into getting "custom env" support in eslint so that these can be moved to something you could turn on and off per file with an inline directive like: /*eslint-env es6*/, but for now you turn this on with the --es6 command line flag.

cc: @raynos @lxe @johnmegahan @rtsao @mlmorg @marthakelly @jcorbin @freeqaz @vicapow @philogb @superbeefy @mishabosin @addisonedwardlee @kenzanboo @collenjones @cain-uber @partriv @shaohua @yuanzong @Amazeotron @danielheller @Jeloi @jschao-uber @MarkReeder @noamlerner @Matt-Esch @rajeshsegu @rhobot @sh1mmer @thegleb @kriskowal @Willyham @ross- @orbiteleven

rtsao commented 9 years ago

I personally like object shorthand in combination with destructuring in scenarios like this:

ES6:

function component({foo, bar}) {
  return foo + bar;
}

ES5:

function component(obj) {
  return obj.foo + obj.bar;
}

Object shorthand for methods is also convenient if func-names is enforced:

ES6:

React.createClass({
    render() {}
});

ES5:

React.createClass({
  render: function render() {}
});

Thus, I think I'd be okay with either turning off object-shorthand or setting it to "always".

Regarding accessor-pairs, the defaults seem sensible to me. setWithoutGet true and getWithoutSet false. I can't think of a reason to have a setter but no getter.

andrewdeandrade commented 9 years ago

@rtsao I haven't used the ES6 getters/setters yet, but I can think of cases where you would want to set something, but have no reason to get the value back. Internal configuration of a class for example, would involve setting, but you probably wouldn't need to get that value back out for use elsewhere. It would be nice if you could enforce no-param-reassign for setters that have getters, so you would be passing and getting out values instead of references.

Why wouldn't you write the first example as:

function component(foo, bar) {
  return foo + bar;
}

So between turning off object-shorthand or setting it to always, which one and why?

shaohua commented 9 years ago

minor thing, inline comments are helpful and I hope we can reconsider no-inline-comments for es5. my philosophy has been 'inline comments are better than no comments'

marthakelly commented 9 years ago

fwiw inline comments will break the postcss css parser... because it doesn't know where to end the comment block

rtsao commented 9 years ago

@malandrew It's not so bad with just two parameters, but I find named object properties more convenient because I don't have to remember the correct parameter order.

I'm not sure how I feel about heterogeneous object literals that mix shorthand and non-shorthand:

var obj = {
  foo: 'abc',
  bar: 4,
  blah,
  thing
}

versus:

var obj = {
  foo: 'abc',
  bar: 4,
  blah: blah,
  thing: thing
}

Should the former be enforced by turning on the rule?

andrewdeandrade commented 9 years ago

I'm not a fan of the mixing either, so I updated object-shorthand to "always".

I also turned accessor-pairs on for getWithoutSet.

andrewdeandrade commented 9 years ago

@marthakelly the inline-comments rule disables inline comments, so it's all good.

andrewdeandrade commented 9 years ago

@shaohua Furthermore, lint-trap always disallowed inline comments. Comments for a line should be put before the line being commented on. It's not that you can't comment (you most certainly should), it's where the comment goes.

johnmegahan commented 9 years ago

lgtm

vicapow commented 9 years ago

LGTM 👍

cain-wang commented 9 years ago

Thanks, can't wait!

rajeshsegu commented 9 years ago

:clap:

ross- commented 9 years ago

We've been doing object-shorthand. Mixing the two was weird for a bit but I quickly got used to it.

What's the status of https://github.com/yannickcr/eslint-plugin-react support? :grin:

andrewdeandrade commented 9 years ago

@ross- I will investigate anything react specific separately in a different issue/pull request. This is just a pull request for ES6 mode. I'll check out the module you linked to.