1 | /**
|
2 | * @fileoverview Rule to count multiple spaces in regular expressions
|
3 | * @author Matt DuVall <http://www.mattduvall.com/>
|
4 | */
|
5 |
|
6 | //------------------------------------------------------------------------------
|
7 | // Rule Definition
|
8 | //------------------------------------------------------------------------------
|
9 |
|
10 | module.exports = function(context) {
|
11 |
|
12 | ;
|
13 |
|
14 | return {
|
15 |
|
16 | "Literal": function(node) {
|
17 | var token = context.getTokens(node)[0],
|
18 | nodeType = token.type,
|
19 | nodeValue = token.value,
|
20 | multipleSpacesRegex = /( {2,})+?/,
|
21 | regexResults;
|
22 |
|
23 | if (nodeType === "RegularExpression") {
|
24 | regexResults = multipleSpacesRegex.exec(nodeValue);
|
25 |
|
26 | if (regexResults !== null) {
|
27 | context.report(node, "Spaces are hard to count. Use {" + regexResults[0].length + "}.");
|
28 | }
|
29 | }
|
30 | }
|
31 | };
|
32 |
|
33 | };
|