MCPcopy Index your code
hub / github.com/angular/angular / applyWithProgram

Method applyWithProgram

tools/tslint/noExportedInferredCallTypeRule.ts:25–56  ·  view source on GitHub ↗
(sourceFile: ts.SourceFile, program: ts.Program)

Source from the content-addressed store, hash-verified

23 */
24export class Rule extends TypedRule {
25 override applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[] {
26 const checker = program.getTypeChecker();
27
28 return this.applyWithFunction(sourceFile, (ctx) => {
29 for (const st of sourceFile.statements) {
30 if (
31 !ts.isVariableStatement(st) ||
32 !(st.modifiers ?? []).some((s) => s.kind === ts.SyntaxKind.ExportKeyword)
33 ) {
34 continue;
35 }
36
37 for (const decl of st.declarationList.declarations) {
38 if (
39 decl.initializer !== undefined &&
40 ts.isCallExpression(decl.initializer) &&
41 decl.type === undefined
42 ) {
43 const inferredType = checker.getTypeAtLocation(decl.name);
44 const typeStr = checker.typeToString(inferredType, decl);
45
46 ctx.addFailureAtNode(
47 decl,
48 'No explicit type. Inferred types can cause unexpected issues. ' +
49 'Please add an explicit type.',
50 Replacement.appendText(decl.name.end, `: ${typeStr}`),
51 );
52 }
53 }
54 }
55 });
56 }
57}

Callers

nothing calls this directly

Calls 4

getTypeCheckerMethod · 0.80
someMethod · 0.80
appendTextMethod · 0.80
isCallExpressionMethod · 0.65

Tested by

no test coverage detected