Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use oxc_span::{GetSpan, Span};
use crate::{AstNode, context::LintContext, rule::Rule};

fn require_post_message_target_origin_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Missing the `targetOrigin` argument.").with_label(span)
OxcDiagnostic::warn("Missing the `targetOrigin` argument.")
.with_label(span)
.with_note("https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage")
}

#[derive(Debug, Default, Clone)]
Expand All @@ -18,11 +20,18 @@ pub struct RequirePostMessageTargetOrigin;
declare_oxc_lint!(
/// ### What it does
///
/// Enforce using the targetOrigin argument with window.postMessage()
/// Enforce using the `targetOrigin` argument with `window.postMessage()`.
///
/// Note that this rule may have false positives, as it is not capable of
/// detecting all cases correctly without type information. As such, it
/// may not be a good idea to enable in cases where `postMessage()` may
/// be used with `BroadcastChannel` or worker/service worker contexts
/// (for example, `WorkerGlobalScope#postMessage`, where the second argument
/// is a transfer list or options object, not `targetOrigin`).
///
/// ### Why is this bad?
///
/// When calling window.postMessage() without the targetOrigin argument,
/// When calling `window.postMessage()` without the `targetOrigin` argument,
/// the message cannot be received by any window.
///
/// ### Examples
Expand Down Expand Up @@ -129,7 +138,6 @@ fn test() {
r#"window["postMessage"](message)"#,
"window.notPostMessage(message)",
"window.postMessage?.(message)",
"window?.postMessage(message)",
"window?.[postMessage](message)",
r"window?.['postMessage'](message)",
"window.c?.postMessage(message)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,108 +8,124 @@ source: crates/oxc_linter/src/tester.rs
· ▲
╰────
help: Insert `, window.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:25]
1 │ self.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:31]
1 │ globalThis.postMessage(message)
· ▲
╰────
help: Insert `, globalThis.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:24]
1 │ foo.postMessage(message )
· ▲
╰────
help: Insert `, foo.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:29]
1 │ foo.postMessage( ((message)) )
· ▲
╰────
help: Insert `, foo.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:24]
1 │ foo.postMessage(message,)
· ▲
╰────
help: Insert `, foo.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:24]
1 │ foo.postMessage(message , )
· ▲
╰────
help: Insert `, foo.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:31]
1 │ foo.window.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:41]
1 │ document.defaultView.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:32]
1 │ getWindow().postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:27]
1 │ window.postMessage(message, /** comments */ )
· ▲
╰────
help: Insert `, window.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:29]
1 │ window.c.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:30]
1 │ window?.c.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:32]
1 │ window?.a.b.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:32]
1 │ window.a?.b.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

⚠ eslint-plugin-unicorn(require-post-message-target-origin): Missing the `targetOrigin` argument.
╭─[require_post_message_target_origin.tsx:1:33]
1 │ window?.a?.b.postMessage(message)
· ▲
╰────
help: Insert `, self.location.origin`
note: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
Loading