mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
42 lines
1.0 KiB
/**
|
|
* @fileoverview Rule to disallow a duplicate case label.
|
|
* @author Dieter Oberkofler
|
|
* @author Burak Yigit Kaya
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = {
|
|
meta: {
|
|
docs: {
|
|
description: "disallow duplicate case labels",
|
|
category: "Possible Errors",
|
|
recommended: true
|
|
},
|
|
|
|
schema: []
|
|
},
|
|
|
|
create: 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;
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|