Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow accidental comments in JSX from being inserted as text nodes (react/jsx-no-comment-textnodes) #1368

Closed
feross opened this issue Aug 15, 2019 · 1 comment

Comments

@feross
Copy link
Member

feross commented Aug 15, 2019

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md

This rule prevents comment strings (e.g. beginning with // or /*) from being accidentally
injected as a text node in JSX statements.

Rule Details

The following patterns are considered warnings:

var Hello = createReactClass({
  render: function() {
    return (
      <div>// empty div</div>
    );
  }
});

var Hello = createReactClass({
  render: function() {
    return (
      <div>
        /* empty div */
      </div>
    );
  }
});

The following patterns are not considered warnings:

var Hello = createReactClass({
  displayName: 'Hello',
  render: function() {
    return <div>{/* empty div */}</div>;
  }
});

var Hello = createReactClass({
  displayName: 'Hello',
  render: function() {
    return <div /* empty div */></div>;
  }
});

var Hello = createReactClass({
  displayName: 'Hello',
  render: function() {
    return <div className={'foo' /* temp class */}</div>;
  }
});

Legitimate uses

It's possible you may want to legitimately output comment start characters (// or /*)
in a JSX text node. In which case, you can do the following:

var Hello = createReactClass({
  render: function() {
    return (
      <div>{'/* This will be output as a text node */'}</div>
    );
  }
});
@feross feross added this to the standard 14 milestone Aug 15, 2019
@feross feross changed the title Disallow accidental comments from being inserted as text nodes (react/jsx-no-comment-textnodes) Disallow accidental comments in JSX from being inserted as text nodes (react/jsx-no-comment-textnodes) Aug 15, 2019
@feross
Copy link
Member Author

feross commented Aug 15, 2019

Shipping in standard 14.

@feross feross closed this as completed in 29861dc Aug 15, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2021
suchitg8 pushed a commit to suchitg8/standard that referenced this issue Apr 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

1 participant