Blame view

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