|
4 | 4 | // Ported from https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/no-unknown-property.js |
5 | 5 | // TODO: Port to TypeScript |
6 | 6 |
|
| 7 | +import { decodeSettings, normalizeSettings } from "@eslint-react/shared"; |
7 | 8 | import { createRule } from "../utils"; |
| 9 | +import { compare, compareVersions } from "compare-versions"; |
8 | 10 |
|
9 | 11 | // ------------------------------------------------------------------------------ |
10 | 12 | // Constants |
@@ -419,10 +421,6 @@ const DOM_PROPERTY_NAMES_ONE_WORD = [ |
419 | 421 | "security", |
420 | 422 | // Video specific |
421 | 423 | "controls", |
422 | | - // popovers |
423 | | - "popover", |
424 | | - "popovertarget", |
425 | | - "popovertargetaction", |
426 | 424 | ]; |
427 | 425 |
|
428 | 426 | const DOM_PROPERTY_NAMES_TWO_WORDS = [ |
@@ -890,16 +888,29 @@ const REACT_ON_PROPS = [ |
890 | 888 | "onPointerUpCapture", |
891 | 889 | ]; |
892 | 890 |
|
| 891 | +const POPOVER_API_PROPS = [ |
| 892 | + "popover", |
| 893 | + "popoverTarget", |
| 894 | + "popoverTargetAction", |
| 895 | + "onToggle", |
| 896 | + "onBeforeToggle", |
| 897 | +]; |
| 898 | + |
893 | 899 | function getDOMPropertyNames(context) { |
894 | 900 | const ALL_DOM_PROPERTY_NAMES = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD); |
895 | 901 | // this was removed in React v16.1+, see https://github.com/facebook/react/pull/10823 |
896 | | - if (!testReactVersion(context, ">= 16.1.0")) { |
897 | | - return ALL_DOM_PROPERTY_NAMES.concat("allowTransparency"); |
| 902 | + if (testReactVersion(context, "<=", "16.1.0")) { |
| 903 | + ALL_DOM_PROPERTY_NAMES.push("allowTransparency"); |
| 904 | + return ALL_DOM_PROPERTY_NAMES; |
898 | 905 | } |
899 | 906 | // 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 |
900 | | - if (testReactVersion(context, ">= 16.4.0")) { |
901 | | - return ALL_DOM_PROPERTY_NAMES.concat(REACT_ON_PROPS); |
| 907 | + if (testReactVersion(context, ">=", "16.4.0")) { |
| 908 | + ALL_DOM_PROPERTY_NAMES.push(...REACT_ON_PROPS); |
902 | 909 | } |
| 910 | + // these were added in React v19.0.0-rc.0, see https://github.com/facebook/react/pull/27981 |
| 911 | + testReactVersion(context, ">=", "19.0.0-rc.0") |
| 912 | + ? ALL_DOM_PROPERTY_NAMES.push(...POPOVER_API_PROPS) |
| 913 | + : ALL_DOM_PROPERTY_NAMES.push(...POPOVER_API_PROPS.map((prop) => prop.toLowerCase())); |
903 | 914 | return ALL_DOM_PROPERTY_NAMES; |
904 | 915 | } |
905 | 916 |
|
@@ -1185,6 +1196,8 @@ function report(context, message, messageId, data) { |
1185 | 1196 | }); |
1186 | 1197 | } |
1187 | 1198 |
|
1188 | | -function testReactVersion(context, version) { |
1189 | | - return true; |
| 1199 | +function testReactVersion(context, comparator, version) { |
| 1200 | + const { version: localVersion } = normalizeSettings(decodeSettings(context.settings)); |
| 1201 | + console.log(localVersion, version, comparator); |
| 1202 | + return compare(localVersion, version, comparator); |
1190 | 1203 | } |
0 commit comments