Add noCommaOperator rule
MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -108,6 +108,7 @@ type LintDiagnosticCategory =
| 'lint/noAsyncPromiseExecutor'
| 'lint/noCatchAssign'
| 'lint/noChildrenProp'
+ | 'lint/noCommaOperator'
| 'lint/noCompareNegZero'
| 'lint/noCondAssign'
| 'lint/noDebugger'

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -291,6 +291,17 @@ export const descriptions = createMessages({
},
// @romejs/js-compiler
LINT: {
+ NO_COMMA_OPERATOR: {
+ category: 'lint/noCommaOperator',
+ message: 'Avoid usage of the comma operator. It can lead to easy mistakes and ambiguous code.',
+ advice: [
+ {
+ type: 'log',
+ category: 'info',
+ text: 'If you want multiple expressions then break it up.',
+ },
+ ],
+ },
NEGATION_ELSE: {
category: 'lint/negationElse',
message: 'Invert the blocks when you have a negation test',

MODIFY
packages/@romejs/js-compiler/lint/rules/index.ts
packages/@romejs/js-compiler/lint/rules/index.ts
@@ -22,6 +22,7 @@ import noArguments from './regular/noArguments';
import noAsyncPromiseExecutor from './regular/noAsyncPromiseExecutor';
import noCatchAssign from './regular/noCatchAssign';
import noChildrenProp from './react/noChildrenProp';
+import noCommaOperator from './regular/noCommaOperator';
import noCompareNegZero from './regular/noCompareNegZero';
import noCondAssign from './regular/noCondAssign';
import noDebugger from './regular/noDebugger';
@@ -76,6 +77,7 @@ export const lintTransforms = [
noAsyncPromiseExecutor,
noCatchAssign,
noChildrenProp,
+ noCommaOperator,
noCompareNegZero,
noCondAssign,
noDebugger,

ADD
packages/@romejs/js-compiler/lint/rules/regular/noCommaOperator.test.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 {test} from 'rome';
+import {testLintMultiple} from '../testHelpers';
+
+test(
+ 'no comma operator',
+ async (t) => {
+ await testLintMultiple(
+ t,
+ [
+ // INVALID
+ '(0, 1, 2)',
+ ],
+ {category: 'lint/noCommaOperator'},
+ );
+ },
+);

ADD
packages/@romejs/js-compiler/lint/rules/regular/noCommaOperator.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 {descriptions} from '@romejs/diagnostics';
+
+export default {
+ name: 'noCommaOperator',
+ enter(path: Path): AnyNode {
+ const {node} = path;
+
+ if (node.type === 'SequenceExpression') {
+ path.context.addNodeDiagnostic(node, descriptions.LINT.NO_COMMA_OPERATOR);
+ }
+
+ return node;
+ },
+};

Add noCommaOperator rule