UNPKG

1.33 kBJavaScriptView Raw
1/**
2 * Ensure there are no spaces after argument separators in call expressions.
3 *
4 * Type: `Boolean`
5 *
6 * Value: `true`
7 *
8 * #### Example
9 *
10 * ```js
11 * "disallowSpaceBetweenArguments": true
12 * ```
13 *
14 * ##### Valid
15 *
16 * ```js
17 * a(b,c);
18 * ```
19 *
20 * ##### Invalid
21 *
22 * ```js
23 * a(b, c);
24 * ```
25 */
26
27var assert = require('assert');
28
29module.exports = function() {};
30
31module.exports.prototype = {
32
33 configure: function(options) {
34 assert(
35 options === true,
36 this.getOptionName() + ' option requires a true value or should be removed'
37 );
38 },
39
40 getOptionName: function() {
41 return 'disallowSpaceBetweenArguments';
42 },
43
44 check: function(file, errors) {
45 file.iterateNodesByType(['CallExpression'], function(node) {
46 node.arguments.forEach(function(param) {
47 var token = file.getFirstNodeToken(param);
48 var punctuatorToken = file.getPrevToken(token);
49
50 if (punctuatorToken.value === ',') {
51 errors.assert.noWhitespaceBetween({
52 token: punctuatorToken,
53 nextToken: file.getNextToken(punctuatorToken),
54 message: 'Illegal space between arguments'
55 });
56 }
57 });
58 });
59 }
60};