add unsafeNegotiation to lint for in and instanceof
MODIFY
packages/@romejs/js-compiler/transforms/lint/index.ts
packages/@romejs/js-compiler/transforms/lint/index.ts
@@ -9,10 +9,12 @@ import defaultExportSameBasename from './defaultExportSameBasename';
import undeclaredVariables from './undeclaredVariables';
import unusedVariables from './unusedVariables';
import emptyBlocks from './emptyBlocks';
+import unsafeNegation from './unsafeNegation';
export const lintTransforms = [
undeclaredVariables,
defaultExportSameBasename,
unusedVariables,
emptyBlocks,
+ unsafeNegation,
];

ADD
packages/@romejs/js-compiler/transforms/lint/unsafeNegation.ts
+import {Path} from '@romejs/js-compiler';
+import {AnyNode} from '@romejs/js-ast';
+import {markup} from '@romejs/string-markup';
+
+export default {
+ name: 'unsafeNegation',
+ enter(path: Path): AnyNode {
+ const {node} = path;
+ if (
+ node.type === 'BinaryExpression' &&
+ (node.operator === 'in' || node.operator === 'instanceof') &&
+ node.left.type === 'UnaryExpression' &&
+ node.left.operator === '!'
+ ) {
+ path.context.addNodeDiagnostic(node, {
+ category: 'lint/unsafeNegation',
+ message: markup`Unsafe usage of negation operator in left side of binary expression`,
+ });
+ }
+ return node;
+ },
+};

add unsafeNegotiation to lint for in and instanceof