Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable regexp/no-unused-capturing-group rule #11013

Merged
merged 4 commits into from Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -104,6 +104,7 @@ module.exports = {
allows: ["dotAll"],
},
],
"regexp/no-unused-capturing-group": "error",
"regexp/no-useless-flag": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion src/language-css/clean.js
Expand Up @@ -37,7 +37,7 @@ function clean(ast, newObj, parent) {
delete newObj.text;

// standalone pragma
if (/^\*\s*@(format|prettier)\s*$/.test(ast.text)) {
if (/^\*\s*@(?:format|prettier)\s*$/.test(ast.text)) {
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/language-css/parser-postcss.js
Expand Up @@ -515,7 +515,7 @@ function parseNestedCSS(node, options) {
}

if (name === "at-root") {
if (/^\(\s*(without|with)\s*:.+\)$/s.test(params)) {
if (/^\(\s*(?:without|with)\s*:.+\)$/s.test(params)) {
node.params = parseValue(params, options);
} else {
node.selector = parseSelector(params);
Expand Down
2 changes: 1 addition & 1 deletion src/language-css/utils.js
Expand Up @@ -89,7 +89,7 @@ function hasStringOrFunction(groupList) {

function isSCSS(parser, text) {
const hasExplicitParserChoice = parser === "less" || parser === "scss";
const IS_POSSIBLY_SCSS = /(\w\s*:\s*[^:}]+|#){|@import[^\n]+(?:url|,)/;
const IS_POSSIBLY_SCSS = /(?:\w\s*:\s*[^:}]+|#){|@import[^\n]+(?:url|,)/;
return hasExplicitParserChoice
? parser === "scss"
: IS_POSSIBLY_SCSS.test(text);
Expand Down
2 changes: 1 addition & 1 deletion src/language-graphql/pragma.js
@@ -1,7 +1,7 @@
"use strict";

function hasPragma(text) {
return /^\s*#[^\S\n]*@(format|prettier)\s*(\n|$)/.test(text);
return /^\s*#[^\S\n]*@(?:format|prettier)\s*(?:\n|$)/.test(text);
}

function insertPragma(text) {
Expand Down
2 changes: 1 addition & 1 deletion src/language-html/pragma.js
@@ -1,7 +1,7 @@
"use strict";

function hasPragma(text) {
return /^\s*<!--\s*@(format|prettier)\s*-->/.test(text);
return /^\s*<!--\s*@(?:format|prettier)\s*-->/.test(text);
}

function insertPragma(text) {
Expand Down
2 changes: 1 addition & 1 deletion src/language-html/syntax-vue.js
Expand Up @@ -73,7 +73,7 @@ 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$]*])*$/;
Expand Down
4 changes: 2 additions & 2 deletions src/language-js/parse/typescript.js
Expand Up @@ -63,9 +63,9 @@ function parse(text, parsers, opts) {
function isProbablyJsx(text) {
return new RegExp(
[
"(^[^\"'`]*</)", // Contains "</" when probably not in a string
"(?:^[^\"'`]*</)", // Contains "</" when probably not in a string
"|",
"(^[^/]{2}.*/>)", // Contains "/>" on line not starting with "//"
"(?:^[^/]{2}.*/>)", // Contains "/>" on line not starting with "//"
].join(""),
"m"
).test(text);
Expand Down
2 changes: 1 addition & 1 deletion src/language-js/print/angular.js
Expand Up @@ -54,7 +54,7 @@ function printAngular(path, options, print) {
"body"
);
case "NGMicrosyntaxKey":
return /^[$_a-z][\w$]*(-[$_a-z][\w$])*$/i.test(node.name)
return /^[$_a-z][\w$]*(?:-[$_a-z][\w$])*$/i.test(node.name)
? node.name
: JSON.stringify(node.name);
case "NGMicrosyntaxExpression":
Expand Down
2 changes: 1 addition & 1 deletion src/language-js/print/typescript.js
Expand Up @@ -467,7 +467,7 @@ function printTypescript(path, options, print) {
if (!isGlobalDeclaration) {
parts.push(
isExternalModule ||
/(^|\s)module(\s|$)/.test(textBetweenNodeAndItsId)
/(?:^|\s)module(?:\s|$)/.test(textBetweenNodeAndItsId)
? "module "
: "namespace "
);
Expand Down
8 changes: 4 additions & 4 deletions src/language-js/utils.js
Expand Up @@ -480,7 +480,7 @@ function isSimpleType(node) {
return false;
}

const unitTestRe = /^(skip|[fx]?(it|describe|test))$/;
const unitTestRe = /^(?:skip|[fx]?(?:it|describe|test))$/;

/**
* @param {{callee: MemberExpression | OptionalMemberExpression}} node
Expand All @@ -502,7 +502,7 @@ function isSkipOrOnlyBlock(node) {
* @returns {boolean}
*/
function isUnitTestSetUp(node) {
const unitTestSetUpRe = /^(before|after)(Each|All)$/;
const unitTestSetUpRe = /^(?:before|after)(?:Each|All)$/;
return (
node.callee.type === "Identifier" &&
unitTestSetUpRe.test(node.callee.name) &&
Expand Down Expand Up @@ -722,7 +722,7 @@ function isStringPropSafeToUnquote(node, options) {

// Matches “simple” numbers like `123` and `2.5` but not `1_000`, `1e+100` or `0b10`.
function isSimpleNumber(numberString) {
return /^(\d+|\d+\.\d+)$/.test(numberString);
return /^(?:\d+|\d+\.\d+)$/.test(numberString);
}

/**
Expand All @@ -741,7 +741,7 @@ function isJestEachTemplateLiteral(node, parentNode) {
*
* Ref: https://github.com/facebook/jest/pull/6102
*/
const jestEachTriggerRegex = /^[fx]?(describe|it|test)$/;
const jestEachTriggerRegex = /^[fx]?(?:describe|it|test)$/;
return (
parentNode.type === "TaggedTemplateExpression" &&
parentNode.quasi === node &&
Expand Down
2 changes: 1 addition & 1 deletion src/language-markdown/print-preprocess.js
Expand Up @@ -134,7 +134,7 @@ function transformIndentedCodeblockAndMarkItsParentList(ast, options) {
return mapAst(ast, (node, index, parentStack) => {
if (node.type === "code") {
// the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
const isIndented = /^\n?( {4,}|\t)/.test(
const isIndented = /^\n?(?: {4,}|\t)/.test(
options.originalText.slice(
node.position.start.offset,
node.position.end.offset
Expand Down
2 changes: 1 addition & 1 deletion src/language-markdown/printer-markdown.js
Expand Up @@ -142,7 +142,7 @@ function genericPrint(path, options, print) {

const proseWrap =
// leading char that may cause different syntax
nextNode && /^>|^([*+-]|#{1,6}|\d+[).])$/.test(nextNode.value)
nextNode && /^>|^(?:[*+-]|#{1,6}|\d+[).])$/.test(nextNode.value)
? "never"
: options.proseWrap;

Expand Down
4 changes: 2 additions & 2 deletions src/language-yaml/pragma.js
@@ -1,11 +1,11 @@
"use strict";

function isPragma(text) {
return /^\s*@(prettier|format)\s*$/.test(text);
return /^\s*@(?:prettier|format)\s*$/.test(text);
}

function hasPragma(text) {
return /^\s*#[^\S\n]*@(prettier|format)\s*?(\n|$)/.test(text);
return /^\s*#[^\S\n]*@(?:prettier|format)\s*?(?:\n|$)/.test(text);
}

function insertPragma(text) {
Expand Down
2 changes: 1 addition & 1 deletion src/language-yaml/printer-yaml.js
Expand Up @@ -387,7 +387,7 @@ function shouldPrintDocumentHeadEndMarker(
* preserve the first document head end marker
*/
(root.children[0] === document &&
/---(\s|$)/.test(
/---(?:\s|$)/.test(
options.originalText.slice(locStart(document), locStart(document) + 4)
)) ||
/**
Expand Down