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
}

0 commit comments

Comments
 (0)