Skip to content

Commit

Permalink
[Fix] no-unknown-property support new precedence prop
Browse files Browse the repository at this point in the history
Fixes #3827
  • Loading branch information
acusti committed Dec 9, 2024
1 parent d5da0a6 commit 9bb6f62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Fixed
* [`no-danger`]: avoid a crash on a nested component name ([#3833][] @ljharb)
* [Fix] types: correct generated type declaration ([#3840][] @ocavue)
* [`no-unknown-property`]: support `precedence` prop ([#3829][] @acusti)

### Changed
* [Tests] [`jsx-no-script-url`]: Improve tests ([#3849][] @radu2147)

[#3849]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3849
[#3840]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3840
[#3833]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3833
[#3829]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3829

## [7.37.2] - 2024.10.22

Expand Down
12 changes: 8 additions & 4 deletions lib/rules/no-unknown-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,20 @@ const REACT_ON_PROPS = [
];

function getDOMPropertyNames(context) {
const ALL_DOM_PROPERTY_NAMES = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD);
let domPropertyNames = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD);
// this was removed in React v16.1+, see https://github.com/facebook/react/pull/10823
if (!testReactVersion(context, '>= 16.1.0')) {
return ALL_DOM_PROPERTY_NAMES.concat('allowTransparency');
return domPropertyNames.concat('allowTransparency');
}
// these were added in React v16.4.0, see https://reactjs.org/blog/2018/05/23/react-v-16-4.html and https://github.com/facebook/react/pull/12507
if (testReactVersion(context, '>= 16.4.0')) {
return ALL_DOM_PROPERTY_NAMES.concat(REACT_ON_PROPS);
domPropertyNames = domPropertyNames.concat(REACT_ON_PROPS);
// precedence was added in React v19, see https://react.dev/blog/2024/04/25/react-19#support-for-stylesheets
if (testReactVersion(context, '>= 19.0.0')) {
domPropertyNames = domPropertyNames.concat('precedence');
}
}
return ALL_DOM_PROPERTY_NAMES;
return domPropertyNames;
}

// ------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-unknown-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ ruleTester.run('no-unknown-property', rule, {
{ code: '<div onPointerDown={this.onDown} onPointerUp={this.onUp} />' },
{ code: '<input type="checkbox" defaultChecked={this.state.checkbox} />' },
{ code: '<div onTouchStart={this.startAnimation} onTouchEnd={this.stopAnimation} onTouchCancel={this.cancel} onTouchMove={this.move} onMouseMoveCapture={this.capture} onTouchCancelCapture={this.log} />' },
{
code: '<link precedence="medium" href="https://foo.bar" rel="canonical" />',
settings: {
react: { version: '19.0.0' },
},
},
// Case ignored attributes, for `charset` discussion see https://github.com/jsx-eslint/eslint-plugin-react/pull/1863
{ code: '<meta charset="utf-8" />;' },
{ code: '<meta charSet="utf-8" />;' },
Expand Down

0 comments on commit 9bb6f62

Please sign in to comment.