Skip to content

Commit 87fcdc4

Browse files
authored
fix(plugins/dom): add popover api props to 'no-unknown-property', clo… (#865)
1 parent eaa5b04 commit 87fcdc4

File tree

5 files changed

+50
-14
lines changed

5 files changed

+50
-14
lines changed

packages/plugins/eslint-plugin-react-dom/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@typescript-eslint/scope-manager": "^8.15.0",
5959
"@typescript-eslint/types": "^8.15.0",
6060
"@typescript-eslint/utils": "^8.15.0",
61+
"compare-versions": "^6.1.1",
6162
"ts-pattern": "^5.5.0"
6263
},
6364
"devDependencies": {

packages/plugins/eslint-plugin-react-dom/src/rules/no-unknown-property.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,25 @@ ruleTester.run(RULE_NAME, rule, {
655655
<div popover id="my-popover">Greetings, one and all!</div>
656656
</div>
657657
`,
658+
settings: {
659+
"react-x": {
660+
version: "18.3.1",
661+
},
662+
},
663+
},
664+
{
665+
code: `
666+
<div>
667+
<button popoverTarget="my-popover" popoverTargetAction="toggle">Open Popover</button>
668+
669+
<div popover id="my-popover">Greetings, one and all!</div>
670+
</div>
671+
`,
672+
settings: {
673+
"react-x": {
674+
version: "19.0.0-rc.0",
675+
},
676+
},
658677
},
659678
],
660679
});

packages/plugins/eslint-plugin-react-dom/src/rules/no-unknown-property.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// Ported from https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/no-unknown-property.js
55
// TODO: Port to TypeScript
66

7+
import { decodeSettings, normalizeSettings } from "@eslint-react/shared";
78
import { createRule } from "../utils";
9+
import { compare, compareVersions } from "compare-versions";
810

911
// ------------------------------------------------------------------------------
1012
// Constants
@@ -419,10 +421,6 @@ const DOM_PROPERTY_NAMES_ONE_WORD = [
419421
"security",
420422
// Video specific
421423
"controls",
422-
// popovers
423-
"popover",
424-
"popovertarget",
425-
"popovertargetaction",
426424
];
427425

428426
const DOM_PROPERTY_NAMES_TWO_WORDS = [
@@ -890,16 +888,29 @@ const REACT_ON_PROPS = [
890888
"onPointerUpCapture",
891889
];
892890

891+
const POPOVER_API_PROPS = [
892+
"popover",
893+
"popoverTarget",
894+
"popoverTargetAction",
895+
"onToggle",
896+
"onBeforeToggle",
897+
];
898+
893899
function getDOMPropertyNames(context) {
894900
const ALL_DOM_PROPERTY_NAMES = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD);
895901
// 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;
898905
}
899906
// 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);
902909
}
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()));
903914
return ALL_DOM_PROPERTY_NAMES;
904915
}
905916

@@ -1185,6 +1196,8 @@ function report(context, message, messageId, data) {
11851196
});
11861197
}
11871198

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);
11901203
}

packages/plugins/eslint-plugin-react-x/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"@typescript-eslint/types": "^8.15.0",
6161
"@typescript-eslint/utils": "^8.15.0",
6262
"compare-versions": "^6.1.1",
63-
"is-immutable-type": "5.0.0",
63+
"is-immutable-type": "^5.0.0",
6464
"ts-pattern": "^5.5.0"
6565
},
6666
"devDependencies": {

pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)