(sourceFile: ts.SourceFile, program: ts.Program)
| 24 | */ |
| 25 | export 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 | } |
nothing calls this directly
no test coverage detected