node/tools/eslint/lib/rules/no-duplicate-case.js
Michaël Zasso 2d441493a4 tools: update eslint to v1.10.3
PR-URL: https://github.com/nodejs/io.js/pull/2286
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-01-13 23:15:39 +01:00

34 lines
945 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 = [];