1- import { TSESTree as es } from '@typescript-eslint/utils' ;
2- import { getTypeServices } from '../etc' ;
1+ import { TSESTree as es , ESLintUtils } from '@typescript-eslint/utils' ;
2+ import { getTypeServices , isIdentifier , isMemberExpression , isObjectExpression , isProperty } from '../etc' ;
33import { ruleCreator } from '../utils' ;
44
55export const noIgnoredErrorRule = ruleCreator ( {
@@ -18,18 +18,59 @@ export const noIgnoredErrorRule = ruleCreator({
1818 } ,
1919 name : 'no-ignored-error' ,
2020 create : ( context ) => {
21+ const { getTypeAtLocation } = ESLintUtils . getParserServices ( context ) ;
2122 const { couldBeObservable, couldBeFunction } = getTypeServices ( context ) ;
2223
24+ function isMissingErrorCallback ( callExpression : es . CallExpression ) : boolean {
25+ if ( callExpression . arguments . length >= 2 ) {
26+ return false ;
27+ }
28+ return couldBeFunction ( callExpression . arguments [ 0 ] ) ;
29+ }
30+
31+ function isObjMissingError ( arg : es . ObjectExpression ) : boolean {
32+ return ! arg . properties . some (
33+ property =>
34+ isProperty ( property )
35+ && isIdentifier ( property . key )
36+ && property . key . name === 'error' ,
37+ ) ;
38+ }
39+
40+ function isTypeMissingError ( arg : es . Identifier ) : boolean {
41+ const argType = getTypeAtLocation ( arg ) ;
42+ return ! argType ?. getProperties ( ) . some ( p => p . name === 'error' ) ;
43+ }
44+
45+ function isMissingErrorProperty ( callExpression : es . CallExpression ) : boolean {
46+ if ( callExpression . arguments . length !== 1 ) {
47+ return false ;
48+ }
49+
50+ const [ arg ] = callExpression . arguments ;
51+
52+ if ( isObjectExpression ( arg ) ) {
53+ return isObjMissingError ( arg ) ;
54+ }
55+ if ( isIdentifier ( arg ) ) {
56+ return isTypeMissingError ( arg ) ;
57+ }
58+ if ( isMemberExpression ( arg ) && isIdentifier ( arg . property ) ) {
59+ return isTypeMissingError ( arg . property ) ;
60+ }
61+ return false ;
62+ }
63+
2364 return {
2465 'CallExpression[arguments.length > 0] > MemberExpression > Identifier[name=\'subscribe\']' :
2566 ( node : es . Identifier ) => {
2667 const memberExpression = node . parent as es . MemberExpression ;
2768 const callExpression = memberExpression . parent as es . CallExpression ;
2869
2970 if (
30- callExpression . arguments . length < 2
71+ ( isMissingErrorCallback ( callExpression )
72+ || isMissingErrorProperty ( callExpression ) )
3173 && couldBeObservable ( memberExpression . object )
32- && couldBeFunction ( callExpression . arguments [ 0 ] )
3374 ) {
3475 context . report ( {
3576 messageId : 'forbidden' ,
0 commit comments