UNPKG

e-lado

Version:

[![CircleCI](https://circleci.com/gh/sharetribe/sharetribe/tree/master.svg?style=svg)](https://circleci.com/gh/sharetribe/sharetribe/tree/master) [![Dependency Status](https://gemnasium.com/sharetribe/sharetribe.png)](https://gemnasium.com/sharetribe/shar

44 lines (35 loc) 1.11 kB
/** * @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(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({ node: switchCase, message: "Duplicate case label." }); } else { mapping[key] = switchCase; } }); } }; } };