Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insertBefore 2nd param should be allowed to be null #1156

Closed
kkmuffme opened this issue Apr 5, 2021 · 2 comments · Fixed by #1157
Closed

insertBefore 2nd param should be allowed to be null #1156

kkmuffme opened this issue Apr 5, 2021 · 2 comments · Fixed by #1157

Comments

@kkmuffme
Copy link

kkmuffme commented Apr 5, 2021

https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore allows the 2nd arg to be null
That will however give an error to use undefined instead.

However when we use undefined, then it auto-fixes it and removes the "undefined" arg (unless checkArguments of https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-undefined.md#checkarguments is set)

no-null
no-useless-undefined

hello.insertBefore( button, null );

// this workaround does not work either, as Chrome will report an error:
// parameter 2 is not of type" 'node'
const myNull = Object.create( null );
hello.insertBefore( button, myNull );
@kkmuffme kkmuffme added the bug label Apr 5, 2021
@sindresorhus
Copy link
Owner

I guess we could not report it if the method name is insertBefore and the second argument is null.

@kachkaev
Copy link
Contributor

kachkaev commented Sep 2, 2023

I think I found an edge case which is not fixed yet. I might submit an issue later when there is time, but here is a quick example:

a.insertBefore(ghostNode, a.childNodes[0] ?? null);

Null is in a sub-AST-node of the second arg, which makes the rule triggered:

Use `undefined` instead of `null`. unicorn/no-null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants