Add doubleEquals lint suggestion
MODIFY
packages/@romejs/cli/cli.ts
packages/@romejs/cli/cli.ts
@@ -364,7 +364,7 @@ export default async function cli() {
}
case 'DIAGNOSTICS': {
- process.exit(1);
+ process.exit(res.diagnostics.length === 0 ? 0 : 1);
break;
}

MODIFY
packages/@romejs/js-compiler/lint/rules/doubleEquals.ts
packages/@romejs/js-compiler/lint/rules/doubleEquals.ts
@@ -9,6 +9,8 @@ import {Path} from '@romejs/js-compiler';
import {AnyNode} from '@romejs/js-ast';
import {descriptions} from '@romejs/diagnostics';
+const SUGGESTION_DESCRIPTION = 'This may be unsafe if you are relying on type coercion';
+
export default {
name: 'doubleEquals',
enter(path: Path): AnyNode {
@@ -17,11 +19,35 @@ export default {
if (node.type === 'BinaryExpression' && node.right.type !== 'NullLiteral' &&
node.left.type !== 'NullLiteral') {
if (node.operator === '!=') {
- context.addNodeDiagnostic(node, descriptions.LINT.NEGATE_DOUBLE_EQUALS);
+ context.addFixableDiagnostic({
+ old: node,
+ suggestions: [
+ {
+ title: 'Use !==',
+ description: SUGGESTION_DESCRIPTION,
+ fixed: {
+ ...node,
+ operator: '!==',
+ },
+ },
+ ],
+ }, descriptions.LINT.NEGATE_DOUBLE_EQUALS);
}
if (node.operator === '==') {
- context.addNodeDiagnostic(node, descriptions.LINT.DOUBLE_EQUALS);
+ context.addFixableDiagnostic({
+ old: node,
+ suggestions: [
+ {
+ title: 'Use ===',
+ description: SUGGESTION_DESCRIPTION,
+ fixed: {
+ ...node,
+ operator: '===',
+ },
+ },
+ ],
+ }, descriptions.LINT.DOUBLE_EQUALS);
}
}

Add doubleEquals lint suggestion