eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

no-null: false positive when null is used as function argument

Open kkmuffme opened this issue 2 years ago • 2 comments

eslint unicorn v42.0.0

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-null.md

Fails when null is used as function argument, even though this should pass. In fact this is even an example given in the "Pass" section: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-null.md#pass

This works (no error):

const foo = Object.create(null);

but this fails:

drawingManager.setMap( null );

markers[ index ].setMap( null );

I think this shouldn't fail? I can't choose what argument types a function accepts in many cases (libraries). And if we want to have this error for functions we can control, it's better to give an error for no null arg when function is declared?

kkmuffme avatar Jun 15 '22 08:06 kkmuffme

I guess we can add an option for this.

fisker avatar Jul 14 '22 10:07 fisker

Running into the same issue making MSW mocks with HttpResponse, since the first parameter to HttpResponse's constructor is typed as body?: BodyInit | null and I need to mock a null case.

ardunster avatar Feb 26 '24 21:02 ardunster