]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-duplicate-case.js
e2d9665e7f564d8fced4fbba68fe7def57756f67
2 * @fileoverview Rule to disallow a duplicate case label.
3 * @author Dieter Oberkofler
4 * @author Burak Yigit Kaya
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 const astUtils
= require("./utils/ast-utils");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
24 description
: "disallow duplicate case labels",
25 category
: "Possible Errors",
27 url
: "https://eslint.org/docs/rules/no-duplicate-case"
33 unexpected
: "Duplicate case label."
38 const sourceCode
= context
.getSourceCode();
41 * Determines whether the two given nodes are considered to be equal.
42 * @param {ASTNode} a First node.
43 * @param {ASTNode} b Second node.
44 * @returns {boolean} `true` if the nodes are considered to be equal.
46 function equal(a
, b
) {
47 if (a
.type
!== b
.type
) {
51 return astUtils
.equalTokens(a
, b
, sourceCode
);
54 SwitchStatement(node
) {
55 const previousTests
= [];
57 for (const switchCase
of node
.cases
) {
58 if (switchCase
.test
) {
59 const test
= switchCase
.test
;
61 if (previousTests
.some(previousTest
=> equal(previousTest
, test
))) {
62 context
.report({ node
: switchCase
, messageId
: "unexpected" });
64 previousTests
.push(test
);