summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2016-12-31 21:52:56 -0800
committerRich Trott <rtrott@gmail.com>2017-01-06 14:36:38 -0800
commit38b18e330fc74029515bd1d9e39bc9c670119a39 (patch)
tree8c66039edc3c2ce415db4242dd0419da71884122 /tools
parent33cd0aa70c1a3161fa821875b538c888eba7ddc6 (diff)
downloadandroid-node-v8-38b18e330fc74029515bd1d9e39bc9c670119a39.tar.gz
android-node-v8-38b18e330fc74029515bd1d9e39bc9c670119a39.tar.bz2
android-node-v8-38b18e330fc74029515bd1d9e39bc9c670119a39.zip
tools: remove no-useless-regex-char-class-escape
The `no-useless-regex-char-class-escape` custom lint rule was introduced as a less aggressive alternative to some enhancements that were introduced into ESLint. Those enhancements were blocking us from updating ESLint. However, they have since been relaxed and the custom rule is no longer needed. Remove it. PR-URL: https://github.com/nodejs/node/pull/10561 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/eslint-rules/no-useless-regex-char-class-escape.js190
1 files changed, 0 insertions, 190 deletions
diff --git a/tools/eslint-rules/no-useless-regex-char-class-escape.js b/tools/eslint-rules/no-useless-regex-char-class-escape.js
deleted file mode 100644
index e18077098d..0000000000
--- a/tools/eslint-rules/no-useless-regex-char-class-escape.js
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * @fileoverview Disallow useless escape in regex character class
- * Based on 'no-useless-escape' rule
- */
-'use strict';
-
-//------------------------------------------------------------------------------
-// Rule Definition
-//------------------------------------------------------------------------------
-
-const REGEX_CHARCLASS_ESCAPES = new Set('\\bcdDfnrsStvwWxu0123456789]');
-
-/**
- * Parses a regular expression into a list of regex character class list.
- * @param {string} regExpText raw text used to create the regular expression
- * @returns {Object[]} A list of character classes tokens with index and
- * escape info
- * @example
- *
- * parseRegExpCharClass('a\\b[cd-]')
- *
- * returns:
- * [
- * {
- * empty: false,
- * start: 4,
- * end: 6,
- * chars: [
- * {text: 'c', index: 4, escaped: false},
- * {text: 'd', index: 5, escaped: false},
- * {text: '-', index: 6, escaped: false}
- * ]
- * }
- * ]
- */
-
-function parseRegExpCharClass(regExpText) {
- const charList = [];
- let charListIdx = -1;
- const initState = {
- escapeNextChar: false,
- inCharClass: false,
- startingCharClass: false
- };
-
- regExpText.split('').reduce((state, char, index) => {
- if (!state.escapeNextChar) {
- if (char === '\\') {
- return Object.assign(state, { escapeNextChar: true });
- }
- if (char === '[' && !state.inCharClass) {
- charListIdx += 1;
- charList.push({ start: index + 1, chars: [], end: -1 });
- return Object.assign(state, {
- inCharClass: true,
- startingCharClass: true
- });
- }
- if (char === ']' && state.inCharClass) {
- const charClass = charList[charListIdx];
- charClass.empty = charClass.chars.length === 0;
- if (charClass.empty) {
- charClass.start = charClass.end = -1;
- } else {
- charList[charListIdx].end = index - 1;
- }
- return Object.assign(state, {
- inCharClass: false,
- startingCharClass: false
- });
- }
- }
- if (state.inCharClass) {
- charList[charListIdx].chars.push({
- text: char,
- index, escaped:
- state.escapeNextChar
- });
- }
- return Object.assign(state, {
- escapeNextChar: false,
- startingCharClass: false
- });
- }, initState);
-
- return charList;
-}
-
-module.exports = {
- meta: {
- docs: {
- description: 'disallow unnecessary regex characer class escape sequences',
- category: 'Best Practices',
- recommended: false
- },
- fixable: 'code',
- schema: [{
- 'type': 'object',
- 'properties': {
- 'override': {
- 'type': 'array',
- 'items': { 'type': 'string' },
- 'uniqueItems': true
- }
- },
- 'additionalProperties': false
- }]
- },
-
- create(context) {
- const overrideSet = new Set(context.options.length ?
- context.options[0].override || [] :
- []);
-
- /**
- * Reports a node
- * @param {ASTNode} node The node to report
- * @param {number} startOffset The backslash's offset
- * from the start of the node
- * @param {string} character The uselessly escaped character
- * (not including the backslash)
- * @returns {void}
- */
- function report(node, startOffset, character) {
- context.report({
- node,
- loc: {
- line: node.loc.start.line,
- column: node.loc.start.column + startOffset
- },
- message: 'Unnecessary regex escape in character' +
- ' class: \\{{character}}',
- data: { character },
- fix: (fixer) => {
- const start = node.range[0] + startOffset;
- return fixer.replaceTextRange([start, start + 1], '');
- }
- });
- }
-
- /**
- * Checks if a node has superflous escape character
- * in regex character class.
- *
- * @param {ASTNode} node - node to check.
- * @returns {void}
- */
- function check(node) {
- if (node.regex) {
- parseRegExpCharClass(node.regex.pattern)
- .forEach((charClass) => {
- charClass
- .chars
- // The '-' character is a special case if is not at
- // either edge of the character class. To account for this,
- // filter out '-' characters that appear in the middle of a
- // character class.
- .filter((charInfo) => !(charInfo.text === '-' &&
- (charInfo.index !== charClass.start &&
- charInfo.index !== charClass.end)))
-
- // The '^' character is a special case if it's at the beginning
- // of the character class. To account for this, filter out '^'
- // characters that appear at the start of a character class.
- //
- .filter((charInfo) => !(charInfo.text === '^' &&
- charInfo.index === charClass.start))
-
- // Filter out characters that aren't escaped.
- .filter((charInfo) => charInfo.escaped)
-
- // Filter out characters that are valid to escape, based on
- // their position in the regular expression.
- .filter((charInfo) => !REGEX_CHARCLASS_ESCAPES.has(charInfo.text))
-
- // Filter out overridden character list.
- .filter((charInfo) => !overrideSet.has(charInfo.text))
-
- // Report all the remaining characters.
- .forEach((charInfo) =>
- report(node, charInfo.index, charInfo.text));
- });
- }
- }
-
- return {
- Literal: check
- };
- }
-};