From 7ba28c8972a050e640b61d35af9d2adf0df87747 Mon Sep 17 00:00:00 2001 From: Christian Gonzalez <1581488+christiango@users.noreply.github.com> Date: Mon, 27 Oct 2025 21:52:11 +0000 Subject: [PATCH 1/4] Handle unions in no-postmessage-star-origin --- lib/rules/no-postmessage-star-origin.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-postmessage-star-origin.js b/lib/rules/no-postmessage-star-origin.js index 5a76c0e..83d3067 100644 --- a/lib/rules/no-postmessage-star-origin.js +++ b/lib/rules/no-postmessage-star-origin.js @@ -9,6 +9,10 @@ const astUtils = require("../ast-utils"); +function isWindowOrAny(type) { + return type === "any" || type === "Window"; +} + module.exports = { meta: { type: "suggestion", @@ -41,7 +45,16 @@ module.exports = { ); const tsType = fullTypeChecker.getTypeAtLocation(tsNode); const type = fullTypeChecker.typeToString(tsType); - if (type !== "any" && type !== "Window") { + if (!isWindowOrAny(type)) { + return; + } + + if ( + tsType.isUnion() && + tsType.types + .map((value) => fullTypeChecker.typeToString(value)) + .every((t) => !isWindowOrAny(t)) + ) { return; } } From 3125194866ee5656c14e4620d4b39f1938aa5b9f Mon Sep 17 00:00:00 2001 From: Christian Gonzalez <1581488+christiango@users.noreply.github.com> Date: Mon, 27 Oct 2025 22:12:02 +0000 Subject: [PATCH 2/4] Also add a check for element --- lib/rules/no-inner-html.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/no-inner-html.js b/lib/rules/no-inner-html.js index 24b30f1..4a4330e 100644 --- a/lib/rules/no-inner-html.js +++ b/lib/rules/no-inner-html.js @@ -30,7 +30,7 @@ module.exports = { function mightBeHTMLElement(node) { const type = astUtils.getNodeTypeAsString(fullTypeChecker, node, context); - return type.match(/HTML.*Element/) || type === "any"; + return type.match(/HTML.*Element/) || type === "any" || type == "Element"; } return { From 24f7d0b942a96b68b97f2f9fd33cc588040ff115 Mon Sep 17 00:00:00 2001 From: Christian Gonzalez <1581488+christiango@users.noreply.github.com> Date: Mon, 27 Oct 2025 22:27:49 +0000 Subject: [PATCH 3/4] Fix it properly --- lib/rules/no-postmessage-star-origin.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/rules/no-postmessage-star-origin.js b/lib/rules/no-postmessage-star-origin.js index 83d3067..144c895 100644 --- a/lib/rules/no-postmessage-star-origin.js +++ b/lib/rules/no-postmessage-star-origin.js @@ -45,19 +45,15 @@ module.exports = { ); const tsType = fullTypeChecker.getTypeAtLocation(tsNode); const type = fullTypeChecker.typeToString(tsType); - if (!isWindowOrAny(type)) { + // Remove some false positives by returning if the type does not contain Union + if (tsType.isUnionOrIntersection()) { + if (tsType.types.every(t=> !isWindowOrAny(fullTypeChecker.typeToString(t)))) { + return; + } + } else if(!isWindowOrAny(type)){ return; } - if ( - tsType.isUnion() && - tsType.types - .map((value) => fullTypeChecker.typeToString(value)) - .every((t) => !isWindowOrAny(t)) - ) { - return; - } - } context.report({ node: node, From a45c29dc6e5e03a807231ded39e1328169e05e7c Mon Sep 17 00:00:00 2001 From: Christian Gonzalez <1581488+christiango@users.noreply.github.com> Date: Mon, 27 Oct 2025 22:32:13 +0000 Subject: [PATCH 4/4] Formatting fix --- lib/rules/no-postmessage-star-origin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rules/no-postmessage-star-origin.js b/lib/rules/no-postmessage-star-origin.js index 144c895..680e5ae 100644 --- a/lib/rules/no-postmessage-star-origin.js +++ b/lib/rules/no-postmessage-star-origin.js @@ -45,15 +45,15 @@ module.exports = { ); const tsType = fullTypeChecker.getTypeAtLocation(tsNode); const type = fullTypeChecker.typeToString(tsType); - // Remove some false positives by returning if the type does not contain Union + // Remove some false positives by returning if the type does not contain Window or any if (tsType.isUnionOrIntersection()) { - if (tsType.types.every(t=> !isWindowOrAny(fullTypeChecker.typeToString(t)))) { + if (tsType.types.every((t) => !isWindowOrAny(fullTypeChecker.typeToString(t)))) { return; } - } else if(!isWindowOrAny(type)){ + } else if (!isWindowOrAny(type)) { return; } - + } context.report({ node: node,