Added react/jsx-no-comment-textnodes lint rule.
MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -67,6 +67,7 @@ export type DiagnosticCategory =
| 'lint/undeclaredVariables'
| 'lint/unsafeNegation'
| 'lint/unusedVariables'
+ | 'lint/react/jsxNoCommentTextnodes'
| 'lsp/parse'
| 'parse/js'
| 'parse/json'

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -347,6 +347,10 @@ export const descriptions = createMessages({
category: 'lint/preferWhile',
message: 'A while loop should be used over a for loop',
},
+ REACT_JSX_NO_COMMENT_TEXTNODES: {
+ category: 'lint/react/jsxNoCommentTextnodes',
+ message: 'Comments inside children should be placed in braces',
+ },
UNSAFE_NEGATION: {
category: 'lint/unsafeNegation',
message: 'Unsafe usage of negation operator in left side of binary expression',

MODIFY
packages/@romejs/js-compiler/lint/rules/index.ts
packages/@romejs/js-compiler/lint/rules/index.ts
@@ -51,6 +51,7 @@ import sparseArray from './sparseArray';
import undeclaredVariables from './undeclaredVariables';
import unsafeNegation from './unsafeNegation';
import unusedVariables from './unusedVariables';
+import {reactLintTransforms} from './react';
// Add transforms in alphabetical order.
export const lintTransforms = [
@@ -99,4 +100,7 @@ export const lintTransforms = [
undeclaredVariables,
unsafeNegation,
unusedVariables,
+
+ // React lint rules.
+ ...reactLintTransforms,
];

ADD
packages/@romejs/js-compiler/lint/rules/react/index.ts
+import jsxNoCommentTextnodes from './jsxNoCommentTextnodes';
+
+// Add transforms in alphabetical order.
+export const reactLintTransforms = [
+ jsxNoCommentTextnodes,
+];

ADD
packages/@romejs/js-compiler/lint/rules/react/jsxNoCommentTextnodes.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(
+ 'case single statement',
+ async (t) => {
+ await testLintMultiple(
+ t,
+ [
+ // INVALID
+ 'const a = <div>// comment</div>',
+ 'const a = <div>/* comment */</div>',
+ // VALID
+ 'const a = <div>{/* comment */}</div>',
+ 'const a = <div className={"cls" /* comment */}></div>',
+ ],
+ {category: 'lint/react/jsxNoCommentTextnodes'},
+ );
+ },
+);

ADD
packages/@romejs/js-compiler/lint/rules/react/jsxNoCommentTextnodes.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: 'jsxNoCommentTextnodes',
+ enter(path: Path): AnyNode {
+ const {node} = path;
+
+ if (node.type === 'JSXText') {
+ if (/^\s*\/(\/|\*)/m.test(node.value)) {
+ path.context.addNodeDiagnostic(node, descriptions.LINT.REACT_JSX_NO_COMMENT_TEXTNODES);
+ }
+ }
+
+ return node;
+ },
+};

Added react/jsx-no-comment-textnodes lint rule.