Skip to content

fix: run flutter/prepare before the SonarCloud scan so Dart imports resolve - #1187

Open
anhappdev wants to merge 3 commits into
masterfrom
fix/sonar-dart-resolve-deps
Open

anhappdev wants to merge 3 commits into
masterfrom
fix/sonar-dart-resolve-deps

Conversation

@anhappdev

@anhappdev anhappdev commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

SonarCloud reports thousands of false-positive Dart issues (dart:S2260), e.g. The function 'expect' isn't defined, Undefined name 'BackendInfo', Target of URI doesn't exist: 'package:collection/collection.dart'. On master there are 4,444 open ones (3,656 in flutter/lib, 502 in unit_test, 206 in integration_test, 80 in test). PRs only show the ones in files they touch, e.g. #1180 shows 51, all in benchmark_store_test.dart.

Cause

scanner/build-app only runs make flutter/android (native libs via bazel). It never runs flutter/prepare, so there is no .dart_tool/package_config.json and no generated sources (lib/protos, *.g.dart, l10n, *.gen.dart). The Dart analyzer cannot resolve any import.

SonarQube Cloud documents this prerequisite: run flutter pub get and do a full build before the analysis, otherwise results are "incomplete and potentially incorrect" (Dart docs).

Change

New scanner/prepare-dart target (make flutter/prepare), run before sonar-scanner. It runs outside the C++ build-wrapper, so the captured compile commands are unchanged. flutter/prepare already runs in CI without secrets (Firebase config falls back to dummy values) and in the same Android base image.

Verification

Local check on flutter/unit_test/benchmark/benchmark_store_test.dart:

dart analyze
before make flutter/prepare 135 issues (same errors as Sonar)
after make flutter/prepare No issues found

make -n scanner/scan shows the order: build-wrapper build, make flutter/prepare, sonar-scanner.

Live check on this PR

Three new unit test files (31 tests, all pass locally, import_sorter, dart format and dart analyze --fatal-infos clean) so the Sonar Dart analysis has new files to resolve on this PR:

  • unit_test/resources/utils_test.dart: URI helpers, filterInternetResources, jsonToStringIndented, lerpRange
  • unit_test/benchmark/performance_result_validity_test.dart: valid / semivalid / invalid matrix, stable diffusion ignoring early stopping, colors
  • unit_test/board_decoder_test.dart: loads the bundled database.json asset

Expected result: the SonarCloud report for this PR shows no dart:S2260 ("isn't defined" / "Undefined name") on these files. Before the fix, the same kind of file (benchmark_store_test.dart in #1180) got 51 of them. If they still appear, the scan still can't resolve imports.

Not verified / to watch

  • The Docker scanner image was not run locally; the SonarScanner job on this PR is the real test.
  • Once Dart resolves, the first master analysis may surface real Dart issues that were hidden by the noise. Existing 4,444 false positives should close on the next master scan.

The scanner only ran 'make flutter/android' (native libs), so pub get and code generation never happened. The Dart analyzer could not resolve any package import or generated file and reported thousands of false-positive dart:S2260 issues (e.g. "The function 'expect' isn't defined").
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

…and board decoder

Also gives the Sonar Dart analysis new test files to resolve, to confirm on this PR that imports from flutter_test and mlperfbench no longer report dart:S2260.
@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@anhappdev anhappdev changed the title fix: run flutter/prepare before the Sonar scan so Dart imports resolve fix: run flutter/prepare before the SonarCloud scan so Dart imports resolve Oct 7, 2026
@anhappdev
anhappdev marked this pull request as ready for review October 11, 2026 08:25
@anhappdev
anhappdev requested a review from a team as a code owner October 11, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant