1
1
'use strict' ;
2
2
const {
3
3
not,
4
- matches,
5
4
methodCallSelector,
6
5
callExpressionSelector,
7
6
} = require ( './selectors/index.js' ) ;
@@ -15,43 +14,23 @@ const messages = {
15
14
[ SUGGESTION_REMOVE_MESSAGE_ID ] : 'Remove `null`.' ,
16
15
} ;
17
16
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
-
36
17
const selector = [
37
18
'Literal' ,
38
19
'[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
+ ] ) ,
40
30
] . join ( '' ) ;
41
31
42
32
const isLooseEqual = node => node . type === 'BinaryExpression' && [ '==' , '!=' ] . includes ( node . operator ) ;
43
33
const 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' ;
55
34
56
35
const create = context => {
57
36
const { checkStrictEquality} = {
@@ -66,10 +45,6 @@ const create = context => {
66
45
return ;
67
46
}
68
47
69
- if ( isSecondArgumentOfInsertBefore ( node ) ) {
70
- return ;
71
- }
72
-
73
48
const problem = {
74
49
node,
75
50
messageId : ERROR_MESSAGE_ID ,
0 commit comments