Skip to content

Commit 5895e9f

Browse files
clydinalan-agius4
authored andcommitted
test: enable no-case-declarations lint rule
The `no-case-declarations` rule is now enabled and all failures in have been addressed within the published code. Unit tests have been excluded.
1 parent 16268e3 commit 5895e9f

File tree

15 files changed

+95
-77
lines changed

15 files changed

+95
-77
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
],
101101

102102
/* TODO: evaluate usage of these rules and fix issues as needed */
103-
"no-case-declarations": "off",
104103
"@typescript-eslint/ban-types": "off",
105104
"@typescript-eslint/no-implied-eval": "off",
106105
"@typescript-eslint/no-var-requires": "off",
@@ -124,6 +123,7 @@
124123
"rules": {
125124
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
126125
"max-lines-per-function": "off",
126+
"no-case-declarations": "off",
127127
"no-console": "off"
128128
}
129129
}

packages/angular/build/src/builders/extract-i18n/builder.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,16 @@ async function createSerializer(
153153
case Format.LegacyMigrate:
154154
return new LegacyMessageIdMigrationSerializer(diagnostics);
155155
case Format.Arb:
156-
const fileSystem = {
157-
relative(from: string, to: string): string {
158-
return path.relative(from, to);
159-
},
160-
};
161-
162-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
163-
return new ArbTranslationSerializer(sourceLocale, basePath as any, fileSystem as any);
156+
return new ArbTranslationSerializer(
157+
sourceLocale,
158+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
159+
basePath as any,
160+
{
161+
relative(from: string, to: string): string {
162+
return path.relative(from, to);
163+
},
164+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
165+
} as any,
166+
);
164167
}
165168
}

packages/angular/build/src/tools/angular/transformers/jit-bootstrap-transformer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ export function elideImports(
145145
let symbol: ts.Symbol | undefined;
146146
switch (node.kind) {
147147
case ts.SyntaxKind.Identifier:
148-
const parent = node.parent;
149-
if (parent && ts.isShorthandPropertyAssignment(parent)) {
150-
const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(parent);
148+
if (node.parent && ts.isShorthandPropertyAssignment(node.parent)) {
149+
const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(node.parent);
151150
if (shorthandSymbol) {
152151
symbol = shorthandSymbol;
153152
}

packages/angular/build/src/tools/angular/transformers/jit-resource-transformer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function visitComponentMetadata(
210210

211211
return node;
212212

213-
case 'styleUrls':
213+
case 'styleUrls': {
214214
if (!ts.isArrayLiteralExpression(node.initializer)) {
215215
return node;
216216
}
@@ -234,6 +234,7 @@ function visitComponentMetadata(
234234

235235
// The external styles will be added afterwards in combination with any inline styles
236236
return undefined;
237+
}
237238
default:
238239
// All other elements are passed through
239240
return node;

packages/angular/build/src/utils/index-file/inline-fonts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class InlineFontsProcessor {
145145
}
146146
break;
147147

148-
case 'link':
148+
case 'link': {
149149
const hrefAttr =
150150
attrs.some(({ name, value }) => name === 'rel' && value === 'stylesheet') &&
151151
attrs.find(({ name, value }) => name === 'href' && hrefsContent.has(value));
@@ -157,7 +157,7 @@ export class InlineFontsProcessor {
157157
rewriter.emitStartTag(tag);
158158
}
159159
break;
160-
160+
}
161161
default:
162162
rewriter.emitStartTag(tag);
163163

packages/angular/cli/src/command-builder/schematics-command-module.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,25 @@ export abstract class SchematicsCommandModule
193193
continue;
194194
}
195195

196-
const choices = definition.items?.map((item) => {
197-
return typeof item == 'string'
198-
? {
199-
name: item,
200-
value: item,
201-
}
202-
: {
203-
name: item.label,
204-
value: item.value,
205-
};
206-
});
207-
208196
answers[definition.id] = await (
209197
definition.multiselect ? prompts.checkbox : prompts.select
210198
)({
211199
message: definition.message,
212200
default: definition.default,
213-
choices,
201+
choices: definition.items?.map((item) =>
202+
typeof item == 'string'
203+
? {
204+
name: item,
205+
value: item,
206+
}
207+
: {
208+
name: item.label,
209+
value: item.value,
210+
},
211+
),
214212
});
215213
break;
216-
case 'input':
214+
case 'input': {
217215
let finalValue: JsonValue | undefined;
218216
answers[definition.id] = await prompts.input({
219217
message: definition.message,
@@ -258,6 +256,7 @@ export abstract class SchematicsCommandModule
258256
answers[definition.id] = finalValue;
259257
}
260258
break;
259+
}
261260
}
262261
}
263262

packages/angular/cli/src/command-builder/utilities/schematic-workflow.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { logging } from '@angular-devkit/core';
1010
import { NodeWorkflow } from '@angular-devkit/schematics/tools';
1111
import { colors } from '../../utilities/color';
1212

13+
function removeLeadingSlash(value: string): string {
14+
return value[0] === '/' ? value.slice(1) : value;
15+
}
16+
1317
export function subscribeToWorkflow(
1418
workflow: NodeWorkflow,
1519
logger: logging.LoggerApi,
@@ -24,13 +28,14 @@ export function subscribeToWorkflow(
2428

2529
const reporterSubscription = workflow.reporter.subscribe((event) => {
2630
// Strip leading slash to prevent confusion.
27-
const eventPath = event.path.charAt(0) === '/' ? event.path.substring(1) : event.path;
31+
const eventPath = removeLeadingSlash(event.path);
2832

2933
switch (event.kind) {
3034
case 'error':
3135
error = true;
32-
const desc = event.description == 'alreadyExist' ? 'already exists' : 'does not exist';
33-
logger.error(`ERROR! ${eventPath} ${desc}.`);
36+
logger.error(
37+
`ERROR! ${eventPath} ${event.description == 'alreadyExist' ? 'already exists' : 'does not exist'}.`,
38+
);
3439
break;
3540
case 'update':
3641
logs.push(`${colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)`);
@@ -45,8 +50,7 @@ export function subscribeToWorkflow(
4550
files.add(eventPath);
4651
break;
4752
case 'rename':
48-
const eventToPath = event.to.charAt(0) === '/' ? event.to.substring(1) : event.to;
49-
logs.push(`${colors.blue('RENAME')} ${eventPath} => ${eventToPath}`);
53+
logs.push(`${colors.blue('RENAME')} ${eventPath} => ${removeLeadingSlash(event.to)}`);
5054
files.add(eventPath);
5155
break;
5256
}

packages/angular_devkit/build_angular/src/builders/extract-i18n/builder.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,16 @@ async function createSerializer(
168168
case Format.LegacyMigrate:
169169
return new LegacyMessageIdMigrationSerializer(diagnostics);
170170
case Format.Arb:
171-
const fileSystem = {
172-
relative(from: string, to: string): string {
173-
return path.relative(from, to);
174-
},
175-
};
176-
177-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
178-
return new ArbTranslationSerializer(sourceLocale, basePath as any, fileSystem as any);
171+
return new ArbTranslationSerializer(
172+
sourceLocale,
173+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
174+
basePath as any,
175+
{
176+
relative(from: string, to: string): string {
177+
return path.relative(from, to);
178+
},
179+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
180+
} as any,
181+
);
179182
}
180183
}

packages/angular_devkit/core/src/workspace/json/reader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function parseProject(
191191
for (const [name, value] of Object.entries<JsonValue>(projectNodeValue)) {
192192
switch (name) {
193193
case 'targets':
194-
case 'architect':
194+
case 'architect': {
195195
const nodes = findNodeAtLocation(projectNode, [name]);
196196
if (!isJsonObject(value) || !nodes) {
197197
context.error(`Invalid "${name}" field found; expected an object.`, value);
@@ -201,6 +201,7 @@ function parseProject(
201201
targets = parseTargetsObject(projectName, nodes, context);
202202
jsonMetadata.hasLegacyTargetsName = name === 'architect';
203203
break;
204+
}
204205
case 'prefix':
205206
case 'root':
206207
case 'sourceRoot':

packages/angular_devkit/core/src/workspace/json/writer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,18 @@ function normalizeValue(
132132
switch (type) {
133133
case 'project':
134134
return convertJsonProject(value as ProjectDefinition);
135-
case 'projectcollection':
135+
case 'projectcollection': {
136136
const projects = convertJsonProjectCollection(value as Iterable<[string, ProjectDefinition]>);
137137

138138
return isEmpty(projects) ? undefined : projects;
139+
}
139140
case 'target':
140141
return convertJsonTarget(value as TargetDefinition);
141-
case 'targetcollection':
142+
case 'targetcollection': {
142143
const targets = convertJsonTargetCollection(value as Iterable<[string, TargetDefinition]>);
143144

144145
return isEmpty(targets) ? undefined : targets;
146+
}
145147
default:
146148
return value as JsonValue;
147149
}

packages/angular_devkit/schematics/src/engine/engine.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,14 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
370370
return () => new NullTree();
371371
case 'empty:':
372372
return () => empty();
373-
default:
374-
const hostSource = this._host.createSourceFromUrl(url, context);
375-
if (!hostSource) {
376-
throw new UnknownUrlSourceProtocol(url.toString());
377-
}
373+
}
378374

379-
return hostSource;
375+
const hostSource = this._host.createSourceFromUrl(url, context);
376+
if (!hostSource) {
377+
throw new UnknownUrlSourceProtocol(url.toString());
380378
}
379+
380+
return hostSource;
381381
}
382382

383383
executePostTasks(): Observable<void> {

packages/angular_devkit/schematics/src/tree/action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class ActionList implements Iterable<Action> {
7272
toDelete.add(action.path);
7373
break;
7474

75-
case 'r':
75+
case 'r': {
7676
const maybeCreate = toCreate.get(action.path);
7777
const maybeOverwrite = toOverwrite.get(action.path);
7878
if (maybeCreate) {
@@ -100,6 +100,7 @@ export class ActionList implements Iterable<Action> {
100100
toRename.set(action.path, action.to);
101101
}
102102
break;
103+
}
103104
}
104105
}
105106

packages/angular_devkit/schematics_cli/bin/schematics.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ function parseSchematicName(str: string | null): { collection: string; schematic
4747
return { collection, schematic };
4848
}
4949

50+
function removeLeadingSlash(value: string): string {
51+
return value[0] === '/' ? value.slice(1) : value;
52+
}
53+
5054
export interface MainOptions {
5155
args: string[];
5256
stdout?: ProcessOutput;
@@ -87,27 +91,25 @@ function _createPromptProvider(): schema.PromptProvider {
8791
continue;
8892
}
8993

90-
const choices = definition.items?.map((item) => {
91-
return typeof item == 'string'
92-
? {
93-
name: item,
94-
value: item,
95-
}
96-
: {
97-
name: item.label,
98-
value: item.value,
99-
};
100-
});
101-
10294
answers[definition.id] = await (
10395
definition.multiselect ? prompts.checkbox : prompts.select
10496
)({
10597
message: definition.message,
10698
default: definition.default,
107-
choices,
99+
choices: definition.items.map((item) =>
100+
typeof item == 'string'
101+
? {
102+
name: item,
103+
value: item,
104+
}
105+
: {
106+
name: item.label,
107+
value: item.value,
108+
},
109+
),
108110
});
109111
break;
110-
case 'input':
112+
case 'input': {
111113
let finalValue: JsonValue | undefined;
112114
answers[definition.id] = await prompts.input({
113115
message: definition.message,
@@ -152,6 +154,7 @@ function _createPromptProvider(): schema.PromptProvider {
152154
answers[definition.id] = finalValue;
153155
}
154156
break;
157+
}
155158
}
156159
}
157160

@@ -287,14 +290,14 @@ export async function main({
287290
workflow.reporter.subscribe((event) => {
288291
nothingDone = false;
289292
// Strip leading slash to prevent confusion.
290-
const eventPath = event.path.startsWith('/') ? event.path.slice(1) : event.path;
293+
const eventPath = removeLeadingSlash(event.path);
291294

292295
switch (event.kind) {
293296
case 'error':
294297
error = true;
295-
296-
const desc = event.description == 'alreadyExist' ? 'already exists' : 'does not exist';
297-
logger.error(`ERROR! ${eventPath} ${desc}.`);
298+
logger.error(
299+
`ERROR! ${eventPath} ${event.description == 'alreadyExist' ? 'already exists' : 'does not exist'}.`,
300+
);
298301
break;
299302
case 'update':
300303
loggingQueue.push(`${colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)`);
@@ -306,8 +309,9 @@ export async function main({
306309
loggingQueue.push(`${colors.yellow('DELETE')} ${eventPath}`);
307310
break;
308311
case 'rename':
309-
const eventToPath = event.to.startsWith('/') ? event.to.slice(1) : event.to;
310-
loggingQueue.push(`${colors.blue('RENAME')} ${eventPath} => ${eventToPath}`);
312+
loggingQueue.push(
313+
`${colors.blue('RENAME')} ${eventPath} => ${removeLeadingSlash(event.to)}`,
314+
);
311315
break;
312316
}
313317
});

packages/ngtools/webpack/src/transformers/elide_imports.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ export function elideImports(
6262
let symbol: ts.Symbol | undefined;
6363
switch (node.kind) {
6464
case ts.SyntaxKind.Identifier:
65-
const parent = node.parent;
66-
if (parent && ts.isShorthandPropertyAssignment(parent)) {
67-
const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(parent);
65+
if (node.parent && ts.isShorthandPropertyAssignment(node.parent)) {
66+
const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(node.parent);
6867
if (shorthandSymbol) {
6968
symbol = shorthandSymbol;
7069
}

0 commit comments

Comments
 (0)