node/tools/eslint/lib/rules/no-duplicate-case.js
silverwind d9b8758f47 tools: update ESLint to 2.7.0
PR-URL: https://github.com/nodejs/node/pull/6132
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: thefourtheye <thechargingvolcano@gmail.com>
2016-04-20 16:24:21 -07:00

34 lines
946 B
JavaScript

/**
* @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 = [];