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

Remove comma-dangle rule for ES5 #14

Closed
blond opened this Issue May 8, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@blond
Copy link
Owner

blond commented May 8, 2016

This rule is important only for ES3:

This can cause problems with IE6/7 and IE9 if it's in quirksmode. Also, in some implementations of ES3 would add length to an array if it had an additional trailing comma. This was clarified in ES5 (source):

This was clarified in ES5 (source):

Edition 5 clarifies the fact that a trailing comma at the end of an ArrayInitialiser does not add to the length of the array. This is not a semantic change from Edition 3 but some implementations may have previously misinterpreted this.

For ES5 and ES2015 this rule is more stylistic. For, example, you may want to use trailing commas to cleaner git diffs:

// bad - git diff without trailing comma
const hero = {
     firstName: 'Florence',
-    lastName: 'Nightingale'
+    lastName: 'Nightingale',
+    inventorOf: ['coxcomb graph', 'modern nursing']
};

// good - git diff with trailing comma
const hero = {
     firstName: 'Florence',
     lastName: 'Nightingale',
+    inventorOf: ['coxcomb chart', 'modern nursing'],
};

I don't want to eslint-config-pedant limit your choice of code style.

@blond

This comment has been minimized.

Copy link
Owner Author

blond commented May 8, 2016

@zxqfox, can we get ecmaVersion from .eslintrc in eslint-config-pedant package?

For example:

const ecmaVersion = require('eslint').getCurrentEcmaVersion();
const rules = {};

if (ecmaVersion === 3) {
    rules['comma-dangle'] = ['error', 'never'];
}

return rules;
@zxqfox

This comment has been minimized.

Copy link

zxqfox commented May 8, 2016

@blond Something like

const EslintConfig = require('eslint/lib/config');
const eslintConfig = new EslintConfig({cwd: process.cwd()});
const conf = eslintConfig.getConfig();
Object(conf.parserOptions).ecmaVersion; // 3, 5, 6, 7 or undefined

@tadatuta tadatuta referenced this issue May 10, 2016

Merged

Fixes #97

@zxqfox

This comment has been minimized.

Copy link

zxqfox commented May 10, 2016

Why you scared about trailing , at all? Everyone using uglify so no reason to check it differently for ES3.

This was referenced May 10, 2016

@blond blond closed this in #19 May 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.