UNPKG

945 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to disallow a duplicate case label.
3 * @author Dieter Oberkofler
4 * @author Burak Yigit Kaya
5 * @copyright 2015 Dieter Oberkofler. All rights reserved.
6 * @copyright 2015 Burak Yigit Kaya. All rights reserved.
7 */
8
9"use strict";
10
11//------------------------------------------------------------------------------
12// Rule Definition
13//------------------------------------------------------------------------------
14
15module.exports = function(context) {
16
17 return {
18 "SwitchStatement": function(node) {
19 var mapping = {};
20
21 node.cases.forEach(function(switchCase) {
22 var key = context.getSource(switchCase.test);
23 if (mapping[key]) {
24 context.report(switchCase, "Duplicate case label.");
25 } else {
26 mapping[key] = switchCase;
27 }
28 });
29 }
30 };
31};
32
33module.exports.schema = [];