Rel1cx / eslint-react

A series of composable ESLint plugins for libraries and frameworks that use React as a UI runtime.
https://eslint-react.xyz
MIT License
255 stars 11 forks source link

[bug] HTML characters should be allowed inside of `no-useless-fragment` #850

Open imjordanxd opened 5 hours ago

imjordanxd commented 5 hours ago

Describe the bug

The following code produces an error but is a false positive:

function Foo() {
    return <>&nbsp;</>;
}

Reproduction

No response

Expected behavior

An error should not be reported in this case.

Platform and versions

Node 20.18.0
@eslint-react 1.15.0

Stack trace

No response

Additional context

No response

SukkaW commented 2 hours ago

Any more reproduction?

With React 18.3+ and TypeScript 5.4+, it is possible to return a string in a Component now. Your current reproduction can be simplified without fragments:

function Foo() {
  return '&nbsp;';
}
imjordanxd commented 1 hour ago

@SukkaW unfortunately, that won't work. &nbsp; is a reserved entity in HTML. React handles strings for us. It's the same reason we can't return '<div>Hello, world</div>'. We wouldn't expect that to work! Here's a codesandbox.

SukkaW commented 29 minutes ago

@SukkaW unfortunately, that won't work. &nbsp; is a reserved entity in HTML. React handles strings for us. It's the same reason we can't return '<div>Hello, world</div>'. We wouldn't expect that to work! Here's a codesandbox.

Then it would be:

function Foo() {
  return ' ';
}

or

function Foo() {
  return '\xA0';
}

Most modern compilers (esbuild, swc) will transform alone &nbsp;.