eslint-plugin-unicorn: `require-post-message-target-origin` shouldn't trigger for incompatible APIs
What’s wrong
I’m currently developing a browser extension that communicates with native software:
import { browser, Runtime } from 'webextension-polyfill-ts'
const nativePort: Runtime.Port = browser.runtime.connectNative(APPLICATION_ID)
nativePort.postMessage({ cmd: 'Version' }) // (x) Missing the `targetOrigin` argument.
Which rule is buggy
require-post-message-target-origin
is triggered but the method only accepts one argument (see runtime.Port).
Ideas
- Enforce the name of the variable to be
window
,document
or the likes. - Check the type of the variable or the existence of the import
'webextension-polyfill'
/'webextension-polyfill-ts'
. - Add a warning for web extension developers here: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v34.0.1/docs/rules/require-post-message-target-origin.md
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 20 (2 by maintainers)
So
require-post-message-target-origin
should be disabled by default for.ts
files in the recommended config.I think we should turn this rule off…
Indeed it is! So this rule can be dropped altogether as far as I’m concerned.
That will be meaningless if this https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1396#issuecomment-872931334 is true.
Ok got it, the problem is more that browsers fail silently instead of throwing an exception. What if this rule only triggers for
window.postMessage
by default inunicorn/recommended
, and add an option to trigger on any variable likefoo.postMessage
?Do you think disable this rule in your file or project is a good idea? If you are developing a browser extension, you probably don’t need call window.postMessage.