jsx-eslint / eslint-plugin-jsx-a11y

Static AST checker for a11y rules on JSX elements.
MIT License
3.39k stars 636 forks source link

heading-has-content false positive for object spread #980

Open wozitto opened 6 months ago

wozitto commented 6 months ago

The code throws an error.

const SectionTitle = (props) => (
  <h2 {...props} />
);

However, this code does not throw an error.

const SectionTitle = (props) => (
  <h2 {...props} >{props.children}</h2>
);

Both syntaxes produce the same output when rendered, which leads me to believe that the first syntax should not result in an error either.

Version: 6.8.0

スクリーンショット 2024-04-17 22 40 42
ljharb commented 5 months ago

This is the natural limits of syntactic analysis - we can’t know if children is included in the props, so we have to require a syntactic children placement.