diff --git a/.eslintrc.js b/.eslintrc.js index 4e8403735..c7ed3987e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -113,6 +113,7 @@ module.exports = { strictTypes: false, }, ], + "regexp/no-useless-lazy": "error", "unicorn/better-regex": "error", "unicorn/explicit-length-check": "error", diff --git a/scripts/release/steps/update-dependents-count.js b/scripts/release/steps/update-dependents-count.js index 7fa3e8037..1d402ed15 100644 --- a/scripts/release/steps/update-dependents-count.js +++ b/scripts/release/steps/update-dependents-count.js @@ -23,7 +23,7 @@ async function update() { githubPage .replace(/\n/g, "") .match( - /.*?<\/svg>\s*([\d,]+?)\s*Repositories\s*<\/a>/ + /.*?<\/svg>\s*([\d,]+)\s*Repositories\s*<\/a>/ )[1] .replace(/,/g, "") ); diff --git a/scripts/release/steps/update-version.js b/scripts/release/steps/update-version.js index 78b7004c2..5b9a8315d 100644 --- a/scripts/release/steps/update-version.js +++ b/scripts/release/steps/update-version.js @@ -16,7 +16,7 @@ async function bump({ version }) { content.replace(/^(\*\*Prettier ).*?(\*\*)$/m, `$1${version}$2`) ); processFile(".github/ISSUE_TEMPLATE/integration.md", (content) => - content.replace(/^(- Prettier Version: ).*?$/m, `$1${version}`) + content.replace(/^(- Prettier Version: ).*$/m, `$1${version}`) ); processFile("docs/install.md", (content) => content.replace(/^(npx prettier@)\S+/m, `$1${version}`) diff --git a/src/language-css/parser-postcss.js b/src/language-css/parser-postcss.js index 0d4bd19d3..81f319f9f 100644 --- a/src/language-css/parser-postcss.js +++ b/src/language-css/parser-postcss.js @@ -284,8 +284,8 @@ function parseMediaQuery(params) { return addTypePrefix(addMissingType(result), "media-"); } -const DEFAULT_SCSS_DIRECTIVE = /(\s*?)(!default).*$/; -const GLOBAL_SCSS_DIRECTIVE = /(\s*?)(!global).*$/; +const DEFAULT_SCSS_DIRECTIVE = /(\s*)(!default).*$/; +const GLOBAL_SCSS_DIRECTIVE = /(\s*)(!global).*$/; function parseNestedCSS(node, options) { if (node && typeof node === "object") { @@ -455,7 +455,7 @@ function parseNestedCSS(node, options) { // only css support custom-selector if (options.parser === "css" && node.name === "custom-selector") { - const customSelector = node.params.match(/:--\S+?\s+/)[0].trim(); + const customSelector = node.params.match(/:--\S+\s+/)[0].trim(); node.customSelector = customSelector; node.selector = parseSelector( node.params.slice(customSelector.length).trim() diff --git a/src/language-css/utils.js b/src/language-css/utils.js index df9a5867d..775a4ee21 100644 --- a/src/language-css/utils.js +++ b/src/language-css/utils.js @@ -275,7 +275,7 @@ function isSCSSNestedPropertyNode(node) { return node.selector .replace(/\/\*.*?\*\//, "") - .replace(/\/\/.*?\n/, "") + .replace(/\/\/.*\n/, "") .trim() .endsWith(":"); } diff --git a/src/language-html/conditional-comment.js b/src/language-html/conditional-comment.js index d0f1eb5a3..bf00b3847 100644 --- a/src/language-html/conditional-comment.js +++ b/src/language-html/conditional-comment.js @@ -9,12 +9,12 @@ const { const parseFunctions = [ { // - regex: /^(\[if([^\]]*?)]>)(.*?))(.*?) - regex: /^\[if([^\]]*?)]>|^function\s*\(/; + const fnExpRE = /^(?:[\w$]+|\([^)]*\))\s*=>|^function\s*\(/; // simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b]) const simplePathRE = - /^[$A-Z_a-z][\w$]*(?:\.[$A-Z_a-z][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[$A-Z_a-z][\w$]*])*$/; + /^[$A-Z_a-z][\w$]*(?:\.[$A-Z_a-z][\w$]*|\['[^']*']|\["[^"]*"]|\[\d+]|\[[$A-Z_a-z][\w$]*])*$/; // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104 const value = eventBindingValue.trim(); diff --git a/src/language-html/utils.js b/src/language-html/utils.js index 031cf8060..5d9e822d9 100644 --- a/src/language-html/utils.js +++ b/src/language-html/utils.js @@ -30,7 +30,7 @@ const htmlTrimStart = (string) => string.replace(/^[\t\n\f\r ]+/, ""); const htmlTrimEnd = (string) => string.replace(/[\t\n\f\r ]+$/, ""); const htmlTrim = (string) => htmlTrimStart(htmlTrimEnd(string)); const htmlTrimLeadingBlankLines = (string) => - string.replace(/^[\t\f\r ]*?\n/g, ""); + string.replace(/^[\t\f\r ]*\n/g, ""); const htmlTrimPreserveIndentation = (string) => htmlTrimLeadingBlankLines(htmlTrimEnd(string)); const splitByHtmlWhitespace = (string) => string.split(/[\t\n\f\r ]+/); diff --git a/src/language-yaml/utils.js b/src/language-yaml/utils.js index 904ffc8ce..82a4a354f 100644 --- a/src/language-yaml/utils.js +++ b/src/language-yaml/utils.js @@ -251,7 +251,7 @@ function getBlockValueLineContents( : options.originalText .slice(node.position.start.offset, node.position.end.offset) // exclude open line `>` or `|` - .match(/^[^\n]*?\n(.*)$/s)[1]; + .match(/^[^\n]*\n(.*)$/s)[1]; const leadingSpaceCount = node.indent === null