Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Add comma-dangle eslint rule for trailing commas #79

Closed
ntwb opened this issue May 3, 2017 · 0 comments
Closed

Add comma-dangle eslint rule for trailing commas #79

ntwb opened this issue May 3, 2017 · 0 comments

Comments

@ntwb
Copy link
Member

ntwb commented May 3, 2017

Via WordPress/gutenberg#612 and WordPress/gutenberg#741

Let's add a lint rule for trailing commas:

const obj = {
    aubergine: 1,
    tomato: 2,
};

const arr = [
    'salmon',
    'shrimp',
];

There are several advantages to this. From the WordPress coding standards for PHP:

Note the comma after the last array item: this is recommended because it makes it easier to change the order of the array, and makes for cleaner diffs when new items are added.
In the past, this has been avoided in JavaScript due to lack of support in older versions of IE (this didn't work correctly until IE9). However, we don't have to care about this because we have a build process to handle it for us and because WordPress is dropping support for IE 8-10.

Rule: http://eslint.org/docs/rules/comma-dangle

Rule configuration suggestion: 'comma-dangle': ['error', 'always-multiline'],

WordPress JavaScript Coding Standards docs that will need to be updated:
• See https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/#objects
• See https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/#arrays-and-function-calls
• See https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/#examples-of-good-spacing
• See https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/#underscore-js-collection-functions

Previously: e911437

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant