@@ -5,6 +5,28 @@ const getDocsUrl = require('./lib/get-docs-url')
55
66const PROMISE_INSTANCE_METHODS = new Set ( [ 'then' , 'catch' , 'finally' ] )
77
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+
830module . exports = {
931 meta : {
1032 type : 'problem' ,
@@ -37,15 +59,16 @@ module.exports = {
3759 MemberExpression ( node ) {
3860 if (
3961 node . object . type === 'Identifier' &&
40- ( ! node . computed || node . property . type === 'Literal' ) &&
4162 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+ ) ) )
4972 ) {
5073 context . report ( {
5174 node,
0 commit comments