Skip to content

Commit

Permalink
test: enable @typescript-eslint/no-unnecessary-type-assertion lint …
Browse files Browse the repository at this point in the history
…rule

The `@typescript-eslint/no-unnecessary-type-assertion` rule is now enabled and all failures
have been addressed within the code.
  • Loading branch information
clydin committed Jun 25, 2024
1 parent 53dd9a2 commit fa9bce0
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 24 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
Expand Down
2 changes: 1 addition & 1 deletion modules/testing/builder/src/builder-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class BuilderHarness<T> {
// Harness builder targets currently do not support configurations
return {};
} else {
return (this.builderTargets.get(target)?.options || {}) as json.JsonObject;
return this.builderTargets.get(target)?.options || {};
}
},
hasTarget: async (project, target) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function visitDecorator(
return node;
}

const objectExpression = args[0] as ts.ObjectLiteralExpression;
const objectExpression = args[0];
const styleReplacements: ts.Expression[] = [];

// visit all properties
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/build/src/utils/i18n-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function normalizeTranslationFileOption(
}

if (Array.isArray(option) && option.every((element) => typeof element === 'string')) {
return option as string[];
return option;
}

let errorMessage = `Project i18n locales translation field value for '${locale}' is malformed. `;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ export function createJobHandler<A extends JsonValue, I extends JsonValue, O ext
if (isPromise(result)) {
result = from(result);
} else if (!isObservable(result)) {
result = of(result as O);
result = of(result);
}

subscription = (result as Observable<O>).subscribe(
subscription = result.subscribe(
(value: O) => subject.next({ kind: JobOutboundMessageKind.Output, description, value }),
(error) => subject.error(error),
() => complete(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export class SimpleScheduler<

const output = outboundBus.pipe(
filter((x) => x.kind == JobOutboundMessageKind.Output),
map((x) => (x as JobOutboundMessageOutput<O>).value),
map((x) => x.value),
shareReplay(1),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ describe('SimpleScheduler', () => {

const job = scheduler.schedule('job', 0);
let sideValue = '';
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const c = job.getChannel('any') as Observable<string>;
c.subscribe((x) => (sideValue = x));

Expand All @@ -486,6 +487,7 @@ describe('SimpleScheduler', () => {

const job = scheduler.schedule('job', 0);
let sideValue = '';
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const c = job.getChannel('any', { type: 'number' }) as Observable<string>;
expect(c).toBeDefined(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function serveWebpackBrowser(
logger.warn(`Warning: 'outputHashing' option is disabled when using the dev-server.`);
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const browserOptions = (await context.validateOptions(
{
...rawBrowserOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default custom<ApplicationPresetOptions>(() => {
}

customOptions.i18n = {
...(i18n as NonNullable<ApplicationPresetOptions['i18n']>),
...i18n,
pluginCreators: i18nPluginCreators,
};

Expand Down
6 changes: 2 additions & 4 deletions packages/angular_devkit/core/node/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,11 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats> {
}

isDirectory(path: Path): Observable<boolean> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.stat(path)!.pipe(map((stat) => stat.isDirectory()));
return this.stat(path).pipe(map((stat) => stat.isDirectory()));
}

isFile(path: Path): Observable<boolean> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.stat(path)!.pipe(map((stat) => stat.isFile()));
return this.stat(path).pipe(map((stat) => stat.isFile()));
}

// Some hosts may not support stat.
Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/schematics/src/rules/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function callSource(source: Source, context: SchematicContext): Observabl
}

if (result && TreeSymbol in result) {
return result as Tree;
return result;
}

throw new InvalidSourceResultException(result);
Expand Down Expand Up @@ -91,7 +91,7 @@ async function callRuleAsync(rule: Rule, tree: Tree, context: SchematicContext):
}

if (result && TreeSymbol in result) {
return result as Tree;
return result;
}

throw new InvalidRuleResultException(result);
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/schematics/src/rules/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function applyPathTemplate<T extends PathTemplateData>(
}

// Coerce to string.
return '' + (data[pipe] as PathTemplatePipeFunction)(acc);
return '' + data[pipe](acc);
}, '' + replacement);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/angular_devkit/schematics/src/tree/common_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export function testTreeVisit({ createTree, sets }: VisitTestSpec) {
allPaths.push(path);
});

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(allPaths).toEqual(expected!);
expect(allPaths).toEqual(expected);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function visitDecorator(
return node;
}

const objectExpression = args[0] as ts.ObjectLiteralExpression;
const objectExpression = args[0];
const styleReplacements: ts.Expression[] = [];

// visit all properties
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/app-shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getServerModulePath(host: Tree, sourceRoot: string, mainPath: string):
if (!expNode) {
return null;
}
const relativePath = (expNode as ts.ExportDeclaration).moduleSpecifier as ts.StringLiteral;
const relativePath = expNode.moduleSpecifier as ts.StringLiteral;
const modulePath = join(sourceRoot, `${relativePath.text}.ts`);

return modulePath;
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/angular/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function buildSelector(options: ComponentOptions, projectPrefix: string) {
export default function (options: ComponentOptions): Rule {
return async (host: Tree) => {
const workspace = await getWorkspace(host);
const project = workspace.projects.get(options.project as string);
const project = workspace.projects.get(options.project);

if (!project) {
throw new SchematicsException(`Project "${options.project}" does not exist.`);
Expand All @@ -55,7 +55,7 @@ export default function (options: ComponentOptions): Rule {

options.module = findModuleFromOptions(host, options);

const parsedPath = parseName(options.path as string, options.name);
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
options.selector =
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function buildSelector(options: DirectiveOptions, projectPrefix: string) {
export default function (options: DirectiveOptions): Rule {
return async (host: Tree) => {
const workspace = await getWorkspace(host);
const project = workspace.projects.get(options.project as string);
const project = workspace.projects.get(options.project);
if (!project) {
throw new SchematicsException(`Project "${options.project}" does not exist.`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function buildRoute(options: ModuleOptions, modulePath: string) {
export default function (options: ModuleOptions): Rule {
return async (host: Tree) => {
if (options.path === undefined) {
options.path = await createDefaultPath(host, options.project as string);
options.path = await createDefaultPath(host, options.project);
}

if (options.module) {
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/pipe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Schema as PipeOptions } from './schema';

export default function (options: PipeOptions): Rule {
return async (host: Tree) => {
options.path ??= await createDefaultPath(host, options.project as string);
options.path ??= await createDefaultPath(host, options.project);
options.module = findModuleFromOptions(host, options);

const parsedPath = parseName(options.path, options.name);
Expand Down

0 comments on commit fa9bce0

Please sign in to comment.