@@ -5,6 +5,28 @@ const getDocsUrl = require('./lib/get-docs-url')
5
5
6
6
const PROMISE_INSTANCE_METHODS = new Set ( [ 'then' , 'catch' , 'finally' ] )
7
7
8
+ function isPermittedProperty ( expression , standardSet , allowedMethods ) {
9
+ // istanbul ignore if
10
+ if ( expression . type !== 'MemberExpression' ) return false
11
+
12
+ if ( expression . property . type === 'Literal' )
13
+ return (
14
+ standardSet . has ( expression . property . value ) ||
15
+ allowedMethods . includes ( expression . property . value )
16
+ )
17
+
18
+ // istanbul ignore else
19
+ if ( expression . property . type === 'Identifier' )
20
+ return (
21
+ expression . computed ||
22
+ standardSet . has ( expression . property . name ) ||
23
+ allowedMethods . includes ( expression . property . name )
24
+ )
25
+
26
+ // istanbul ignore next
27
+ return false
28
+ }
29
+
8
30
module . exports = {
9
31
meta : {
10
32
type : 'problem' ,
@@ -37,15 +59,16 @@ module.exports = {
37
59
MemberExpression ( node ) {
38
60
if (
39
61
node . object . type === 'Identifier' &&
40
- ( ! node . computed || node . property . type === 'Literal' ) &&
41
62
node . object . name === 'Promise' &&
42
- ( ( node . property . name && ! PROMISE_STATICS . has ( node . property . name ) ) ||
43
- ( node . property . value &&
44
- ! PROMISE_STATICS . has ( node . property . value ) ) ) &&
45
- ( node . property . name !== 'prototype' ||
46
- ( ! PROMISE_INSTANCE_METHODS . has ( node ?. parent ?. property ?. name ) &&
47
- ! allowedMethods . includes ( node ?. parent ?. property ?. name ) ) ) &&
48
- ! allowedMethods . includes ( node . property . name ?? node . property . value )
63
+ ( ( node . property . name !== 'prototype' &&
64
+ ! isPermittedProperty ( node , PROMISE_STATICS , allowedMethods ) ) ||
65
+ ( node . property . name === 'prototype' &&
66
+ node . parent . type === 'MemberExpression' &&
67
+ ! isPermittedProperty (
68
+ node . parent ,
69
+ PROMISE_INSTANCE_METHODS ,
70
+ allowedMethods ,
71
+ ) ) )
49
72
) {
50
73
context . report ( {
51
74
node,
0 commit comments