11'use strict' ;
22const {
33 not,
4- matches,
54 methodCallSelector,
65 callExpressionSelector,
76} = require ( './selectors/index.js' ) ;
@@ -15,43 +14,23 @@ const messages = {
1514 [ SUGGESTION_REMOVE_MESSAGE_ID ] : 'Remove `null`.' ,
1615} ;
1716
18- const objectCreateSelector = methodCallSelector ( {
19- object : 'Object' ,
20- method : 'create' ,
21- argumentsLength : 1 ,
22- } ) ;
23-
24- // `useRef(null)`
25- // eslint-disable-next-line unicorn/prevent-abbreviations
26- const useRefSelector = callExpressionSelector ( { name : 'useRef' , argumentsLength : 1 } ) ;
27-
28- // `React.useRef(null)`
29- // eslint-disable-next-line unicorn/prevent-abbreviations
30- const reactUseRefSelector = methodCallSelector ( {
31- object : 'React' ,
32- method : 'useRef' ,
33- argumentsLength : 1 ,
34- } ) ;
35-
3617const selector = [
3718 'Literal' ,
3819 '[raw="null"]' ,
39- not ( `${ matches ( [ objectCreateSelector , useRefSelector , reactUseRefSelector ] ) } > .arguments` ) ,
20+ not ( [
21+ // `Object.create(null)`, `Object.create(null, foo)`
22+ `${ methodCallSelector ( { object : 'Object' , method : 'create' , minimumArguments : 1 , maximumArguments : 2 } ) } > .arguments:first-child` ,
23+ // `useRef(null)`
24+ `${ callExpressionSelector ( { name : 'useRef' , argumentsLength : 1 } ) } > .arguments:first-child` ,
25+ // `React.useRef(null)`
26+ `${ methodCallSelector ( { object : 'React' , method : 'useRef' , argumentsLength : 1 } ) } > .arguments:first-child` ,
27+ // `foo.insertBefore(bar, null)`
28+ `${ methodCallSelector ( { method : 'insertBefore' , argumentsLength : 2 } ) } [arguments.0.type!="SpreadElement"] > .arguments:nth-child(2)` ,
29+ ] ) ,
4030] . join ( '' ) ;
4131
4232const isLooseEqual = node => node . type === 'BinaryExpression' && [ '==' , '!=' ] . includes ( node . operator ) ;
4333const isStrictEqual = node => node . type === 'BinaryExpression' && [ '===' , '!==' ] . includes ( node . operator ) ;
44- const isSecondArgumentOfInsertBefore = node =>
45- node . parent . type === 'CallExpression' &&
46- ! node . parent . optional &&
47- node . parent . arguments . length === 2 &&
48- node . parent . arguments [ 0 ] . type !== 'SpreadElement' &&
49- node . parent . arguments [ 1 ] === node &&
50- node . parent . callee . type === 'MemberExpression' &&
51- ! node . parent . callee . computed &&
52- ! node . parent . callee . optional &&
53- node . parent . callee . property . type === 'Identifier' &&
54- node . parent . callee . property . name === 'insertBefore' ;
5534
5635const create = context => {
5736 const { checkStrictEquality} = {
@@ -66,10 +45,6 @@ const create = context => {
6645 return ;
6746 }
6847
69- if ( isSecondArgumentOfInsertBefore ( node ) ) {
70- return ;
71- }
72-
7348 const problem = {
7449 node,
7550 messageId : ERROR_MESSAGE_ID ,
0 commit comments