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.
This commit is contained in:
Charles Lyding 2024-07-10 17:46:58 -04:00 committed by Alan Agius
parent 16268e3b30
commit 5895e9fb01
15 changed files with 96 additions and 78 deletions

View File

@ -100,7 +100,6 @@
], ],
/* TODO: evaluate usage of these rules and fix issues as needed */ /* TODO: evaluate usage of these rules and fix issues as needed */
"no-case-declarations": "off",
"@typescript-eslint/ban-types": "off", "@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-implied-eval": "off", "@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/no-var-requires": "off", "@typescript-eslint/no-var-requires": "off",
@ -124,6 +123,7 @@
"rules": { "rules": {
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }], "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"max-lines-per-function": "off", "max-lines-per-function": "off",
"no-case-declarations": "off",
"no-console": "off" "no-console": "off"
} }
} }

View File

@ -153,13 +153,16 @@ async function createSerializer(
case Format.LegacyMigrate: case Format.LegacyMigrate:
return new LegacyMessageIdMigrationSerializer(diagnostics); return new LegacyMessageIdMigrationSerializer(diagnostics);
case Format.Arb: case Format.Arb:
const fileSystem = { return new ArbTranslationSerializer(
sourceLocale,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
basePath as any,
{
relative(from: string, to: string): string { relative(from: string, to: string): string {
return path.relative(from, to); return path.relative(from, to);
}, },
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
return new ArbTranslationSerializer(sourceLocale, basePath as any, fileSystem as any); } as any,
);
} }
} }

View File

@ -145,9 +145,8 @@ export function elideImports(
let symbol: ts.Symbol | undefined; let symbol: ts.Symbol | undefined;
switch (node.kind) { switch (node.kind) {
case ts.SyntaxKind.Identifier: case ts.SyntaxKind.Identifier:
const parent = node.parent; if (node.parent && ts.isShorthandPropertyAssignment(node.parent)) {
if (parent && ts.isShorthandPropertyAssignment(parent)) { const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(node.parent);
const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(parent);
if (shorthandSymbol) { if (shorthandSymbol) {
symbol = shorthandSymbol; symbol = shorthandSymbol;
} }

View File

@ -210,7 +210,7 @@ function visitComponentMetadata(
return node; return node;
case 'styleUrls': case 'styleUrls': {
if (!ts.isArrayLiteralExpression(node.initializer)) { if (!ts.isArrayLiteralExpression(node.initializer)) {
return node; return node;
} }
@ -234,6 +234,7 @@ function visitComponentMetadata(
// The external styles will be added afterwards in combination with any inline styles // The external styles will be added afterwards in combination with any inline styles
return undefined; return undefined;
}
default: default:
// All other elements are passed through // All other elements are passed through
return node; return node;

View File

@ -145,7 +145,7 @@ export class InlineFontsProcessor {
} }
break; break;
case 'link': case 'link': {
const hrefAttr = const hrefAttr =
attrs.some(({ name, value }) => name === 'rel' && value === 'stylesheet') && attrs.some(({ name, value }) => name === 'rel' && value === 'stylesheet') &&
attrs.find(({ name, value }) => name === 'href' && hrefsContent.has(value)); attrs.find(({ name, value }) => name === 'href' && hrefsContent.has(value));
@ -157,7 +157,7 @@ export class InlineFontsProcessor {
rewriter.emitStartTag(tag); rewriter.emitStartTag(tag);
} }
break; break;
}
default: default:
rewriter.emitStartTag(tag); rewriter.emitStartTag(tag);

View File

@ -193,8 +193,13 @@ export abstract class SchematicsCommandModule
continue; continue;
} }
const choices = definition.items?.map((item) => { answers[definition.id] = await (
return typeof item == 'string' definition.multiselect ? prompts.checkbox : prompts.select
)({
message: definition.message,
default: definition.default,
choices: definition.items?.map((item) =>
typeof item == 'string'
? { ? {
name: item, name: item,
value: item, value: item,
@ -202,18 +207,11 @@ export abstract class SchematicsCommandModule
: { : {
name: item.label, name: item.label,
value: item.value, value: item.value,
}; },
}); ),
answers[definition.id] = await (
definition.multiselect ? prompts.checkbox : prompts.select
)({
message: definition.message,
default: definition.default,
choices,
}); });
break; break;
case 'input': case 'input': {
let finalValue: JsonValue | undefined; let finalValue: JsonValue | undefined;
answers[definition.id] = await prompts.input({ answers[definition.id] = await prompts.input({
message: definition.message, message: definition.message,
@ -260,6 +258,7 @@ export abstract class SchematicsCommandModule
break; break;
} }
} }
}
return answers; return answers;
}); });

View File

@ -10,6 +10,10 @@ import { logging } from '@angular-devkit/core';
import { NodeWorkflow } from '@angular-devkit/schematics/tools'; import { NodeWorkflow } from '@angular-devkit/schematics/tools';
import { colors } from '../../utilities/color'; import { colors } from '../../utilities/color';
function removeLeadingSlash(value: string): string {
return value[0] === '/' ? value.slice(1) : value;
}
export function subscribeToWorkflow( export function subscribeToWorkflow(
workflow: NodeWorkflow, workflow: NodeWorkflow,
logger: logging.LoggerApi, logger: logging.LoggerApi,
@ -24,13 +28,14 @@ export function subscribeToWorkflow(
const reporterSubscription = workflow.reporter.subscribe((event) => { const reporterSubscription = workflow.reporter.subscribe((event) => {
// Strip leading slash to prevent confusion. // Strip leading slash to prevent confusion.
const eventPath = event.path.charAt(0) === '/' ? event.path.substring(1) : event.path; const eventPath = removeLeadingSlash(event.path);
switch (event.kind) { switch (event.kind) {
case 'error': case 'error':
error = true; error = true;
const desc = event.description == 'alreadyExist' ? 'already exists' : 'does not exist'; logger.error(
logger.error(`ERROR! ${eventPath} ${desc}.`); `ERROR! ${eventPath} ${event.description == 'alreadyExist' ? 'already exists' : 'does not exist'}.`,
);
break; break;
case 'update': case 'update':
logs.push(`${colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)`); logs.push(`${colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)`);
@ -45,8 +50,7 @@ export function subscribeToWorkflow(
files.add(eventPath); files.add(eventPath);
break; break;
case 'rename': case 'rename':
const eventToPath = event.to.charAt(0) === '/' ? event.to.substring(1) : event.to; logs.push(`${colors.blue('RENAME')} ${eventPath} => ${removeLeadingSlash(event.to)}`);
logs.push(`${colors.blue('RENAME')} ${eventPath} => ${eventToPath}`);
files.add(eventPath); files.add(eventPath);
break; break;
} }

View File

@ -168,13 +168,16 @@ async function createSerializer(
case Format.LegacyMigrate: case Format.LegacyMigrate:
return new LegacyMessageIdMigrationSerializer(diagnostics); return new LegacyMessageIdMigrationSerializer(diagnostics);
case Format.Arb: case Format.Arb:
const fileSystem = { return new ArbTranslationSerializer(
sourceLocale,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
basePath as any,
{
relative(from: string, to: string): string { relative(from: string, to: string): string {
return path.relative(from, to); return path.relative(from, to);
}, },
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
return new ArbTranslationSerializer(sourceLocale, basePath as any, fileSystem as any); } as any,
);
} }
} }

View File

@ -191,7 +191,7 @@ function parseProject(
for (const [name, value] of Object.entries<JsonValue>(projectNodeValue)) { for (const [name, value] of Object.entries<JsonValue>(projectNodeValue)) {
switch (name) { switch (name) {
case 'targets': case 'targets':
case 'architect': case 'architect': {
const nodes = findNodeAtLocation(projectNode, [name]); const nodes = findNodeAtLocation(projectNode, [name]);
if (!isJsonObject(value) || !nodes) { if (!isJsonObject(value) || !nodes) {
context.error(`Invalid "${name}" field found; expected an object.`, value); context.error(`Invalid "${name}" field found; expected an object.`, value);
@ -201,6 +201,7 @@ function parseProject(
targets = parseTargetsObject(projectName, nodes, context); targets = parseTargetsObject(projectName, nodes, context);
jsonMetadata.hasLegacyTargetsName = name === 'architect'; jsonMetadata.hasLegacyTargetsName = name === 'architect';
break; break;
}
case 'prefix': case 'prefix':
case 'root': case 'root':
case 'sourceRoot': case 'sourceRoot':

View File

@ -132,16 +132,18 @@ function normalizeValue(
switch (type) { switch (type) {
case 'project': case 'project':
return convertJsonProject(value as ProjectDefinition); return convertJsonProject(value as ProjectDefinition);
case 'projectcollection': case 'projectcollection': {
const projects = convertJsonProjectCollection(value as Iterable<[string, ProjectDefinition]>); const projects = convertJsonProjectCollection(value as Iterable<[string, ProjectDefinition]>);
return isEmpty(projects) ? undefined : projects; return isEmpty(projects) ? undefined : projects;
}
case 'target': case 'target':
return convertJsonTarget(value as TargetDefinition); return convertJsonTarget(value as TargetDefinition);
case 'targetcollection': case 'targetcollection': {
const targets = convertJsonTargetCollection(value as Iterable<[string, TargetDefinition]>); const targets = convertJsonTargetCollection(value as Iterable<[string, TargetDefinition]>);
return isEmpty(targets) ? undefined : targets; return isEmpty(targets) ? undefined : targets;
}
default: default:
return value as JsonValue; return value as JsonValue;
} }

View File

@ -370,7 +370,8 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
return () => new NullTree(); return () => new NullTree();
case 'empty:': case 'empty:':
return () => empty(); return () => empty();
default: }
const hostSource = this._host.createSourceFromUrl(url, context); const hostSource = this._host.createSourceFromUrl(url, context);
if (!hostSource) { if (!hostSource) {
throw new UnknownUrlSourceProtocol(url.toString()); throw new UnknownUrlSourceProtocol(url.toString());
@ -378,7 +379,6 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
return hostSource; return hostSource;
} }
}
executePostTasks(): Observable<void> { executePostTasks(): Observable<void> {
const executors = new Map<string, TaskExecutor>(); const executors = new Map<string, TaskExecutor>();

View File

@ -72,7 +72,7 @@ export class ActionList implements Iterable<Action> {
toDelete.add(action.path); toDelete.add(action.path);
break; break;
case 'r': case 'r': {
const maybeCreate = toCreate.get(action.path); const maybeCreate = toCreate.get(action.path);
const maybeOverwrite = toOverwrite.get(action.path); const maybeOverwrite = toOverwrite.get(action.path);
if (maybeCreate) { if (maybeCreate) {
@ -102,6 +102,7 @@ export class ActionList implements Iterable<Action> {
break; break;
} }
} }
}
this._actions = []; this._actions = [];
toDelete.forEach((x) => { toDelete.forEach((x) => {

View File

@ -47,6 +47,10 @@ function parseSchematicName(str: string | null): { collection: string; schematic
return { collection, schematic }; return { collection, schematic };
} }
function removeLeadingSlash(value: string): string {
return value[0] === '/' ? value.slice(1) : value;
}
export interface MainOptions { export interface MainOptions {
args: string[]; args: string[];
stdout?: ProcessOutput; stdout?: ProcessOutput;
@ -87,8 +91,13 @@ function _createPromptProvider(): schema.PromptProvider {
continue; continue;
} }
const choices = definition.items?.map((item) => { answers[definition.id] = await (
return typeof item == 'string' definition.multiselect ? prompts.checkbox : prompts.select
)({
message: definition.message,
default: definition.default,
choices: definition.items.map((item) =>
typeof item == 'string'
? { ? {
name: item, name: item,
value: item, value: item,
@ -96,18 +105,11 @@ function _createPromptProvider(): schema.PromptProvider {
: { : {
name: item.label, name: item.label,
value: item.value, value: item.value,
}; },
}); ),
answers[definition.id] = await (
definition.multiselect ? prompts.checkbox : prompts.select
)({
message: definition.message,
default: definition.default,
choices,
}); });
break; break;
case 'input': case 'input': {
let finalValue: JsonValue | undefined; let finalValue: JsonValue | undefined;
answers[definition.id] = await prompts.input({ answers[definition.id] = await prompts.input({
message: definition.message, message: definition.message,
@ -154,6 +156,7 @@ function _createPromptProvider(): schema.PromptProvider {
break; break;
} }
} }
}
return answers; return answers;
}; };
@ -287,14 +290,14 @@ export async function main({
workflow.reporter.subscribe((event) => { workflow.reporter.subscribe((event) => {
nothingDone = false; nothingDone = false;
// Strip leading slash to prevent confusion. // Strip leading slash to prevent confusion.
const eventPath = event.path.startsWith('/') ? event.path.slice(1) : event.path; const eventPath = removeLeadingSlash(event.path);
switch (event.kind) { switch (event.kind) {
case 'error': case 'error':
error = true; error = true;
logger.error(
const desc = event.description == 'alreadyExist' ? 'already exists' : 'does not exist'; `ERROR! ${eventPath} ${event.description == 'alreadyExist' ? 'already exists' : 'does not exist'}.`,
logger.error(`ERROR! ${eventPath} ${desc}.`); );
break; break;
case 'update': case 'update':
loggingQueue.push(`${colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)`); loggingQueue.push(`${colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)`);
@ -306,8 +309,9 @@ export async function main({
loggingQueue.push(`${colors.yellow('DELETE')} ${eventPath}`); loggingQueue.push(`${colors.yellow('DELETE')} ${eventPath}`);
break; break;
case 'rename': case 'rename':
const eventToPath = event.to.startsWith('/') ? event.to.slice(1) : event.to; loggingQueue.push(
loggingQueue.push(`${colors.blue('RENAME')} ${eventPath} => ${eventToPath}`); `${colors.blue('RENAME')} ${eventPath} => ${removeLeadingSlash(event.to)}`,
);
break; break;
} }
}); });

View File

@ -62,9 +62,8 @@ export function elideImports(
let symbol: ts.Symbol | undefined; let symbol: ts.Symbol | undefined;
switch (node.kind) { switch (node.kind) {
case ts.SyntaxKind.Identifier: case ts.SyntaxKind.Identifier:
const parent = node.parent; if (node.parent && ts.isShorthandPropertyAssignment(node.parent)) {
if (parent && ts.isShorthandPropertyAssignment(parent)) { const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(node.parent);
const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(parent);
if (shorthandSymbol) { if (shorthandSymbol) {
symbol = shorthandSymbol; symbol = shorthandSymbol;
} }

View File

@ -158,7 +158,7 @@ function visitComponentMetadata(
case 'moduleId': case 'moduleId':
return undefined; return undefined;
case 'templateUrl': case 'templateUrl': {
const url = getResourceUrl(node.initializer); const url = getResourceUrl(node.initializer);
if (!url) { if (!url) {
return node; return node;
@ -179,9 +179,10 @@ function visitComponentMetadata(
nodeFactory.createIdentifier('template'), nodeFactory.createIdentifier('template'),
importName, importName,
); );
}
case 'styles': case 'styles':
case 'styleUrl': case 'styleUrl':
case 'styleUrls': case 'styleUrls': {
const isInlineStyle = name === 'styles'; const isInlineStyle = name === 'styles';
let styles: Iterable<ts.Expression>; let styles: Iterable<ts.Expression>;
@ -219,6 +220,7 @@ function visitComponentMetadata(
} }
return undefined; return undefined;
}
default: default:
return node; return node;
} }