Skip to content

Commit 6a96b97

Browse files
authored
Enable eslint rule no-useless-escape (#55138)
1 parent 23eabea commit 6a96b97

32 files changed

+50
-51
lines changed

.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
],
105105

106106
// Todo: For each of these, investigate whether we want to enable them ✨
107-
"no-useless-escape": "off",
108107
"prefer-rest-params": "off",
109108
"prefer-spread": "off",
110109
"@typescript-eslint/no-unused-vars": "off",

scripts/build/tests.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,5 @@ function deleteTemporaryProjectOutput() {
222222
* @param {string} text
223223
*/
224224
function regExpEscape(text) {
225-
return text.replace(/[.*+?^${}()|\[\]\\]/g, "\\$&");
225+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
226226
}

scripts/configurePrerelease.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, nightlyPatc
9090
* @returns {{ majorMinor: string, patch: string }}
9191
*/
9292
function parsePackageJsonVersion(versionString) {
93-
const versionRgx = /(\d+\.\d+)\.(\d+)($|\-)/;
93+
const versionRgx = /(\d+\.\d+)\.(\d+)($|-)/;
9494
const match = versionString.match(versionRgx);
9595
assert(match !== null, "package.json 'version' should match " + versionRgx.toString());
9696
return { majorMinor: match[1], patch: match[2] };

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ export function toLowerCase(x: string) {
19481948
//
19491949
// But to avoid having to do string building for most common cases, also ignore
19501950
// a-z, 0-9, \u0131, \u00DF, \, /, ., : and space
1951-
const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_\. ]+/g;
1951+
const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_. ]+/g;
19521952
/**
19531953
* Case insensitive file systems have descripencies in how they handle some characters (eg. turkish Upper case I with dot on top - \u0130)
19541954
* This function is used in places where we want to make file name as a key on these systems

src/compiler/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export namespace Debug {
366366
}
367367
else {
368368
const text = Function.prototype.toString.call(func);
369-
const match = /^function\s+([\w\$]+)\s*\(/.exec(text);
369+
const match = /^function\s+([\w$]+)\s*\(/.exec(text);
370370
return match ? match[1] : "";
371371
}
372372
}

src/compiler/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,9 +2493,9 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
24932493
}
24942494

24952495
function emitPlaceholder(hint: EmitHint, node: Node, snippet: Placeholder) {
2496-
nonEscapingWrite(`\$\{${snippet.order}:`); // `${2:`
2496+
nonEscapingWrite(`$\{${snippet.order}:`); // `${2:`
24972497
pipelineEmitWithHintWorker(hint, node, /*allowSnippets*/ false); // `...`
2498-
nonEscapingWrite(`\}`); // `}`
2498+
nonEscapingWrite(`}`); // `}`
24992499
// `${2:...}`
25002500
}
25012501

@@ -2505,7 +2505,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
25052505
`A tab stop cannot be attached to a node of kind ${Debug.formatSyntaxKind(node.kind)}.`);
25062506
Debug.assert(hint !== EmitHint.EmbeddedStatement,
25072507
`A tab stop cannot be attached to an embedded statement.`);
2508-
nonEscapingWrite(`\$${snippet.order}`);
2508+
nonEscapingWrite(`$${snippet.order}`);
25092509
}
25102510

25112511
//

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ export function createScanner(languageVersion: ScriptTarget,
15161516
case CharacterCodes.r:
15171517
return "\r";
15181518
case CharacterCodes.singleQuote:
1519-
return "\'";
1519+
return "'";
15201520
case CharacterCodes.doubleQuote:
15211521
return "\"";
15221522
case CharacterCodes.u:

src/compiler/semver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
//
1919
// NOTE: We differ here in that we allow X and X.Y, with missing parts having the default
2020
// value of `0`.
21-
const versionRegExp = /^(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\-([a-z0-9-.]+))?(?:\+([a-z0-9-.]+))?)?)?$/i;
21+
const versionRegExp = /^(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:-([a-z0-9-.]+))?(?:\+([a-z0-9-.]+))?)?)?$/i;
2222

2323
// https://semver.org/#spec-item-9
2424
// > A pre-release version MAY be denoted by appending a hyphen and a series of dot separated
@@ -427,4 +427,4 @@ function formatAlternative(comparators: readonly Comparator[]) {
427427

428428
function formatComparator(comparator: Comparator) {
429429
return `${comparator.operator}${comparator.operand}`;
430-
}
430+
}

src/compiler/utilities.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5813,10 +5813,10 @@ export function hasInvalidEscape(template: TemplateLiteral): boolean {
58135813
// the language service. These characters should be escaped when printing, and if any characters are added,
58145814
// the map below must be updated. Note that this regexp *does not* include the 'delete' character.
58155815
// There is no reason for this other than that JSON.stringify does not handle it either.
5816-
const doubleQuoteEscapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
5817-
const singleQuoteEscapedCharsRegExp = /[\\\'\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
5816+
const doubleQuoteEscapedCharsRegExp = /[\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
5817+
const singleQuoteEscapedCharsRegExp = /[\\'\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
58185818
// Template strings preserve simple LF newlines, still encode CRLF (or CR)
5819-
const backtickQuoteEscapedCharsRegExp = /\r\n|[\\\`\u0000-\u001f\t\v\f\b\r\u2028\u2029\u0085]/g;
5819+
const backtickQuoteEscapedCharsRegExp = /\r\n|[\\`\u0000-\u001f\t\v\f\b\r\u2028\u2029\u0085]/g;
58205820
const escapedCharsMap = new Map(Object.entries({
58215821
"\t": "\\t",
58225822
"\v": "\\v",
@@ -5826,8 +5826,8 @@ const escapedCharsMap = new Map(Object.entries({
58265826
"\n": "\\n",
58275827
"\\": "\\\\",
58285828
"\"": "\\\"",
5829-
"\'": "\\\'",
5830-
"\`": "\\\`",
5829+
"'": "\\'",
5830+
"`": "\\`",
58315831
"\u2028": "\\u2028", // lineSeparator
58325832
"\u2029": "\\u2029", // paragraphSeparator
58335833
"\u0085": "\\u0085", // nextLine
@@ -5883,11 +5883,11 @@ export function escapeNonAsciiString(s: string, quoteChar?: CharacterCodes.doubl
58835883
// paragraphSeparator, and nextLine. The latter three are just desirable to suppress new lines in
58845884
// the language service. These characters should be escaped when printing, and if any characters are added,
58855885
// the map below must be updated.
5886-
const jsxDoubleQuoteEscapedCharsRegExp = /[\"\u0000-\u001f\u2028\u2029\u0085]/g;
5887-
const jsxSingleQuoteEscapedCharsRegExp = /[\'\u0000-\u001f\u2028\u2029\u0085]/g;
5886+
const jsxDoubleQuoteEscapedCharsRegExp = /["\u0000-\u001f\u2028\u2029\u0085]/g;
5887+
const jsxSingleQuoteEscapedCharsRegExp = /['\u0000-\u001f\u2028\u2029\u0085]/g;
58885888
const jsxEscapedCharsMap = new Map(Object.entries({
58895889
"\"": """,
5890-
"\'": "'"
5890+
"'": "'"
58915891
}));
58925892

58935893
function encodeJsxCharacterEntity(charCode: number): string {
@@ -8848,7 +8848,7 @@ export function tryRemoveDirectoryPrefix(path: string, dirPath: string, getCanon
88488848
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
88498849
// It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
88508850
// proof.
8851-
const reservedCharacterPattern = /[^\w\s\/]/g;
8851+
const reservedCharacterPattern = /[^\w\s/]/g;
88528852

88538853
/** @internal */
88548854
export function regExpEscape(text: string) {

src/compiler/utilitiesPublic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ export function validateLocaleAndSetLanguage(
624624
sys: { getExecutingFilePath(): string, resolvePath(path: string): string, fileExists(fileName: string): boolean, readFile(fileName: string): string | undefined },
625625
errors?: Diagnostic[]) {
626626
const lowerCaseLocale = locale.toLowerCase();
627-
const matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(lowerCaseLocale);
627+
const matchResult = /^([a-z]+)([_-]([a-z]+))?$/.exec(lowerCaseLocale);
628628

629629
if (!matchResult) {
630630
if (errors) {

0 commit comments

Comments
 (0)