From 57f0dd56dd63c5546ff902dbd006fdb7a2ef3e48 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sun, 17 Nov 2019 18:06:14 +0800 Subject: [PATCH] Replace `indexOf` with `includes` (#6967) * Replace `indexOf` with `includes` * Add `unicorn/prefer-includes` --- .eslintrc.yml | 2 + package.json | 1 + src/cli/util.js | 7 +- src/common/util.js | 2 +- src/language-css/clean.js | 6 +- src/language-css/parser-postcss.js | 4 +- src/language-css/printer-postcss.js | 4 +- src/language-css/utils.js | 31 ++-- src/language-handlebars/printer-glimmer.js | 8 +- src/language-html/printer-html.js | 2 +- src/language-html/utils.js | 10 +- src/language-js/pragma.js | 2 +- src/language-js/printer-estree.js | 4 +- src/language-js/utils.js | 2 +- src/language-markdown/embed.js | 2 +- src/language-markdown/parser-markdown.js | 2 +- src/language-markdown/printer-markdown.js | 13 +- src/language-yaml/printer-yaml.js | 2 +- src/language-yaml/utils.js | 2 +- src/main/core.js | 8 +- src/main/options-normalizer.js | 4 +- src/main/options.js | 4 +- src/main/range-util.js | 6 +- src/main/support.js | 2 +- tests_integration/path-serializer.js | 4 +- website/playground/urlHash.js | 7 +- yarn.lock | 178 ++++++++++++++++++++- 27 files changed, 242 insertions(+), 77 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 5ddea1bff..927262197 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -10,6 +10,7 @@ parserOptions: ecmaVersion: 2017 plugins: - import + - unicorn rules: curly: error import/no-extraneous-dependencies: @@ -34,3 +35,4 @@ rules: - error - never - exceptRange: true + unicorn/prefer-includes: error diff --git a/package.json b/package.json index 10f16b0aa..12603ebaf 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "eslint-plugin-import": "2.18.2", "eslint-plugin-prettier": "3.1.1", "eslint-plugin-react": "7.16.0", + "eslint-plugin-unicorn": "13.0.0", "execa": "3.2.0", "jest": "23.3.0", "jest-junit": "9.0.0", diff --git a/src/cli/util.js b/src/cli/util.js index e419a11ec..e5134a675 100644 --- a/src/cli/util.js +++ b/src/cli/util.js @@ -600,8 +600,7 @@ function createUsage(context) { const lastCategories = constant.categoryOrder.slice(-1); const restCategories = Object.keys(groupedOptions).filter( category => - firstCategories.indexOf(category) === -1 && - lastCategories.indexOf(category) === -1 + !firstCategories.includes(category) && !lastCategories.includes(category) ); const allCategories = firstCategories.concat(restCategories, lastCategories); @@ -990,9 +989,7 @@ function updateContextArgv(context, plugins, pluginSearchDirs) { function normalizeContextArgv(context, keys) { const detailedOptions = !keys ? context.detailedOptions - : context.detailedOptions.filter( - option => keys.indexOf(option.name) !== -1 - ); + : context.detailedOptions.filter(option => keys.includes(option.name)); const argv = !keys ? context.argv : pick(context.argv, keys); context.argv = optionsNormalizer.normalizeCliOptions(argv, detailedOptions, { diff --git a/src/common/util.js b/src/common/util.js index 9f13f83c6..4a5667bda 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -64,7 +64,7 @@ function skip(chars) { if (!chars.test(c)) { return cursor; } - } else if (chars.indexOf(c) === -1) { + } else if (!chars.includes(c)) { return cursor; } diff --git a/src/language-css/clean.js b/src/language-css/clean.js index 054428ce7..fcfee341b 100644 --- a/src/language-css/clean.js +++ b/src/language-css/clean.js @@ -63,9 +63,9 @@ function clean(ast, newObj, parent) { if ( (ast.type === "value-word" && ((ast.isColor && ast.isHex) || - ["initial", "inherit", "unset", "revert"].indexOf( + ["initial", "inherit", "unset", "revert"].includes( newObj.value.replace().toLowerCase() - ) !== -1)) || + ))) || ast.type === "media-feature" || ast.type === "selector-root-invalid" || ast.type === "selector-pseudo" @@ -140,7 +140,7 @@ function clean(ast, newObj, parent) { if (ast.type === "selector-tag") { const lowercasedValue = ast.value.toLowerCase(); - if (["from", "to"].indexOf(lowercasedValue) !== -1) { + if (["from", "to"].includes(lowercasedValue)) { newObj.value = lowercasedValue; } } diff --git a/src/language-css/parser-postcss.js b/src/language-css/parser-postcss.js index 447a8593e..d0e2287c4 100644 --- a/src/language-css/parser-postcss.js +++ b/src/language-css/parser-postcss.js @@ -442,7 +442,7 @@ function parseNestedCSS(node, options) { "return", "define-mixin", "add-mixin" - ].indexOf(name) !== -1 + ].includes(name) ) { // Remove unnecessary spaces in SCSS variable arguments params = params.replace(/(\$\S+?)\s+?\.\.\./, "$1..."); @@ -465,7 +465,7 @@ function parseNestedCSS(node, options) { return node; } - if (["media", "custom-media"].indexOf(lowercasedName) !== -1) { + if (["media", "custom-media"].includes(lowercasedName)) { if (params.includes("#{")) { // Workaround for media at rule with scss interpolation return { diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index b2b57ab00..722311ed8 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -118,7 +118,7 @@ function genericPrint(path, options, print) { const rawText = node.raws.text || node.text; // Workaround a bug where the location is off. // https://github.com/postcss/postcss-scss/issues/63 - if (text.indexOf(rawText) === -1) { + if (!text.includes(rawText)) { if (node.raws.inline) { return concat(["// ", rawText]); } @@ -512,7 +512,7 @@ function genericPrint(path, options, print) { // Ignore escape `\` if ( iNode.value && - iNode.value.indexOf("\\") !== -1 && + iNode.value.includes("\\") && iNextNode && iNextNode.type !== "value-comment" ) { diff --git a/src/language-css/utils.js b/src/language-css/utils.js index a45e666ca..cb8583448 100644 --- a/src/language-css/utils.js +++ b/src/language-css/utils.js @@ -35,7 +35,7 @@ function getAncestorCounter(path, typeOrTypes) { let ancestorNode; while ((ancestorNode = path.getParentNode(++counter))) { - if (types.indexOf(ancestorNode.type) !== -1) { + if (types.includes(ancestorNode.type)) { return counter; } } @@ -67,9 +67,8 @@ function isSCSS(parser, text) { } function isWideKeywords(value) { - return ( - ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== - -1 + return ["initial", "inherit", "unset", "revert"].includes( + value.toLowerCase() ); } @@ -79,7 +78,7 @@ function isKeyframeAtRuleKeywords(path, value) { atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && - ["from", "to"].indexOf(value.toLowerCase()) !== -1 + ["from", "to"].includes(value.toLowerCase()) ); } @@ -122,7 +121,7 @@ function insideAtRuleNode(path, atRuleNameOrAtRuleNames) { return ( atRuleAncestorNode && - atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1 + atRuleNames.includes(atRuleAncestorNode.name.toLowerCase()) ); } @@ -168,14 +167,13 @@ function isDetachedRulesetDeclarationNode(node) { function isForKeywordNode(node) { return ( node.type === "value-word" && - ["from", "through", "end"].indexOf(node.value) !== -1 + ["from", "through", "end"].includes(node.value) ); } function isIfElseKeywordNode(node) { return ( - node.type === "value-word" && - ["and", "or", "not"].indexOf(node.value) !== -1 + node.type === "value-word" && ["and", "or", "not"].includes(node.value) ); } @@ -214,20 +212,19 @@ function isMathOperatorNode(node) { } function isEqualityOperatorNode(node) { - return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1; + return node.type === "value-word" && ["==", "!="].includes(node.value); } function isRelationalOperatorNode(node) { return ( - node.type === "value-word" && - ["<", ">", "<=", ">="].indexOf(node.value) !== -1 + node.type === "value-word" && ["<", ">", "<=", ">="].includes(node.value) ); } function isSCSSControlDirectiveNode(node) { return ( node.type === "css-atrule" && - ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1 + ["if", "else", "for", "each", "while"].includes(node.name) ); } @@ -363,7 +360,7 @@ function isRightCurlyBraceNode(node) { } function isWordNode(node) { - return ["value-word", "value-atword"].indexOf(node.type) !== -1; + return ["value-word", "value-atword"].includes(node.type); } function isColonNode(node) { @@ -371,9 +368,7 @@ function isColonNode(node) { } function isMediaAndSupportsKeywords(node) { - return ( - node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1 - ); + return node.value && ["not", "and", "or"].includes(node.value.toLowerCase()); } function isColorAdjusterFuncNode(node) { @@ -381,7 +376,7 @@ function isColorAdjusterFuncNode(node) { return false; } - return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1; + return colorAdjusterFunctions.includes(node.value.toLowerCase()); } module.exports = { diff --git a/src/language-handlebars/printer-glimmer.js b/src/language-handlebars/printer-glimmer.js index 55631ea7b..6fd2a9abf 100644 --- a/src/language-handlebars/printer-glimmer.js +++ b/src/language-handlebars/printer-glimmer.js @@ -68,7 +68,7 @@ function print(path, options, print) { } case "ElementNode": { const tagFirstChar = n.tag[0]; - const isLocal = n.tag.indexOf(".") !== -1; + const isLocal = n.tag.includes("."); const isGlimmerComponent = tagFirstChar.toUpperCase() === tagFirstChar || isLocal; const hasChildren = n.children.length > 0; @@ -79,7 +79,7 @@ function print(path, options, print) { const isVoid = (isGlimmerComponent && (!hasChildren || !hasNonWhitespaceChildren)) || - voidTags.indexOf(n.tag) !== -1; + voidTags.includes(n.tag); const closeTagForNoBreak = isVoid ? concat([" />", softline]) : ">"; const closeTagForBreak = isVoid ? "/>" : ">"; const getParams = (path, print) => @@ -275,7 +275,7 @@ function print(path, options, print) { // preserve a space inside of an attribute node where whitespace present, // when next to mustache statement. - const inAttrNode = path.stack.indexOf("attributes") >= 0; + const inAttrNode = path.stack.includes("attributes"); if (inAttrNode) { const parentNode = path.getParentNode(0); const isConcat = parentNode.type === "ConcatStatement"; @@ -334,7 +334,7 @@ function print(path, options, print) { ); } case "MustacheCommentStatement": { - const dashes = n.value.indexOf("}}") > -1 ? "--" : ""; + const dashes = n.value.includes("}}") ? "--" : ""; return concat(["{{!", dashes, n.value, dashes, "}}"]); } case "PathExpression": { diff --git a/src/language-html/printer-html.js b/src/language-html/printer-html.js index ebf2ce56b..02e45f3a3 100644 --- a/src/language-html/printer-html.js +++ b/src/language-html/printer-html.js @@ -631,7 +631,7 @@ function printOpeningTag(path, options, print) { typeof ignoreAttributeData === "boolean" ? () => ignoreAttributeData : Array.isArray(ignoreAttributeData) - ? attr => ignoreAttributeData.indexOf(attr.rawName) !== -1 + ? attr => ignoreAttributeData.includes(attr.rawName) : () => false; return path.map(attrPath => { const attr = attrPath.getValue(); diff --git a/src/language-html/utils.js b/src/language-html/utils.js index 0b7827312..a923aeb8e 100644 --- a/src/language-html/utils.js +++ b/src/language-html/utils.js @@ -62,13 +62,13 @@ function shouldPreserveContent(node, options) { options.parser === "vue" && node.type === "element" && node.parent.type === "root" && - [ + ![ "template", "style", "script", // vue parser can be used for vue dom template as well, so we should still format top-level "html" - ].indexOf(node.fullName) === -1 + ].includes(node.fullName) ) { return true; } @@ -272,7 +272,7 @@ function forceBreakContent(node) { forceBreakChildren(node) || (node.type === "element" && node.children.length !== 0 && - (["body", "script", "style"].indexOf(node.name) !== -1 || + (["body", "script", "style"].includes(node.name) || node.children.some(child => hasNonTextChild(child)))) || (node.firstChild && node.firstChild === node.lastChild && @@ -287,7 +287,7 @@ function forceBreakChildren(node) { return ( node.type === "element" && node.children.length !== 0 && - (["html", "head", "ul", "ol", "select"].indexOf(node.name) !== -1 || + (["html", "head", "ul", "ol", "select"].includes(node.name) || (node.cssDisplay.startsWith("table") && node.cssDisplay !== "table-cell")) ); } @@ -339,7 +339,7 @@ function preferHardlineAsSurroundingSpaces(node) { case "directive": return true; case "element": - return ["script", "select"].indexOf(node.name) !== -1; + return ["script", "select"].includes(node.name); } return false; } diff --git a/src/language-js/pragma.js b/src/language-js/pragma.js index 6bd14660c..ca67d5cc9 100644 --- a/src/language-js/pragma.js +++ b/src/language-js/pragma.js @@ -4,7 +4,7 @@ const docblock = require("jest-docblock"); function hasPragma(text) { const pragmas = Object.keys(docblock.parse(docblock.extract(text))); - return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1; + return pragmas.includes("prettier") || pragmas.includes("format"); } function insertPragma(text) { diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index df2dea511..bc61c4a51 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -3909,11 +3909,11 @@ function printJestEachTemplateLiteral(node, expressions, options) { const correspondingExpression = stringifiedExpressions[i - 1]; row.cells.push(correspondingExpression); - if (correspondingExpression.indexOf("\n") !== -1) { + if (correspondingExpression.includes("\n")) { row.hasLineBreak = true; } - if (node.quasis[i].value.raw.indexOf("\n") !== -1) { + if (node.quasis[i].value.raw.includes("\n")) { tableBody.push({ hasLineBreak: false, cells: [] }); } } diff --git a/src/language-js/utils.js b/src/language-js/utils.js index 6fb301d56..fb51d4f2d 100644 --- a/src/language-js/utils.js +++ b/src/language-js/utils.js @@ -298,7 +298,7 @@ function isSimpleFlowType(node) { return ( node && - flowTypeAnnotations.indexOf(node.type) !== -1 && + flowTypeAnnotations.includes(node.type) && !(node.type === "GenericTypeAnnotation" && node.typeParameters) ); } diff --git a/src/language-markdown/embed.js b/src/language-markdown/embed.js index d06de68f6..29261f35e 100644 --- a/src/language-markdown/embed.js +++ b/src/language-markdown/embed.js @@ -72,7 +72,7 @@ function embed(path, print, textToDoc, options) { const language = supportInfo.languages.find( language => language.name.toLowerCase() === lang || - (language.aliases && language.aliases.indexOf(lang) !== -1) || + (language.aliases && language.aliases.includes(lang)) || (language.extensions && language.extensions.find(ext => ext.substring(1) === lang)) ); diff --git a/src/language-markdown/parser-markdown.js b/src/language-markdown/parser-markdown.js index 5a33dc8a2..2881da96d 100644 --- a/src/language-markdown/parser-markdown.js +++ b/src/language-markdown/parser-markdown.js @@ -54,7 +54,7 @@ function htmlToJsx() { if ( node.type !== "html" || node.value.match(mdx.COMMENT_REGEX) || - INLINE_NODE_WRAPPER_TYPES.indexOf(parent.type) !== -1 + INLINE_NODE_WRAPPER_TYPES.includes(parent.type) ) { return node; } diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index dc588f1ce..d00487ed4 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -65,7 +65,7 @@ function genericPrint(path, options, print) { } return concat([ normalizeDoc(printRoot(path, options, print)), - TRAILING_HARDLINE_NODES.indexOf(getLastDescendantNode(node).type) === -1 + !TRAILING_HARDLINE_NODES.includes(getLastDescendantNode(node).type) ? hardline : "" ]); @@ -482,7 +482,7 @@ function getAncestorCounter(path, typeOrTypes) { let ancestorNode; while ((ancestorNode = path.getParentNode(++counter))) { - if (types.indexOf(ancestorNode.type) !== -1) { + if (types.includes(ancestorNode.type)) { return counter; } } @@ -717,7 +717,7 @@ function printChildren(path, options, print, events) { if ( lastChildNode && - TRAILING_HARDLINE_NODES.indexOf(lastChildNode.type) !== -1 + TRAILING_HARDLINE_NODES.includes(lastChildNode.type) ) { if (shouldPrePrintTripleHardline(childNode, data)) { parts.push(hardline); @@ -766,19 +766,18 @@ function isPrettierIgnore(node) { function shouldNotPrePrintHardline(node, data) { const isFirstNode = data.parts.length === 0; - const isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1; + const isInlineNode = INLINE_NODE_TYPES.includes(node.type); const isInlineHTML = node.type === "html" && - INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1; + INLINE_NODE_WRAPPER_TYPES.includes(data.parentNode.type); return isFirstNode || isInlineNode || isInlineHTML; } function shouldPrePrintDoubleHardline(node, data) { const isSequence = (data.prevNode && data.prevNode.type) === node.type; - const isSiblingNode = - isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1; + const isSiblingNode = isSequence && SIBLING_NODE_TYPES.includes(node.type); const isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose; diff --git a/src/language-yaml/printer-yaml.js b/src/language-yaml/printer-yaml.js index 96d757a2b..8ab01f211 100644 --- a/src/language-yaml/printer-yaml.js +++ b/src/language-yaml/printer-yaml.js @@ -670,7 +670,7 @@ function isAbsolutelyPrintedAsSingleLineNode(node, options) { switch (options.proseWrap) { case "never": - return node.value.indexOf("\n") === -1; + return !node.value.includes("\n"); case "always": return !/[\n ]/.test(node.value); // istanbul ignore next diff --git a/src/language-yaml/utils.js b/src/language-yaml/utils.js index 4a1e8d74c..8990f05c2 100644 --- a/src/language-yaml/utils.js +++ b/src/language-yaml/utils.js @@ -22,7 +22,7 @@ function isNode(value, types) { return ( value && typeof value.type === "string" && - (!types || types.indexOf(value.type) !== -1) + (!types || types.includes(value.type)) ); } diff --git a/src/main/core.js b/src/main/core.js index 0f37afe6a..4d6e98a61 100644 --- a/src/main/core.js +++ b/src/main/core.js @@ -90,7 +90,7 @@ function coreFormat(text, opts, addAlignmentSize) { opts.endOfLine === "lf" ? doc : mapDoc(doc, currentDoc => - typeof currentDoc === "string" && currentDoc.indexOf("\n") !== -1 + typeof currentDoc === "string" && currentDoc.includes("\n") ? currentDoc.replace(/\n/g, eol) : currentDoc ), @@ -167,7 +167,7 @@ function coreFormat(text, opts, addAlignmentSize) { let cursorOffset = newCursorNodeStart; for (const entry of cursorNodeDiff) { if (entry.removed) { - if (entry.value.indexOf(CURSOR) > -1) { + if (entry.value.includes(CURSOR)) { break; } } else { @@ -293,7 +293,7 @@ function format(text, opts) { const hasRangeEnd = opts.rangeEnd < text.length; // get rid of CR/CRLF parsing - if (text.indexOf("\r") !== -1) { + if (text.includes("\r")) { const offsetKeys = [ hasCursor && "cursorOffset", hasRangeStart && "rangeStart", @@ -372,7 +372,7 @@ module.exports = { parse(text, opts, massage) { opts = normalizeOptions(opts); - if (text.indexOf("\r") !== -1) { + if (text.includes("\r")) { text = text.replace(/\r\n?/g, "\n"); } const parsed = parser.parse(text, opts); diff --git a/src/main/options-normalizer.js b/src/main/options-normalizer.js index a46a579df..73c8eb695 100644 --- a/src/main/options-normalizer.js +++ b/src/main/options-normalizer.js @@ -26,7 +26,7 @@ class FlagSchema extends vnopts.ChoiceSchema { if ( typeof value === "string" && value.length !== 0 && - this._flags.indexOf(value) === -1 + !this._flags.includes(value) ) { const suggestion = this._flags.find(flag => leven(flag, value) < 3); if (suggestion) { @@ -57,7 +57,7 @@ function normalizeOptions( ? vnopts.levenUnknownHandler : Array.isArray(passThrough) ? (key, value) => - passThrough.indexOf(key) === -1 ? undefined : { [key]: value } + !passThrough.includes(key) ? undefined : { [key]: value } : (key, value) => ({ [key]: value }); const descriptor = isCLI ? cliDescriptor : vnopts.apiDescriptor; diff --git a/src/main/options.js b/src/main/options.js index 0e01509c0..ebddeaa14 100644 --- a/src/main/options.js +++ b/src/main/options.js @@ -176,9 +176,9 @@ function inferParser(filepath, plugins) { language.extensions.some(extension => filename.endsWith(extension))) || (language.filenames && language.filenames.find(name => name.toLowerCase() === filename)) || - (filename.indexOf(".") === -1 && + (!filename.includes(".") && language.interpreters && - language.interpreters.indexOf(getInterpreter(filepath)) !== -1)) + language.interpreters.includes(getInterpreter(filepath)))) ); return language && language.parsers[0]; diff --git a/src/main/range-util.js b/src/main/range-util.js index ac80f89bd..657a52f97 100644 --- a/src/main/range-util.js +++ b/src/main/range-util.js @@ -138,11 +138,11 @@ function isSourceElement(opts, node) { case "flow": case "babel": case "typescript": - return jsSourceElements.indexOf(node.type) > -1; + return jsSourceElements.includes(node.type); case "json": - return jsonSourceElements.indexOf(node.type) > -1; + return jsonSourceElements.includes(node.type); case "graphql": - return graphqlSourceElements.indexOf(node.kind) > -1; + return graphqlSourceElements.includes(node.kind); case "vue": return node.tag !== "root"; } diff --git a/src/main/support.js b/src/main/support.js index 15c428064..2674fea32 100644 --- a/src/main/support.js +++ b/src/main/support.js @@ -96,7 +96,7 @@ function getSupportInfo(version, opts) { } // "babylon" was renamed to "babel" in 1.16.0 - if (useBabylonParser && language.parsers.indexOf("babel") !== -1) { + if (useBabylonParser && language.parsers.includes("babel")) { return Object.assign({}, language, { parsers: language.parsers.map(parser => parser === "babel" ? "babylon" : parser diff --git a/tests_integration/path-serializer.js b/tests_integration/path-serializer.js index da80071ce..089c88dc8 100644 --- a/tests_integration/path-serializer.js +++ b/tests_integration/path-serializer.js @@ -2,7 +2,7 @@ const replaceCWD = text => { const cwd = process.cwd(); - while (text.indexOf(cwd) !== -1) { + while (text.includes(cwd)) { text = text.replace(cwd, ""); } @@ -12,7 +12,7 @@ const replaceCWD = text => { module.exports = { test: value => typeof value === "string" && - (value.indexOf("\\") > -1 || value.indexOf(process.cwd()) > -1), + (value.includes("\\") || value.includes(process.cwd())), print: (value, serializer) => serializer(replaceCWD(value).replace(/\\/g, "/")) }; diff --git a/website/playground/urlHash.js b/website/playground/urlHash.js index 530f65015..b37cd4e6b 100644 --- a/website/playground/urlHash.js +++ b/website/playground/urlHash.js @@ -7,10 +7,9 @@ export function read() { } // backwards support for old json encoded URIComponent - const decode = - hash.indexOf("%7B%22") !== -1 - ? decodeURIComponent - : LZString.decompressFromEncodedURIComponent; + const decode = hash.includes("%7B%22") + ? decodeURIComponent + : LZString.decompressFromEncodedURIComponent; try { return JSON.parse(decode(hash)); diff --git a/yarn.lock b/yarn.lock index 6fc5dca10..b3ff0d44a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -781,6 +781,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.7.tgz#4f2563bad652b2acb1722d7e7aae2b0ff62d192c" integrity sha512-1YKeT4JitGgE4SOzyB9eMwO0nGVNkNEsm9qlIt1Lqm/tG2QEiSMTD4kS3aO6L+w5SClLVxALmIBESK6Mk5wX0A== +"@types/normalize-package-data@^2.4.0": + version "2.4.0" + resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" + integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== + "@types/resolve@0.0.8": version "0.0.8" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" @@ -1834,6 +1839,13 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +clean-regexp@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/clean-regexp/-/clean-regexp-1.0.0.tgz#8df7c7aae51fd36874e8f8d05b9180bc11a3fed7" + integrity sha1-jffHquUf02h06PjQW5GAvBGj/tc= + dependencies: + escape-string-regexp "^1.0.5" + clean-stack@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" @@ -2434,6 +2446,14 @@ escodegen@^1.9.0: optionalDependencies: source-map "~0.6.1" +eslint-ast-utils@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/eslint-ast-utils/-/eslint-ast-utils-1.1.0.tgz#3d58ba557801cfb1c941d68131ee9f8c34bd1586" + integrity sha512-otzzTim2/1+lVrlH19EfQQJEhVJSu0zOb9ygb3iapN6UlyaDtyRq4b5U1FuW0v1lRa9Fp/GJyHkSwm6NqABgCA== + dependencies: + lodash.get "^4.4.2" + lodash.zip "^4.2.0" + eslint-config-prettier@6.5.0: version "6.5.0" resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.5.0.tgz#aaf9a495e2a816865e541bfdbb73a65cc162b3eb" @@ -2524,6 +2544,28 @@ eslint-plugin-react@7.16.0: prop-types "^15.7.2" resolve "^1.12.0" +eslint-plugin-unicorn@13.0.0: + version "13.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-13.0.0.tgz#3d73a17cc34ade1aaa02655ae78bbd8a2053fa81" + integrity sha512-9CQk0v74vQpETMt6iqNgjf3IbWEFhrT0sjaLnjkl9SF3rJH6ZL9f7H42BXJ6LPENQR97QzhrIvB8VG0nD05wxQ== + dependencies: + ci-info "^2.0.0" + clean-regexp "^1.0.0" + eslint-ast-utils "^1.1.0" + eslint-template-visitor "^1.1.0" + import-modules "^2.0.0" + lodash.camelcase "^4.3.0" + lodash.defaultsdeep "^4.6.1" + lodash.kebabcase "^4.1.1" + lodash.snakecase "^4.1.1" + lodash.topairs "^4.3.0" + lodash.upperfirst "^4.3.1" + read-pkg-up "^7.0.0" + regexpp "^3.0.0" + reserved-words "^0.1.2" + safe-regex "^2.1.1" + semver "^6.3.0" + eslint-scope@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848" @@ -2540,6 +2582,15 @@ eslint-scope@^5.0.0: esrecurse "^4.1.0" estraverse "^4.1.1" +eslint-template-visitor@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/eslint-template-visitor/-/eslint-template-visitor-1.1.0.tgz#f090d124d1a52e05552149fc50468ed59608b166" + integrity sha512-Lmy6QVlmFiIGl5fPi+8ACnov3sare+0Ouf7deJAGGhmUfeWJ5fVarELUxZRpsZ9sHejiJUq8626d0dn9uvcZTw== + dependencies: + eslint-visitor-keys "^1.1.0" + espree "^6.1.1" + multimap "^1.0.2" + eslint-utils@^1.4.3: version "1.4.3" resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.3.tgz#74fec7c54d0776b6f67e0251040b5806564e981f" @@ -2595,7 +2646,7 @@ eslint@6.6.0: text-table "^0.2.0" v8-compile-cache "^2.0.3" -espree@^6.1.2: +espree@^6.1.1, espree@^6.1.2: version "6.1.2" resolved "https://registry.yarnpkg.com/espree/-/espree-6.1.2.tgz#6c272650932b4f91c3714e5e7b5f5e2ecf47262d" integrity sha512-2iUPuuPP+yW1PZaMSDM9eyVf8D5P0Hi8h83YtZ5bPc/zHYjII5khoixIUTMO794NOY8F/ThF1Bo8ncZILarUTA== @@ -2917,7 +2968,7 @@ find-up@^3.0.0: dependencies: locate-path "^3.0.0" -find-up@^4.0.0: +find-up@^4.0.0, find-up@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== @@ -3380,6 +3431,11 @@ import-local@^1.0.0: pkg-dir "^2.0.0" resolve-cwd "^2.0.0" +import-modules@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/import-modules/-/import-modules-2.0.0.tgz#9c1e13b4e7a15682f70a6e3fa29534e4540cfc5d" + integrity sha512-iczM/v9drffdNnABOKwj0f9G3cFDon99VcG1mxeBsdqnbd+vnQ5c2uAiCHNQITqFTOPaEvwg3VjoWCur0uHLEw== + imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" @@ -4562,10 +4618,40 @@ locate-path@^5.0.0: dependencies: p-locate "^4.1.0" +lodash.camelcase@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" + integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY= + +lodash.defaultsdeep@^4.6.1: + version "4.6.1" + resolved "https://registry.yarnpkg.com/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz#512e9bd721d272d94e3d3a63653fa17516741ca6" + integrity sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA== + +lodash.get@^4.4.2: + version "4.4.2" + resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" + integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= + +lodash.kebabcase@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36" + integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY= + +lodash.snakecase@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d" + integrity sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40= + lodash.sortby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" +lodash.topairs@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.topairs/-/lodash.topairs-4.3.0.tgz#3b6deaa37d60fb116713c46c5f17ea190ec48d64" + integrity sha1-O23qo31g+xFnE8RsXxfqGQ7EjWQ= + lodash.unescape@4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" @@ -4574,6 +4660,16 @@ lodash.uniqby@4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz#d99c07a669e9e6d24e1362dfe266c67616af1302" +lodash.upperfirst@^4.3.1: + version "4.3.1" + resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce" + integrity sha1-E2Xt9DFIBIHvDRxolXpe2Z1J984= + +lodash.zip@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020" + integrity sha1-7GZi5IlkCO1KtsVCo5kLcswIACA= + lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4: version "4.17.15" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" @@ -4912,6 +5008,11 @@ ms@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" +multimap@^1.0.2: + version "1.1.0" + resolved "https://registry.yarnpkg.com/multimap/-/multimap-1.1.0.tgz#5263febc085a1791c33b59bb3afc6a76a2a10ca8" + integrity sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw== + mute-stream@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" @@ -5049,6 +5150,16 @@ normalize-package-data@^2.3.2, normalize-package-data@^2.3.4: semver "2 || 3 || 4 || 5" validate-npm-package-license "^3.0.1" +normalize-package-data@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8" + integrity sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA== + dependencies: + hosted-git-info "^2.1.4" + resolve "^1.10.0" + semver "2 || 3 || 4 || 5" + validate-npm-package-license "^3.0.1" + normalize-path@3.0.0, normalize-path@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" @@ -5374,6 +5485,16 @@ parse-json@^4.0.0: error-ex "^1.3.1" json-parse-better-errors "^1.0.1" +parse-json@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.0.0.tgz#73e5114c986d143efa3712d4ea24db9a4266f60f" + integrity sha512-OOY5b7PAEFV0E2Fir1KOkxchnZNCdowAJgQ5NuxjpBKTRP3pQhwkrkxqQjeoKJ+fO7bCpmIZaogI4eZGDMEGOw== + dependencies: + "@babel/code-frame" "^7.0.0" + error-ex "^1.3.1" + json-parse-better-errors "^1.0.1" + lines-and-columns "^1.1.6" + parse-srcset@ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee: version "1.0.2" resolved "https://codeload.github.com/ikatyang/parse-srcset/tar.gz/54eb9c1cb21db5c62b4d0e275d7249516df6f0ee" @@ -5765,6 +5886,15 @@ read-pkg-up@^2.0.0: find-up "^2.0.0" read-pkg "^2.0.0" +read-pkg-up@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-7.0.0.tgz#3f3e53858ec5ae5e6fe14bc479da0a7c98f85ff3" + integrity sha512-t2ODkS/vTTcRlKwZiZsaLGb5iwfx9Urp924aGzVyboU6+7Z2i6eGr/G1Z4mjvwLLQV3uFOBKobNRGM3ux2PD/w== + dependencies: + find-up "^4.1.0" + read-pkg "^5.2.0" + type-fest "^0.8.1" + read-pkg@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-1.1.0.tgz#f5ffaa5ecd29cb31c0474bca7d756b6bb29e3f28" @@ -5781,6 +5911,16 @@ read-pkg@^2.0.0: normalize-package-data "^2.3.2" path-type "^2.0.0" +read-pkg@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc" + integrity sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg== + dependencies: + "@types/normalize-package-data" "^2.4.0" + normalize-package-data "^2.5.0" + parse-json "^5.0.0" + type-fest "^0.6.0" + "readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.6: version "2.3.6" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" @@ -5870,6 +6010,11 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" +regexp-tree@~0.1.1: + version "0.1.16" + resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.16.tgz#0715feadb6f766aad7eac5ef4287d2c39acf2fc5" + integrity sha512-nXWhGJLTWLNdhWF1uqoXQgAOgv8mQGpgXTOk8BWp08YMOKCtn74VoyOJ+AXZ68Dj50Myd+msYs+aGRBzWJ5dJA== + regexp-util@1.2.2, regexp-util@^1.2.0, regexp-util@^1.2.1: version "1.2.2" resolved "https://registry.yarnpkg.com/regexp-util/-/regexp-util-1.2.2.tgz#5cf599134921eb0d776e41d41e9c0da33f0fa2fc" @@ -5881,6 +6026,11 @@ regexpp@^2.0.1: resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== +regexpp@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.0.0.tgz#dd63982ee3300e67b41c1956f850aa680d9d330e" + integrity sha512-Z+hNr7RAVWxznLPuA7DIh8UNX1j9CDrUQxskw9IrBE1Dxue2lyXT+shqEIeLUjrokxIP8CMy1WkjgG3rTsd5/g== + regexpu-core@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-4.6.0.tgz#2037c18b327cfce8a6fea2a4ec441f2432afb8b6" @@ -6001,6 +6151,11 @@ require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" +reserved-words@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/reserved-words/-/reserved-words-0.1.2.tgz#00a0940f98cd501aeaaac316411d9adc52b31ab1" + integrity sha1-AKCUD5jNUBrqqsMWQR2a3FKzGrE= + resolve-cwd@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a" @@ -6024,7 +6179,7 @@ resolve@1.1.7: version "1.1.7" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" -resolve@1.12.0, resolve@^1.1.6, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.12.0, resolve@^1.3.2, resolve@^1.5.0: +resolve@1.12.0, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.12.0, resolve@^1.3.2, resolve@^1.5.0: version "1.12.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.0.tgz#3fc644a35c84a48554609ff26ec52b66fa577df6" integrity sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w== @@ -6187,6 +6342,13 @@ safe-regex@^1.1.0: dependencies: ret "~0.1.10" +safe-regex@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/safe-regex/-/safe-regex-2.1.1.tgz#f7128f00d056e2fe5c11e81a1324dd974aadced2" + integrity sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A== + dependencies: + regexp-tree "~0.1.1" + "safer-buffer@>= 2.1.2 < 3", safer-buffer@^2.0.2, safer-buffer@^2.1.0, safer-buffer@~2.1.0: version "2.1.2" resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" @@ -6926,6 +7088,16 @@ type-fest@^0.5.2: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.5.2.tgz#d6ef42a0356c6cd45f49485c3b6281fc148e48a2" integrity sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw== +type-fest@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b" + integrity sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== + +type-fest@^0.8.1: + version "0.8.1" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" + integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== + typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"