Enable regexp/no-useless-lazy rule (#11014)
This commit is contained in:
1 parent
82e6937d50
commit
294a02b979
11 files changed
+15
-14
No files matched your search
@@ -113,6 +113,7 @@ module.exports = {
|
||||
strictTypes: false,
|
||||
},
|
||||
],
|
||||
"regexp/no-useless-lazy": "error",
|
||||
|
||||
"unicorn/better-regex": "error",
|
||||
"unicorn/explicit-length-check": "error",
|
||||
|
||||
@@ -23,7 +23,7 @@ async function update() {
|
||||
githubPage
|
||||
.replace(/\n/g, "")
|
||||
.match(
|
||||
/<svg.*?octicon-code-square.*?>.*?<\/svg>\s*([\d,]+?)\s*Repositories\s*<\/a>/
|
||||
/<svg.*?octicon-code-square.*?>.*?<\/svg>\s*([\d,]+)\s*Repositories\s*<\/a>/
|
||||
)[1]
|
||||
.replace(/,/g, "")
|
||||
);
|
||||
|
||||
@@ -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}`)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -275,7 +275,7 @@ function isSCSSNestedPropertyNode(node) {
|
||||
|
||||
return node.selector
|
||||
.replace(/\/\*.*?\*\//, "")
|
||||
.replace(/\/\/.*?\n/, "")
|
||||
.replace(/\/\/.*\n/, "")
|
||||
.trim()
|
||||
.endsWith(":");
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ const {
|
||||
const parseFunctions = [
|
||||
{
|
||||
// <!--[if ... ]> ... <![endif]-->
|
||||
regex: /^(\[if([^\]]*?)]>)(.*?)<!\s*\[endif]$/s,
|
||||
regex: /^(\[if([^\]]*)]>)(.*?)<!\s*\[endif]$/s,
|
||||
parse: parseIeConditionalStartEndComment,
|
||||
},
|
||||
{
|
||||
// <!--[if ... ]><!-->
|
||||
regex: /^\[if([^\]]*?)]><!$/,
|
||||
regex: /^\[if([^\]]*)]><!$/,
|
||||
parse: parseIeConditionalStartComment,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -284,7 +284,7 @@ function embed(path, print, textToDoc, options) {
|
||||
if (parser) {
|
||||
const value =
|
||||
parser === "markdown"
|
||||
? dedentString(node.value.replace(/^[^\S\n]*?\n/, ""))
|
||||
? dedentString(node.value.replace(/^[^\S\n]*\n/, ""))
|
||||
: node.value;
|
||||
const textToDocOptions = { parser, __embeddedInHtml: true };
|
||||
if (options.parser === "html" && parser === "babel") {
|
||||
|
||||
@@ -55,7 +55,7 @@ function genericPrint(path, options, print) {
|
||||
case "text": {
|
||||
if (node.parent.type === "interpolation") {
|
||||
// replace the trailing literalline with hardline for better readability
|
||||
const trailingNewlineRegex = /\n[^\S\n]*?$/;
|
||||
const trailingNewlineRegex = /\n[^\S\n]*$/;
|
||||
const hasTrailingNewline = trailingNewlineRegex.test(node.value);
|
||||
const value = hasTrailingNewline
|
||||
? node.value.replace(trailingNewlineRegex, "")
|
||||
|
||||
@@ -73,10 +73,10 @@ function printVueBindings(value, textToDoc) {
|
||||
function isVueEventBindingExpression(eventBindingValue) {
|
||||
// https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/codegen/events.js#L3-L4
|
||||
// arrow function or anonymous function
|
||||
const fnExpRE = /^(?:[\w$]+|\([^)]*?\))\s*=>|^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();
|
||||
|
||||
@@ -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 ]+/);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user