Skip to content
Permalink
Browse files

fix(eslint-plugin): [no-unnecessary-condition] false positive when ar…

…ray predicate returns unknown (#2772)
  • Loading branch information
ArnaudBarre committed Nov 17, 2020
1 parent 3e4a0ed commit 111c244c3eb157efeb5c43ff39f12633b27f091e
@@ -450,6 +450,10 @@ export default createRule<Options, MessageId>({
// Not a callable function
return;
}
// Predicate is always necessary if it involves `any` or `unknown`
if (returnTypes.some(t => isTypeAnyType(t) || isTypeUnknownType(t))) {
return;
}
if (!returnTypes.some(isPossiblyFalsy)) {
return context.report({
node: callback,
@@ -235,6 +235,14 @@ function length(x: string) {
function nonEmptyStrings(x: string[]) {
return x.filter(length);
}
// filter-like predicate
function count(
list: string[],
predicate: (value: string, index: number, array: string[]) => unknown,
) {
return list.filter(predicate).length;
}
`,
// Ignores non-array methods of the same name
`

0 comments on commit 111c244

Please sign in to comment.