11import { TSESTree as es } from '@typescript-eslint/utils' ;
2- import { getTypeServices , isIdentifier , isImport , isObjectExpression , isProperty } from '../etc' ;
2+ import { getTypeServices , isIdentifier , isImport , isMemberExpression , isObjectExpression , isProperty } from '../etc' ;
33import { ruleCreator } from '../utils' ;
44
55export const noIgnoredDefaultValueRule = ruleCreator ( {
@@ -10,16 +10,16 @@ export const noIgnoredDefaultValueRule = ruleCreator({
1010 requiresTypeChecking : true ,
1111 } ,
1212 messages : {
13- forbidden : 'Ignoring the default value is forbidden.' ,
13+ forbidden : 'Not specifying a default value is forbidden.' ,
1414 } ,
1515 schema : [ ] ,
1616 type : 'problem' ,
1717 } ,
1818 name : 'no-ignored-default-value' ,
1919 create : ( context ) => {
20- const { couldBeObservable } = getTypeServices ( context ) ;
20+ const { couldBeObservable, getType } = getTypeServices ( context ) ;
2121
22- function checkConfig ( configArg : es . ObjectExpression ) {
22+ function checkConfigObj ( configArg : es . ObjectExpression ) {
2323 if ( ! configArg . properties . some ( p => isProperty ( p ) && isIdentifier ( p . key ) && p . key . name === 'defaultValue' ) ) {
2424 context . report ( {
2525 messageId : 'forbidden' ,
@@ -28,6 +28,16 @@ export const noIgnoredDefaultValueRule = ruleCreator({
2828 }
2929 }
3030
31+ function checkConfigType ( configArg : es . Node ) {
32+ const configArgType = getType ( configArg ) ;
33+ if ( ! configArgType ?. getProperties ( ) . some ( p => p . name === 'defaultValue' ) ) {
34+ context . report ( {
35+ messageId : 'forbidden' ,
36+ node : configArg ,
37+ } ) ;
38+ }
39+ }
40+
3141 function checkFunctionArgs ( callExpression : es . CallExpression , reportNode : es . Node ) {
3242 const scope = context . sourceCode . getScope ( callExpression ) ;
3343 if ( ! isImport ( scope , 'firstValueFrom' , / ^ r x j s \/ ? / )
@@ -49,10 +59,17 @@ export const noIgnoredDefaultValueRule = ruleCreator({
4959 } ) ;
5060 return ;
5161 }
62+ if ( isIdentifier ( configArg ) ) {
63+ checkConfigType ( configArg ) ;
64+ return ;
65+ } else if ( isMemberExpression ( configArg ) && isIdentifier ( configArg . property ) ) {
66+ checkConfigType ( configArg . property ) ;
67+ return ;
68+ }
5269 if ( ! isObjectExpression ( configArg ) ) {
5370 return ;
5471 }
55- checkConfig ( configArg ) ;
72+ checkConfigObj ( configArg ) ;
5673 }
5774
5875 function checkOperatorArgs ( callExpression : es . CallExpression , reportNode : es . Node ) {
@@ -71,10 +88,17 @@ export const noIgnoredDefaultValueRule = ruleCreator({
7188 return ;
7289 }
7390 const [ arg ] = args ;
91+ if ( isIdentifier ( arg ) ) {
92+ checkConfigType ( arg ) ;
93+ return ;
94+ } else if ( isMemberExpression ( arg ) && isIdentifier ( arg . property ) ) {
95+ checkConfigType ( arg . property ) ;
96+ return ;
97+ }
7498 if ( ! isObjectExpression ( arg ) ) {
7599 return ;
76100 }
77- checkConfig ( arg ) ;
101+ checkConfigObj ( arg ) ;
78102 }
79103
80104 return {
0 commit comments