Skip to content

Commit d4733a3

Browse files
Reduce _DoubleClampVisitor false positives (#128539)
I'm getting a few false positives in https://github.com/flutter/flutter/pull/128522/checks from the `num.clamp` checker since I introduced a class with a `clamp` method.
1 parent 0b8fe01 commit d4733a3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

dev/bots/analyze.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,15 @@ class _DoubleClampVisitor extends RecursiveAstVisitor<CompilationUnit> {
239239

240240
@override
241241
CompilationUnit? visitMethodInvocation(MethodInvocation node) {
242-
if (node.methodName.name == 'clamp') {
242+
final NodeList<Expression> arguments = node.argumentList.arguments;
243+
// This may produce false positives when `node.target` is not a subtype of
244+
// num. The static type of `node.target` isn't guaranteed to be resolved at
245+
// this time. Check whether the argument list consists of 2 positional args
246+
// to reduce false positives.
247+
final bool isNumClampInvocation = node.methodName.name == 'clamp'
248+
&& arguments.length == 2
249+
&& !arguments.any((Expression exp) => exp is NamedExpression);
250+
if (isNumClampInvocation) {
243251
final _Line line = _getLine(parseResult, node.function.offset);
244252
if (!line.content.contains('// ignore_clamp_double_lint')) {
245253
clamps.add(line);

0 commit comments

Comments
 (0)