Enable the ESLint no-useless-escape rule (PR 12551 follow-up)

Note that a number of these cases are covered by existing unit-tests, and a few others only matter for the development/build scripts.
Furthermore, I've also tried to the best of my ability to test each case *manually* to hopefully further reduce the likelihood of this patch introducing any bugs.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-useless-escape
This commit is contained in:
Jonas Jenwald 2020-11-07 12:59:53 +01:00
parent e3851a6765
commit 9602844368
9 changed files with 11 additions and 10 deletions

View File

@ -111,6 +111,7 @@
"no-useless-call": "error", "no-useless-call": "error",
"no-useless-catch": "error", "no-useless-catch": "error",
"no-useless-concat": "error", "no-useless-concat": "error",
"no-useless-escape": "error",
"no-useless-return": "error", "no-useless-return": "error",
"prefer-promise-reject-errors": "error", "prefer-promise-reject-errors": "error",
"wrap-iife": ["error", "any"], "wrap-iife": ["error", "any"],

View File

@ -202,7 +202,7 @@ function preprocessCSS(mode, source, destination) {
} }
function expandImports(content, baseUrl) { function expandImports(content, baseUrl) {
return content.replace(/^\s*@import\s+url\(([^\)]+)\);\s*$/gm, function ( return content.replace(/^\s*@import\s+url\(([^)]+)\);\s*$/gm, function (
all, all,
url url
) { ) {

View File

@ -124,7 +124,7 @@ function safeSpawnSync(command, parameters, options) {
options.shell = true; options.shell = true;
// `options.shell = true` requires parameters to be quoted. // `options.shell = true` requires parameters to be quoted.
parameters = parameters.map(param => { parameters = parameters.map(param => {
if (!/[\s`~!#$*(){\[|\\;'"<>?]/.test(param)) { if (!/[\s`~!#$*(){[|\\;'"<>?]/.test(param)) {
return param; return param;
} }
return '"' + param.replace(/([$\\"`])/g, "\\$1") + '"'; return '"' + param.replace(/([$\\"`])/g, "\\$1") + '"';

View File

@ -61,7 +61,7 @@ class Util extends PDFObject {
throw new TypeError("First argument of printf must be a string"); throw new TypeError("First argument of printf must be a string");
} }
const pattern = /%(,[0-4])?([\+ 0#]+)?([0-9]+)?(\.[0-9]+)?(.)/g; const pattern = /%(,[0-4])?([+ 0#]+)?([0-9]+)?(\.[0-9]+)?(.)/g;
const PLUS = 1; const PLUS = 1;
const SPACE = 2; const SPACE = 2;
const ZERO = 4; const ZERO = 4;

View File

@ -824,7 +824,7 @@ function escapeString(str) {
// replace "(", ")", "\n", "\r" and "\" // replace "(", ")", "\n", "\r" and "\"
// by "\(", "\)", "\\n", "\\r" and "\\" // by "\(", "\)", "\\n", "\\r" and "\\"
// in order to write it in a PDF file. // in order to write it in a PDF file.
return str.replace(/([\(\)\\\n\r])/g, match => { return str.replace(/([()\\\n\r])/g, match => {
if (match === "\n") { if (match === "\n") {
return "\\n"; return "\\n";
} else if (match === "\r") { } else if (match === "\r") {

View File

@ -165,7 +165,7 @@ WebServer.prototype = {
var range = req.headers.range; var range = req.headers.range;
if (range && !disableRangeRequests) { if (range && !disableRangeRequests) {
var rangesMatches = /^bytes=(\d+)\-(\d+)?/.exec(range); var rangesMatches = /^bytes=(\d+)-(\d+)?/.exec(range);
if (!rangesMatches) { if (!rangesMatches) {
res.writeHead(501); res.writeHead(501);
res.end("Bad range", "utf8"); res.end("Bad range", "utf8");

View File

@ -1552,7 +1552,7 @@ const PDFViewerApplication = {
if (!producer.includes(generator)) { if (!producer.includes(generator)) {
return false; return false;
} }
generatorId = generator.replace(/[ .\-]/g, "_"); generatorId = generator.replace(/[ .-]/g, "_");
return true; return true;
}); });
} }

View File

@ -115,7 +115,7 @@ var FontInspector = (function FontInspectorClosure() {
name.textContent = fontName; name.textContent = fontName;
var download = document.createElement("a"); var download = document.createElement("a");
if (url) { if (url) {
url = /url\(['"]?([^\)"']+)/.exec(url); url = /url\(['"]?([^)"']+)/.exec(url);
download.href = url[1]; download.href = url[1];
} else if (fontObj.data) { } else if (fontObj.data) {
download.href = URL.createObjectURL( download.href = URL.createObjectURL(

View File

@ -617,10 +617,10 @@ function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
); );
return defaultFilename; return defaultFilename;
} }
const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/; const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
// SCHEME HOST 1.PATH 2.QUERY 3.REF // SCHEME HOST 1.PATH 2.QUERY 3.REF
// Pattern to get last matching NAME.pdf // Pattern to get last matching NAME.pdf
const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i; const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
const splitURI = reURI.exec(url); const splitURI = reURI.exec(url);
let suggestedFilename = let suggestedFilename =
reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[1]) ||