Checks for duplicate switch case declarations
MODIFY
packages/@romejs/js-compiler/transforms/lint/index.ts
packages/@romejs/js-compiler/transforms/lint/index.ts
@@ -17,6 +17,7 @@ import noCondAssign from './noCondAssign';
import noDebugger from './noDebugger';
import noDeleteVars from './noDeleteVars';
import noDupeArgs from './noDupeArgs';
+import noDuplicateCase from './noDuplicateCase';
import noDuplicateKeys from './noDuplicateKeys';
import noEmptyCharacterClass from './noEmptyCharacterClass';
import noExtraBooleanCast from './noExtraBooleanCast';
@@ -46,6 +47,7 @@ export const lintTransforms = [
noDebugger,
noDeleteVars,
noDupeArgs,
+ noDuplicateCase,
noDuplicateKeys,
noEmptyCharacterClass,
noExtraBooleanCast,

ADD
packages/@romejs/js-compiler/transforms/lint/noDuplicateCase.ts
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+import {Path} from '@romejs/js-compiler';
+import {AnyNode} from '@romejs/js-ast';
+
+export default {
+ name: 'noDuplicateCase',
+ enter(path: Path): AnyNode {
+ const {node, context} = path;
+
+ if (node.type === 'SwitchStatement') {
+ let uniqueSwitchCases = new Set();
+
+ for (const param of node.cases) {
+ const test: any = param.test;
+
+ if (test && test.value && uniqueSwitchCases.has(test.value)) {
+ context.addNodeDiagnostic(param, {
+ category: 'lint/noDuplicateCase',
+ message: `Duplicate case <emphasis>${test.value}</emphasis> not allowed`,
+ });
+ }
+
+ test && uniqueSwitchCases.add(test.value);
+ }
+ }
+
+ return node;
+ },
+};

Checks for duplicate switch case declarations