JSCS rules around trailing commas in object/array literals.
This plugin is deprecated. Use ESLint with its comma-dangle
rule as JSCS is deprecated now and so is this plugin.
This module no longer define rules disallowTrailingComma
& requireTrailingComma
as rules named this way and covering most of their functionality are now included in JSCS. If you need to apply different logic to arrays and objects, you need to migrate configuration, for example the followint config:
"requireTrailingComma": {
"inArrays": true,
"inObjects": false
}
would need to be changed to:
"requireTrailingCommaInCollapsedLiterals": {
"inArrays": true,
"inObjects": false
}
"requireTrailingCommaInExpandedLiterals": {
"inArrays": true,
"inObjects": false
}
To install the module, invoke:
npm install jscs-trailing-comma --save-dev
This set of rules checks for trailing commas in object/array literals and either enforces them or disallows them to have a consistend code style.
Note: In ECMAScript 5.1 trailing commas are allowed in object/array literals. Putting trailing commas is sometimes a desired pattern since it makes it possible to add new entries to the end (or remove from it) of the object/array literal without touching the preceding line. It makes Git diffs prettier as you don't touch unrelated parts of code.
This module defines 4 tasks to be passed to JSCS. See the JSCS documentation for further information about working with JSCS and its rules.
To be able to use rules from this module, add the following to your JSCS configuration file:
"plugins": ["jscs-trailing-comma"]
Rules from this module work on a distinction between expanded and collapsed literals. Expanded literals are multi-line, with closing brackets in a separate line. Collapsed literal are either single-line or multi-line but without closing brackets in a separate line. You can think of collapsed literals as single-line with optional line breaks when the line is too long. They're more similar to single-line literals than expanded literals.
Examples could make the distinction clearer.
- Expanded literals:
var o = {
key: "value",
};
var o = {
key1: "value1",
key2: [
"param1",
],
};
- Collapsed literals
var o = {key: "value"};
var o = {key1: "value1", key2: "value2", key3: "value3",
key4: "value4", key5: "value5"};
Arrays are treated in a similar way.
Requires a trailing comma in expanded literals.
Type: Boolean|Object
Values: true
or an object with inArrays
and inObjects
as child properties. Child properties must be set to true
.
"requireTrailingCommaInExpandedLiterals": {
"inArrays": true,
"inObjects": true
}
var o1 = {
key: "value",
};
var o2 = {key: "value",};
var o3 = {key: "value"};
var o4 = [
"value",
};
var o5 = ["value",];
var o6 = ["value"];
var o1 = {
key: "value"
};
var o2 = [
"value"
};
Disallows a trailing comma in expanded literals.
Type: Boolean|Object
Values: true
or an object with inArrays
and inObjects
as child properties. Child properties must be set to true
.
"disallowTrailingCommaInExpandedLiterals": {
"inArrays": true,
"inObjects": true
}
var o1 = {
key: "value"
};
var o2 = {key: "value",};
var o3 = {key: "value"};
var o4 = [
"value"
};
var o5 = ["value",];
var o6 = ["value"];
var o1 = {
key: "value",
};
var o2 = [
"value",
};
Requires a trailing comma in collapsed literals.
Type: Boolean|Object
Values: true
or an object with inArrays
and inObjects
as child properties. Child properties must be set to true
.
"requireTrailingCommaInCollapsedLiterals": {
"inArrays": true,
"inObjects": true
}
var o1 = {
key: "value",
};
var o2 = {
key: "value"
};
var o3 = {key: "value",};
var o4 = [
"value",
};
var o5 = [
"value"
};
var o6 = ["value",];
var o1 = {key: "value"};
var o2 = ["value"];
Disallows a trailing comma in collapsed literals.
Type: Boolean|Object
Values: true
or an object with inArrays
and inObjects
as child properties. Child properties must be set to true
.
"disallowTrailingCommaInCollapsedLiterals": {
"inArrays": true,
"inObjects": true
}
var o1 = {
key: "value",
};
var o2 = {
key: "value"
};
var o3 = {key: "value"};
var o4 = [
"value",
};
var o5 = [
"value"
};
var o6 = ["value"];
var o1 = {key: "value",};
var o2 = ["value",];
This project aims to support all Node.js LTS versions in the "active" phase (see LTS README for more details) as well as the latest stable Node.js.
Copyright (c) 2014 Laboratorium EE. Licensed under the MIT license.