Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [no-base-to-string] add checkUnknown Option#11128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Changes fromall commits
efb5f30
d601fd3
3bdc647
224b370
3ca5d85
80fd6d8
4fcfd24
a098114
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -21,6 +21,7 @@ enum Usefulness { | ||
exporttypeOptions=[ | ||
{ | ||
ignoredTypeNames?:string[]; | ||
checkUnknown?:boolean; | ||
}, | ||
]; | ||
exporttypeMessageIds='baseArrayJoin'|'baseToString'; | ||
@@ -46,6 +47,10 @@ export default createRule<Options, MessageIds>({ | ||
type:'object', | ||
additionalProperties:false, | ||
properties:{ | ||
checkUnknown:{ | ||
type:'boolean', | ||
description:'Whether to also check values of type `unknown`', | ||
}, | ||
ignoredTypeNames:{ | ||
type:'array', | ||
description: | ||
@@ -60,6 +65,7 @@ export default createRule<Options, MessageIds>({ | ||
}, | ||
defaultOptions:[ | ||
{ | ||
checkUnknown:false, | ||
ignoredTypeNames:['Error','RegExp','URL','URLSearchParams'], | ||
}, | ||
], | ||
@@ -76,6 +82,7 @@ export default createRule<Options, MessageIds>({ | ||
type??services.getTypeAtLocation(node), | ||
newSet(), | ||
); | ||
if(certainty===Usefulness.Always){ | ||
return; | ||
} | ||
@@ -213,7 +220,7 @@ export default createRule<Options, MessageIds>({ | ||
returncollectToStringCertainty(constraint,visited); | ||
} | ||
// unconstrained generic means `unknown` | ||
returnoption.checkUnknown ?Usefulness.Sometimes :Usefulness.Always; | ||
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
// the Boolean type definition missing toString() | ||
@@ -251,8 +258,13 @@ export default createRule<Options, MessageIds>({ | ||
consttoString= | ||
checker.getPropertyOfType(type,'toString')?? | ||
checker.getPropertyOfType(type,'toLocaleString'); | ||
if(!toString){ | ||
// unknown | ||
if(option.checkUnknown&&type.flags===ts.TypeFlags.Unknown){ | ||
JoshuaKGoldberg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
returnUsefulness.Sometimes; | ||
} | ||
// e.g. any | ||
returnUsefulness.Always; | ||
} | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.