1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | var assert = require('assert');
|
34 |
|
35 | module.exports = function() {};
|
36 |
|
37 | module.exports.prototype = {
|
38 | configure: function(options) {
|
39 | assert(
|
40 | options === true,
|
41 | this.getOptionName() + ' option requires a true value or should be removed'
|
42 | );
|
43 | },
|
44 |
|
45 | getOptionName: function() {
|
46 | return 'disallowTrailingComma';
|
47 | },
|
48 |
|
49 | check: function(file, errors) {
|
50 | file.iterateNodesByType([
|
51 | 'ObjectExpression', 'ArrayExpression',
|
52 | 'ObjectPattern', 'ArrayPattern'
|
53 | ], function(node) {
|
54 | var closingToken = file.getLastNodeToken(node);
|
55 | var comma = closingToken.getPreviousCodeToken();
|
56 |
|
57 | if (comma.type === 'Punctuator' && comma.value === ',') {
|
58 | errors.add(
|
59 | 'Extra comma following the final element of an array or object literal',
|
60 | comma
|
61 | );
|
62 | }
|
63 | });
|
64 | },
|
65 |
|
66 | _fix: function(file, error) {
|
67 | error.element.remove();
|
68 | }
|
69 |
|
70 | };
|