Adds no-dupe-args check to lint
MODIFY
packages/@romejs/js-compiler/__rtests__/lint.ts
packages/@romejs/js-compiler/__rtests__/lint.ts
@@ -219,3 +219,19 @@ test('no duplicate keys', async t => {
},
]);
});
+
+test('no duplicated args allowed', async t => {
+ const duplicatedArgs = await testLint(
+ `
+ function hello(a, a) {
+ console.log("Hello);
+ }
+ hello();
+ `,
+ LINT_ENABLED_FORMAT_DISABLED_CONFIG,
+ );
+
+ t.truthy(
+ duplicatedArgs.diagnostics.find(d => d.category === 'lint/noDupeArgs'),
+ );
+});

MODIFY
packages/@romejs/js-compiler/transforms/lint/index.ts
packages/@romejs/js-compiler/transforms/lint/index.ts
@@ -14,6 +14,7 @@ import unsafeNegation from './unsafeNegation';
import noAsyncPromiseExecutor from './noAsyncPromiseExecutor';
import noLabelVar from './noLabelVar';
import noDuplicateKeys from './noDuplicateKeys';
+import noDupeArgs from './noDupeArgs';
export const lintTransforms = [
undeclaredVariables,
@@ -25,4 +26,5 @@ export const lintTransforms = [
noAsyncPromiseExecutor,
noLabelVar,
noDuplicateKeys,
+ noDupeArgs,
];

ADD
packages/@romejs/js-compiler/transforms/lint/noDupeArgs.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';
+import { getBindingIdentifiers } from '@romejs/js-ast-utils';
+
+export default {
+ name: 'noDupeArgs',
+ enter(path: Path): AnyNode {
+ const {node, context} = path;
+
+ if (node.type === 'FunctionHead') {
+ const uniqueIdentifiers = new Set();
+
+ for (const param of node.params) {
+ for (const {name} of getBindingIdentifiers(param)) {
+
+ if (uniqueIdentifiers.has(name)) {
+ context.addNodeDiagnostic(param, {
+ category: 'lint/noDupeArgs',
+ message: `Duplicate argument <emphasis>${name}</emphasis> in function definition`,
+ });
+ }
+
+ uniqueIdentifiers.add(name);
+ }
+ }
+ }
+
+ return node;
+ },
+};

Adds no-dupe-args check to lint