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 */
"no-case-declarations": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/no-var-requires": "off",
@ -124,6 +123,7 @@
"rules": {
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"max-lines-per-function": "off",
"no-case-declarations": "off",
"no-console": "off"
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -72,7 +72,7 @@ export class ActionList implements Iterable<Action> {
toDelete.add(action.path);
break;
case 'r':
case 'r': {
const maybeCreate = toCreate.get(action.path);
const maybeOverwrite = toOverwrite.get(action.path);
if (maybeCreate) {
@ -100,6 +100,7 @@ export class ActionList implements Iterable<Action> {
toRename.set(action.path, action.to);
}
break;
}
}
}

View File

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

View File

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

View File

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