Move eslint rule to separate repo
parent
a5778a95c3
commit
58c36fafee
|
@ -9,6 +9,9 @@ module.exports = {
|
|||
"experimentalObjectRestSpread": true
|
||||
}
|
||||
},
|
||||
"plugins": [
|
||||
"no-regex-dot"
|
||||
],
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
|
@ -28,7 +31,7 @@ module.exports = {
|
|||
"no-empty": [
|
||||
"off"
|
||||
],
|
||||
"no-regex-dot": [
|
||||
"no-regex-dot/no-regex-dot": [
|
||||
"error"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/**
|
||||
* @fileoverview Rule to forbid . in regular expressions (it doesn't match newlines, [\s\S] should be used instead)
|
||||
* @author Vitaliy Filippov
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
docs: {
|
||||
description: "disallow . in regular expressions",
|
||||
category: "Possible Errors",
|
||||
recommended: true
|
||||
},
|
||||
|
||||
schema: []
|
||||
},
|
||||
|
||||
create: function(context) {
|
||||
|
||||
/**
|
||||
* Get the regex expression
|
||||
* @param {ASTNode} node node to evaluate
|
||||
* @returns {*} Regex if found else null
|
||||
* @private
|
||||
*/
|
||||
function getRegExp(node) {
|
||||
if (node.value instanceof RegExp) {
|
||||
return node.value;
|
||||
} else if (typeof node.value === "string") {
|
||||
|
||||
var parent = context.getAncestors().pop();
|
||||
|
||||
if ((parent.type === "NewExpression" || parent.type === "CallExpression") &&
|
||||
parent.callee.type === "Identifier" && parent.callee.name === "RegExp"
|
||||
) {
|
||||
|
||||
// there could be an invalid regular expression string
|
||||
try {
|
||||
return new RegExp(node.value);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given regex string has . in it
|
||||
* @param {String} regexStr regex as string to check
|
||||
* @returns {Boolean} returns true if finds control characters on given string
|
||||
* @private
|
||||
*/
|
||||
function hasDot(regexStr) {
|
||||
return /(^|[^\\])(\\\\)*\./.test(regexStr);
|
||||
}
|
||||
|
||||
return {
|
||||
Literal: function(node) {
|
||||
var computedValue,
|
||||
regex = getRegExp(node);
|
||||
|
||||
if (regex) {
|
||||
computedValue = regex.toString();
|
||||
|
||||
if (hasDot(computedValue)) {
|
||||
context.report(node, "Unexpected . in regular expression, use [\\s\\S] instead");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
};
|
|
@ -13,10 +13,11 @@
|
|||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.10.1",
|
||||
"babel-plugin-transform-es2015-destructuring": "^6.9.0",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.8.0",
|
||||
"eslint": "^3.0.0"
|
||||
"babel-cli": "latest",
|
||||
"babel-plugin-transform-es2015-destructuring": "latest",
|
||||
"babel-plugin-transform-object-rest-spread": "latest",
|
||||
"eslint": "latest",
|
||||
"eslint-plugin-no-regex-dot": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
# php -r 'require "htmLawed.php"; print htmLawed::sanitize(file_get_contents("test_xss.txt"), array("safe" => 1));' > test_php.htm
|
||||
node_modules/.bin/eslint --rulesdir eslint-plugin-no-regex-dot htmLawed.js
|
||||
node_modules/.bin/eslint htmLawed.js
|
||||
node_modules/.bin/babel htmLawed.js > htmLawed.c.js
|
||||
nodejs htmLawed-test.js
|
||||
|
|
Loading…
Reference in New Issue