MCPcopy
hub / github.com/angular/angular / applyWithProgram

Method applyWithProgram

tools/tslint/noDuplicateEnumValuesRule.ts:26–53  ·  view source on GitHub ↗
(sourceFile: ts.SourceFile, program: ts.Program)

Source from the content-addressed store, hash-verified

24 */
25export class Rule extends TypedRule {
26 override applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[] {
27 const checker = program.getTypeChecker();
28
29 return this.applyWithFunction(sourceFile, (ctx) => {
30 ts.forEachChild(sourceFile, function walk(node) {
31 if (ts.isEnumDeclaration(node)) {
32 const seenValues = new Map<string | number, ts.Node>();
33 for (const member of node.members) {
34 const value = checker.getConstantValue(member);
35 if (value !== undefined) {
36 if (seenValues.has(value)) {
37 ctx.addFailureAtNode(
38 member,
39 `Enum member has a duplicate value '${value}'. First occurrence is on line ${
40 sourceFile.getLineAndCharacterOfPosition(seenValues.get(value)!.getStart())
41 .line + 1
42 }.`,
43 );
44 } else {
45 seenValues.set(value, member);
46 }
47 }
48 }
49 }
50 ts.forEachChild(node, walk);
51 });
52 });
53 }
54}

Callers

nothing calls this directly

Calls 4

getTypeCheckerMethod · 0.80
hasMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected