charlike
Version:
Small, fast, simple and streaming project scaffolder for myself, but not only. Supports hundreds of template engines through the @JSTransformers API or if you want custom `render` function passed through options
44 lines (35 loc) • 1.1 kB
JavaScript
/**
* @fileoverview Rule to disallow a duplicate case label.
* @author Dieter Oberkofler
* @author Burak Yigit Kaya
*/
;
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: "disallow duplicate case labels",
category: "Possible Errors",
recommended: true
},
schema: []
},
create(context) {
const sourceCode = context.getSourceCode();
return {
SwitchStatement(node) {
const mapping = {};
node.cases.forEach(switchCase => {
const key = sourceCode.getText(switchCase.test);
if (mapping[key]) {
context.report(switchCase, "Duplicate case label.");
} else {
mapping[key] = switchCase;
}
});
}
};
}
};