Unverified Commit d4733a3f authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

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.
parent 0b8fe017
......@@ -239,7 +239,15 @@ class _DoubleClampVisitor extends RecursiveAstVisitor<CompilationUnit> {
@override
CompilationUnit? visitMethodInvocation(MethodInvocation node) {
if (node.methodName.name == 'clamp') {
final NodeList<Expression> arguments = node.argumentList.arguments;
// This may produce false positives when `node.target` is not a subtype of
// num. The static type of `node.target` isn't guaranteed to be resolved at
// this time. Check whether the argument list consists of 2 positional args
// to reduce false positives.
final bool isNumClampInvocation = node.methodName.name == 'clamp'
&& arguments.length == 2
&& !arguments.any((Expression exp) => exp is NamedExpression);
if (isNumClampInvocation) {
final _Line line = _getLine(parseResult, node.function.offset);
if (!line.content.contains('// ignore_clamp_double_lint')) {
clamps.add(line);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment