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
base:main
Are you sure you want to change the base?
Changes fromall commits
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 { | ||||||
export type Options = [ | ||||||
{ | ||||||
ignoredTypeNames?: string[]; | ||||||
checkUnknown?: boolean; | ||||||
}, | ||||||
]; | ||||||
export type MessageIds = 'baseArrayJoin' | 'baseToString'; | ||||||
@@ -46,6 +47,12 @@ export default createRule<Options, MessageIds>({ | ||||||
type: 'object', | ||||||
additionalProperties: false, | ||||||
properties: { | ||||||
checkUnknown: { | ||||||
type: 'boolean', | ||||||
default: false, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. [Cleanup] This actually doesn't do anything in our stack (long story...) Suggested change
| ||||||
description: | ||||||
'Checks the case where toString is applied to unknown type', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. [Docs] A little bit of phrasing alignment: Suggested change
| ||||||
}, | ||||||
ignoredTypeNames: { | ||||||
type: 'array', | ||||||
description: | ||||||
@@ -60,6 +67,7 @@ export default createRule<Options, MessageIds>({ | ||||||
}, | ||||||
defaultOptions: [ | ||||||
{ | ||||||
checkUnknown: false, | ||||||
ignoredTypeNames: ['Error', 'RegExp', 'URL', 'URLSearchParams'], | ||||||
}, | ||||||
], | ||||||
@@ -76,6 +84,7 @@ export default createRule<Options, MessageIds>({ | ||||||
type ?? services.getTypeAtLocation(node), | ||||||
new Set(), | ||||||
); | ||||||
if (certainty === Usefulness.Always) { | ||||||
return; | ||||||
} | ||||||
@@ -213,7 +222,7 @@ export default createRule<Options, MessageIds>({ | ||||||
return collectToStringCertainty(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 +260,13 @@ export default createRule<Options, MessageIds>({ | ||||||
const toString = | ||||||
checker.getPropertyOfType(type, 'toString') ?? | ||||||
checker.getPropertyOfType(type, 'toLocaleString'); | ||||||
if (!toString) { | ||||||
// unknown | ||||||
if (option.checkUnknown && type.flags === ts.TypeFlags.Unknown) { | ||||||
return Usefulness.Sometimes; | ||||||
} | ||||||
// e.g. any | ||||||
return Usefulness.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.
Uh oh!
There was an error while loading.Please reload this page.