From 500112bb2d541f5cdf527cc3328902287e2bc90b Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Thu, 19 Sep 2024 16:31:41 +0000 Subject: [PATCH] [Fix] `no-unknown-property` support new `precedence` prop Fixes #3827 --- CHANGELOG.md | 5 +++++ lib/rules/no-unknown-property.js | 14 +++++++++----- tests/lib/rules/no-unknown-property.js | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edfba39195..4ddd9379c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased +### Fixed +* [`no-unknown-property`]: support `precedence` prop ([#3829][] @acusti) + +[#3829]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3829 + ## [7.36.1] - 2024.09.12 ### Fixed diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index dc5018007a..d73cb57204 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -234,7 +234,7 @@ const DOM_PROPERTY_NAMES_ONE_WORD = [ // OpenGraph meta tag attributes 'property', // React specific attributes - 'ref', 'key', 'children', + 'ref', 'key', 'children', 'precedence', // Non-standard 'results', 'security', // Video specific @@ -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-0')) { + domPropertyNames = domPropertyNames.concat('precedence'); + } } - return ALL_DOM_PROPERTY_NAMES; + return domPropertyNames; } // ------------------------------------------------------------------------------ diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index 32e6c6d6b3..c4b229ceff 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -89,6 +89,7 @@ ruleTester.run('no-unknown-property', rule, { { code: '
' }, { code: '' }, { code: '
' }, + { code: '' }, // Case ignored attributes, for `charset` discussion see https://github.com/jsx-eslint/eslint-plugin-react/pull/1863 { code: ';' }, { code: ';' },