feat: add react/no-find-dom-node lint rule
MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -123,6 +123,7 @@ type LintDiagnosticCategory =
| 'lint/noEmptyCharacterClass'
| 'lint/noExplicitAny'
| 'lint/noExtraBooleanCast'
+ | 'lint/noFindDOMNode'
| 'lint/noFunctionAssign'
| 'lint/noImportAssign'
| 'lint/noLabelVar'

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -330,6 +330,10 @@ export const descriptions = createMessages({
category: 'lint/noDangerWithChildren',
message: 'Only set one of <emphasis>children</emphasis> or <emphasis>props.dangerouslySetInnerHTML</emphasis>.',
},
+ NO_FIND_DOM_NODE: {
+ category: 'lint/noFindDOMNode',
+ message: 'Do not use findDOMNode',
+ },
PENDING_FIXES: (
relativeFilename: string,
original: string,

MODIFY
packages/@romejs/js-compiler/lint/rules/index.ts
packages/@romejs/js-compiler/lint/rules/index.ts
@@ -37,6 +37,7 @@ import noDuplicateKeys from './regular/noDuplicateKeys';
import noEmptyCharacterClass from './regular/noEmptyCharacterClass';
import noExplicitAny from './regular/noExplicitAny';
import noExtraBooleanCast from './regular/noExtraBooleanCast';
+import noFindDOMNode from './react/noFindDOMNode';
import noFunctionAssign from './regular/noFunctionAssign';
import noImportAssign from './regular/noImportAssign';
import noLabelVar from './regular/noLabelVar';
@@ -96,6 +97,7 @@ export const lintTransforms = [
noEmptyCharacterClass,
noExplicitAny,
noExtraBooleanCast,
+ noFindDOMNode,
noFunctionAssign,
noImportAssign,
noLabelVar,

ADD
packages/@romejs/js-compiler/lint/rules/react/noFindDOMNode.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(
+ 'do not allow findDOMNode',
+ async (t) => {
+ await testLintMultiple(
+ t,
+ [
+ // INVALID
+ 'findDOMNode(this).scrollIntoView()',
+ 'ReactDOM.findDOMNode(this).scrollIntoView()',
+ // VALID
+ 'this.node.scrollIntoView()',
+ ],
+ {category: 'lint/noFindDOMNode'},
+ );
+ },
+);

ADD
packages/@romejs/js-compiler/lint/rules/react/noFindDOMNode.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 {descriptions} from '@romejs/diagnostics';
+import {AnyNode} from '@romejs/js-ast';
+import {Path} from '@romejs/js-compiler';
+import {doesNodeMatchPattern} from '@romejs/js-ast-utils';
+
+function hasFindMemberProperty(node: AnyNode) {
+ return node.type === 'StaticMemberProperty' && doesNodeMatchPattern(node.value, 'findDOMNode')
+}
+
+function hasFindCallExpression(node: AnyNode) {
+ return node.type ==='CallExpression' && doesNodeMatchPattern(node.callee, 'findDOMNode')
+}
+
+export default {
+ name: 'noFindDOMNode',
+
+ enter(path: Path): AnyNode {
+ const {node} = path;
+
+ if (hasFindMemberProperty(node) || hasFindCallExpression(node)) {
+ path.context.addNodeDiagnostic(node, descriptions.LINT.NO_FIND_DOM_NODE);
+ }
+
+ return node;
+ },
+};

feat: add react/no-find-dom-node lint rule