mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
959 B
34 lines
959 B
10 years ago
|
/**
|
||
|
* @fileoverview Rule to count multiple spaces in regular expressions
|
||
|
* @author Matt DuVall <http://www.mattduvall.com/>
|
||
|
*/
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
// Rule Definition
|
||
|
//------------------------------------------------------------------------------
|
||
|
|
||
|
module.exports = function(context) {
|
||
|
|
||
|
return {
|
||
|
|
||
|
"Literal": function(node) {
|
||
|
var token = context.getFirstToken(node),
|
||
|
nodeType = token.type,
|
||
|
nodeValue = token.value,
|
||
|
multipleSpacesRegex = /( {2,})+?/,
|
||
|
regexResults;
|
||
|
|
||
|
if (nodeType === "RegularExpression") {
|
||
|
regexResults = multipleSpacesRegex.exec(nodeValue);
|
||
|
|
||
|
if (regexResults !== null) {
|
||
|
context.report(node, "Spaces are hard to count. Use {" + regexResults[0].length + "}.");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
};
|