Skip to content

Commit 51f89d6

Browse files
clydinfilipesilva
authored andcommitted
test: enable no-useless-escape lint rule
The `no-useless-escape` eslint rule has now been enabled which removes unneeded characters and complexity from string literals and regular expressions. All files that were in violation of this rule have also been corrected.
1 parent 9e71069 commit 51f89d6

File tree

26 files changed

+51
-54
lines changed

26 files changed

+51
-54
lines changed

.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"no-case-declarations": "off",
8787
"no-fallthrough": "off",
8888
"no-underscore-dangle": "off",
89-
"no-useless-escape": "off",
9089
"@typescript-eslint/await-thenable": "off",
9190
"@typescript-eslint/ban-types": "off",
9291
"@typescript-eslint/no-empty-function": "off",

lib/packages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const pattern =
138138
(ex) =>
139139
'(' +
140140
ex
141-
.replace(/[\-\[\]{}()+?./\\^$|]/g, '\\$&')
141+
.replace(/[-[\]{}()+?./\\^$|]/g, '\\$&')
142142
.replace(/(\\\\|\\\/)\*\*/g, '((/|\\\\).+?)?')
143143
.replace(/\*/g, '[^/\\\\]*') +
144144
')',

packages/angular/cli/commands/config-impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function parseJsonPath(path: string): (string | number)[] {
4545
break;
4646
}
4747

48-
const match = fragment.match(/([^\[]+)((\[.*\])*)/);
48+
const match = fragment.match(/([^[]+)((\[.*\])*)/);
4949
if (!match) {
5050
throw new Error('Invalid JSON path.');
5151
}
@@ -55,7 +55,7 @@ function parseJsonPath(path: string): (string | number)[] {
5555
const indices = match[2]
5656
.slice(1, -1)
5757
.split('][')
58-
.map((x) => (/^\d$/.test(x) ? +x : x.replace(/\"|\'/g, '')));
58+
.map((x) => (/^\d$/.test(x) ? +x : x.replace(/"|'/g, '')));
5959
result.push(...indices);
6060
}
6161
}

packages/angular/cli/models/schematic-engine-host.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ function wrap(
147147

148148
// Do not wrap vendored third-party packages or JSON files
149149
if (
150-
!/[\/\\]node_modules[\/\\]@schematics[\/\\]angular[\/\\]third_party[\/\\]/.test(
151-
modulePath,
152-
) &&
150+
!/[/\\]node_modules[/\\]@schematics[/\\]angular[/\\]third_party[/\\]/.test(modulePath) &&
153151
!modulePath.endsWith('.json')
154152
) {
155153
// Wrap module and save in cache

packages/angular/cli/utilities/package-metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function normalizeOptions(
181181

182182
// Substitute any environment variable references.
183183
if (typeof value === 'string') {
184-
substitutedValue = value.replace(/\$\{([^\}]+)\}/, (_, name) => process.env[name] || '');
184+
substitutedValue = value.replace(/\$\{([^}]+)\}/, (_, name) => process.env[name] || '');
185185
}
186186

187187
switch (key) {

packages/angular_devkit/build_angular/src/babel/webpack-loader.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface AngularCustomOptions extends Pick<ApplicationPresetOptions, 'angularLi
2424
function requiresLinking(path: string, source: string): boolean {
2525
// @angular/core and @angular/compiler will cause false positives
2626
// Also, TypeScript files do not require linking
27-
if (/[\\\/]@angular[\\\/](?:compiler|core)|\.tsx?$/.test(path)) {
27+
if (/[\\/]@angular[\\/](?:compiler|core)|\.tsx?$/.test(path)) {
2828
return false;
2929
}
3030

@@ -73,23 +73,23 @@ export default custom<AngularCustomOptions>(() => {
7373
// APF packages with code in [f]esm2015 directories is downlevelled to ES2015 and
7474
// will not have native async.
7575
customOptions.forceAsyncTransformation =
76-
!/[\\\/][_f]?esm2015[\\\/]/.test(this.resourcePath) && source.includes('async');
76+
!/[\\/][_f]?esm2015[\\/]/.test(this.resourcePath) && source.includes('async');
7777
}
7878
shouldProcess ||= customOptions.forceAsyncTransformation || customOptions.forceES5;
7979
}
8080

8181
// Analyze for i18n inlining
8282
if (
8383
i18n &&
84-
!/[\\\/]@angular[\\\/](?:compiler|localize)/.test(this.resourcePath) &&
84+
!/[\\/]@angular[\\/](?:compiler|localize)/.test(this.resourcePath) &&
8585
source.includes('$localize')
8686
) {
8787
customOptions.i18n = i18n as ApplicationPresetOptions['i18n'];
8888
shouldProcess = true;
8989
}
9090

9191
if (optimize) {
92-
const angularPackage = /[\\\/]node_modules[\\\/]@angular[\\\/]/.test(this.resourcePath);
92+
const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(this.resourcePath);
9393
customOptions.optimize = {
9494
// Angular packages provide additional tested side effects guarantees and can use
9595
// otherwise unsafe optimizations.

packages/angular_devkit/build_angular/src/builders/browser/specs/bundle-budgets_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('Browser Builder bundle budgets', () => {
9999
const run = await architect.scheduleTarget(targetSpec, overrides, { logger });
100100
const output = await run.result;
101101
expect(output.success).toBe(true);
102-
expect(logs.join()).toMatch(`Warning.+app\.component\.${ext}`);
102+
expect(logs.join()).toMatch(`Warning.+app\\.component\\.${ext}`);
103103
await run.stop();
104104
});
105105
});
@@ -138,7 +138,7 @@ describe('Browser Builder bundle budgets', () => {
138138
const run = await architect.scheduleTarget(targetSpec, overrides, { logger });
139139
const output = await run.result;
140140
expect(output.success).toBe(false);
141-
expect(logs.join()).toMatch(`Error.+app\.component\.${ext}`);
141+
expect(logs.join()).toMatch(`Error.+app\\.component\\.${ext}`);
142142
await run.stop();
143143
});
144144
});

packages/angular_devkit/build_angular/src/builders/browser/tests/options/subresource-integrity_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
4444
const { result } = await harness.executeOnce();
4545

4646
expect(result?.success).toBe(true);
47-
harness.expectFile('dist/index.html').content.toMatch(/integrity="\w+-[A-Za-z0-9\/\+=]+"/);
47+
harness.expectFile('dist/index.html').content.toMatch(/integrity="\w+-[A-Za-z0-9/+=]+"/);
4848
});
4949

5050
it(`does not issue a warning when 'true' and 'scripts' is set.`, async () => {
@@ -59,7 +59,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
5959
const { result, logs } = await harness.executeOnce();
6060

6161
expect(result?.success).toBe(true);
62-
harness.expectFile('dist/index.html').content.toMatch(/integrity="\w+-[A-Za-z0-9\/\+=]+"/);
62+
harness.expectFile('dist/index.html').content.toMatch(/integrity="\w+-[A-Za-z0-9/+=]+"/);
6363
expect(logs).not.toContain(
6464
jasmine.objectContaining<logging.LogEntry>({
6565
message: jasmine.stringMatching(/subresource-integrity/),

packages/angular_devkit/build_angular/src/utils/index-file/augment-index-html_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('augment-index-html', () => {
2525
};
2626

2727
const oneLineHtml = (html: TemplateStringsArray) =>
28-
tags.stripIndents`${html}`.replace(/(\>\s+)/g, '>');
28+
tags.stripIndents`${html}`.replace(/(>\s+)/g, '>');
2929

3030
it('can generate index.html', async () => {
3131
const source = augmentIndexHtml({

packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class InlineFontsProcessor {
227227
// New lines.
228228
.replace(/\n/g, '')
229229
// Safe spaces.
230-
.replace(/\s?[\{\:\;]\s+/g, (s) => s.trim());
230+
.replace(/\s?[{:;]\s+/g, (s) => s.trim());
231231
}
232232

233233
return cssContent;

0 commit comments

Comments
 (0)