diff options
author | Michaël Zasso <targos@protonmail.com> | 2017-12-22 16:53:42 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-01-11 09:48:05 +0100 |
commit | 3dc30632755713179f345f4af024bd904c6162d0 (patch) | |
tree | f28c4f6dd6dfc5992edf301449d1a371d229755b /tools/node_modules/eslint/node_modules/remark-parse/lib/util | |
parent | a2c7085dd4a8e60d1a47572aca8bb6fcb7a32f88 (diff) | |
download | android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.gz android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.bz2 android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.zip |
tools: move eslint from tools to tools/node_modules
This is required because we need to add the babel-eslint dependency
and it has to be able to resolve "eslint".
babel-eslint is required to support future ES features such as async
iterators and import.meta.
Refs: https://github.com/nodejs/node/pull/17755
PR-URL: https://github.com/nodejs/node/pull/17820
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/remark-parse/lib/util')
5 files changed, 261 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/remark-parse/lib/util/get-indentation.js b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/get-indentation.js new file mode 100644 index 0000000000..eebd40c94a --- /dev/null +++ b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/get-indentation.js @@ -0,0 +1,46 @@ +/** + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module remark:parse:util:get-indentation + * @fileoverview Get indentation. + */ + +'use strict'; + +/* Expose. */ +module.exports = indentation; + +/* Map of characters, and their column length, + * which can be used as indentation. */ +var characters = {' ': 1, '\t': 4}; + +/** + * Gets indentation information for a line. + * + * @param {string} value - Indented line. + * @return {Object} - Indetation information. + */ +function indentation(value) { + var index = 0; + var indent = 0; + var character = value.charAt(index); + var stops = {}; + var size; + + while (character in characters) { + size = characters[character]; + + indent += size; + + if (size > 1) { + indent = Math.floor(indent / size) * size; + } + + stops[indent] = index; + + character = value.charAt(++index); + } + + return {indent: indent, stops: stops}; +} diff --git a/tools/node_modules/eslint/node_modules/remark-parse/lib/util/html.js b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/html.js new file mode 100644 index 0000000000..234ba342e1 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/html.js @@ -0,0 +1,33 @@ +/** + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module remark:parse:util:html + * @fileoverview HTML regexes. + */ + +'use strict'; + +var attributeName = '[a-zA-Z_:][a-zA-Z0-9:._-]*'; +var unquoted = '[^"\'=<>`\\u0000-\\u0020]+'; +var singleQuoted = '\'[^\']*\''; +var doubleQuoted = '"[^"]*"'; +var attributeValue = '(?:' + unquoted + '|' + singleQuoted + '|' + doubleQuoted + ')'; +var attribute = '(?:\\s+' + attributeName + '(?:\\s*=\\s*' + attributeValue + ')?)'; +var openTag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>'; +var closeTag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>'; +var comment = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->'; +var processing = '<[?].*?[?]>'; +var declaration = '<![A-Za-z]+\\s+[^>]*>'; +var cdata = '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>'; + +exports.openCloseTag = new RegExp('^(?:' + openTag + '|' + closeTag + ')'); + +exports.tag = new RegExp('^(?:' + + openTag + '|' + + closeTag + '|' + + comment + '|' + + processing + '|' + + declaration + '|' + + cdata + +')'); diff --git a/tools/node_modules/eslint/node_modules/remark-parse/lib/util/interrupt.js b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/interrupt.js new file mode 100644 index 0000000000..b8dc230550 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/interrupt.js @@ -0,0 +1,51 @@ +/** + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module remark:parse:util:get-indentation + * @fileoverview Get indentation. + */ + +'use strict'; + +module.exports = interrupt; + +function interrupt(interruptors, tokenizers, ctx, params) { + var bools = ['pedantic', 'commonmark']; + var count = bools.length; + var length = interruptors.length; + var index = -1; + var interruptor; + var config; + var fn; + var offset; + var bool; + var ignore; + + while (++index < length) { + interruptor = interruptors[index]; + config = interruptor[1] || {}; + fn = interruptor[0]; + offset = -1; + ignore = false; + + while (++offset < count) { + bool = bools[offset]; + + if (config[bool] !== undefined && config[bool] !== ctx.options[bool]) { + ignore = true; + break; + } + } + + if (ignore) { + continue; + } + + if (tokenizers[fn].apply(ctx, params)) { + return true; + } + } + + return false; +} diff --git a/tools/node_modules/eslint/node_modules/remark-parse/lib/util/normalize.js b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/normalize.js new file mode 100644 index 0000000000..3602a18f78 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/normalize.js @@ -0,0 +1,29 @@ +/** + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module remark:parse:util:normalize + * @fileoverview Normalize an identifier. + */ + +'use strict'; + +/* Dependencies. */ +var collapseWhiteSpace = require('collapse-white-space'); + +/* Expose. */ +module.exports = normalize; + +/** + * Normalize an identifier. Collapses multiple white space + * characters into a single space, and removes casing. + * + * @example + * normalizeIdentifier('FOO\t bar'); // 'foo bar' + * + * @param {string} value - Content to normalize. + * @return {string} - Normalized content. + */ +function normalize(value) { + return collapseWhiteSpace(value).toLowerCase(); +} diff --git a/tools/node_modules/eslint/node_modules/remark-parse/lib/util/remove-indentation.js b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/remove-indentation.js new file mode 100644 index 0000000000..d56db0bad4 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/remark-parse/lib/util/remove-indentation.js @@ -0,0 +1,102 @@ +/** + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module remark:parse:util:remove-indentation + * @fileoverview Remove indentation. + */ + +'use strict'; + +/* Dependencies. */ +var trim = require('trim'); +var repeat = require('repeat-string'); +var getIndent = require('./get-indentation'); + +/* Expose. */ +module.exports = indentation; + +/* Characters. */ +var C_SPACE = ' '; +var C_NEWLINE = '\n'; +var C_TAB = '\t'; + +/** + * Remove the minimum indent from every line in `value`. + * Supports both tab, spaced, and mixed indentation (as + * well as possible). + * + * @example + * removeIndentation(' foo'); // 'foo' + * removeIndentation(' foo', 2); // ' foo' + * removeIndentation('\tfoo', 2); // ' foo' + * removeIndentation(' foo\n bar'); // ' foo\n bar' + * + * @param {string} value - Value to trim. + * @param {number?} [maximum] - Maximum indentation + * to remove. + * @return {string} - Unindented `value`. + */ +function indentation(value, maximum) { + var values = value.split(C_NEWLINE); + var position = values.length + 1; + var minIndent = Infinity; + var matrix = []; + var index; + var indentation; + var stops; + var padding; + + values.unshift(repeat(C_SPACE, maximum) + '!'); + + while (position--) { + indentation = getIndent(values[position]); + + matrix[position] = indentation.stops; + + if (trim(values[position]).length === 0) { + continue; + } + + if (indentation.indent) { + if (indentation.indent > 0 && indentation.indent < minIndent) { + minIndent = indentation.indent; + } + } else { + minIndent = Infinity; + + break; + } + } + + if (minIndent !== Infinity) { + position = values.length; + + while (position--) { + stops = matrix[position]; + index = minIndent; + + while (index && !(index in stops)) { + index--; + } + + if ( + trim(values[position]).length !== 0 && + minIndent && + index !== minIndent + ) { + padding = C_TAB; + } else { + padding = ''; + } + + values[position] = padding + values[position].slice( + index in stops ? stops[index] + 1 : 0 + ); + } + } + + values.shift(); + + return values.join(C_NEWLINE); +} |