2 * @fileoverview Rule to disallow a duplicate case label.
3 * @author Dieter Oberkofler
4 * @author Burak Yigit Kaya
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
18 description: "disallow duplicate case labels",
19 category: "Possible Errors",
21 url: "https://eslint.org/docs/rules/no-duplicate-case"
27 unexpected: "Duplicate case label."
32 const sourceCode = context.getSourceCode();
35 SwitchStatement(node) {
36 const previousKeys = new Set();
38 for (const switchCase of node.cases) {
39 if (switchCase.test) {
40 const key = sourceCode.getText(switchCase.test);
42 if (previousKeys.has(key)) {
43 context.report({ node: switchCase, messageId: "unexpected" });
45 previousKeys.add(key);