Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Clone in Desktop Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

60 lines (52 sloc) 1.26 KB
/**
* Disallows an extra comma following the final element of an array or object literal.
*
* Type: `Boolean`
*
* Value: `true`
*
* JSHint: [`es3`](http://jshint.com/docs/options/#es3)
*
* #### Example
*
* ```js
* "disallowTrailingComma": true
* ```
*
* ##### Valid
*
* ```js
* var foo = [1, 2, 3];
* var bar = {a: "a", b: "b"}
* ```
*
* ##### Invalid
*
* ```js
* var foo = [1, 2, 3, ];
* var bar = {a: "a", b: "b", }
* ```
*/
var assert = require('assert');
module.exports = function() {};
module.exports.prototype = {
configure: function(options) {
assert(
options === true,
this.getOptionName() + ' option requires a true value or should be removed'
);
},
getOptionName: function() {
return 'disallowTrailingComma';
},
check: function(file, errors) {
file.iterateNodesByType(['ObjectExpression', 'ArrayExpression'], function(node) {
var closingToken = file.getLastNodeToken(node);
errors.assert.noTokenBefore({
token: closingToken,
expectedTokenBefore: {type: 'Punctuator', value: ','},
message: 'Extra comma following the final element of an array or object literal'
});
});
}
};
Jump to Line
Something went wrong with that request. Please try again.