Skip to content

♻️ Ignore generated file diagnostics by type instead of by name - #48

Merged
AlexV525 merged 5 commits into
masterfrom
chore/ignore-for-file-by-type
Sep 12, 2026
Merged

AlexV525 merged 5 commits into
masterfrom
chore/ignore-for-file-by-type

Conversation

@AlexV525

Copy link
Copy Markdown
Member

What

Generated route files are silenced by diagnostic type instead of by a list of twelve diagnostic names:

// coverage:ignore-file
// ignore_for_file: type=hint,type=lint,type=warning

Why

Most of the twelve names in the old list moved out of the lint set into the analyzer itself, so the list has to be kept in sync with every such move — and type=lint alone is not enough:

old list entry type now
unnecessary_import INFO HINT
duplicate_import, multiple_combinators, unused_import, unused_local_variable, unused_shown_name WARNING STATIC_WARNING
library_private_types_in_public_api, unintended_html_in_doc_comment, unnecessary_library_directive, unnecessary_library_name INFO LINT
implementation_imports, prefer_const_literals_to_create_immutables still lints (LINT)

hint, lint and warning are the only types an ignore comment can match (analyzer/lib/src/ignore_comments/ignore_info.dart); error diagnostics cannot be ignored this way, which is also true of the old name list.

Verification

  • Per-code equivalence: one trigger file per code × three variants (no ignore / old name list / new triple) → every code that reports without an ignore is suppressed by both forms; the type observed in dart analyze --format machine matches the table above for the ten codes that can be triggered in this SDK.
  • dart analyze --format machine lib for all nine example packages: byte-identical diagnostics before and after.
  • dart format lib -o none --set-exit-if-changed, flutter analyze ., dart test, dart pub publish --dry-run as run by CI.

Example regeneration

All eight example directories were regenerated by running the generator with no arguments, so each reuses its own ff_annotation_route_commands:

  • example_go_router output was stale: the ignore line was written after the license header, // dart format off and // coverage:ignore-file were missing, import 'dart:ui'; was still emitted, and the route settings fields and indentation differed.
  • The module packages are run before example / example_fast_mode, because those also write the module's *_route.dart as a node of their package graph; running the modules last would flip the header's fast mode flag.
  • module_a/lib/module_a_routes.dart and module_a_fast_routes.dart are deliberately not committed: nothing consumes them, they were dropped in 5fc5c69, and the first does not compile (it references TestMode while the import is prefixed as module_a).

Release

pubspec.yaml → 12.1.0 with a matching CHANGELOG.md entry.

The generated header now writes
`// ignore_for_file: type=hint,type=lint,type=warning` instead of listing
twelve diagnostic names that have to be kept in sync with the analyzer.

Most of the listed names have moved out of the lint set into the analyzer
itself, so `type=lint` alone would not have been enough: `unnecessary_import`
is now a hint, and `duplicate_import`, `multiple_combinators`,
`unused_import`, `unused_local_variable` and `unused_shown_name` are static
warnings. `hint`, `lint` and `warning` are the only types an ignore comment
can match; error diagnostics can not be ignored either way.

Regenerated the examples. The committed `example_go_router` output is stale
for unrelated reasons, so only its ignore line was updated.
Ran the generator in all eight example directories with no arguments, so each
one reuses its own `ff_annotation_route_commands` (bin/ff_annotation_route.dart
only reads that file when no arguments are passed):

  example, example/module_a, example1, example_fast_mode,
  example_fast_mode/module_a, example_getx, example_route_extension,
  example_go_router

`example_go_router` was the only stale output: its ignore line was written
after the license header, `// dart format off` and `// coverage:ignore-file`
were missing, `import 'dart:ui';` was still emitted, and the route settings
fields and indentation differed.

The module packages are run before `example` / `example_fast_mode`, because
those two also write the module's `*_route.dart` as a node of their package
graph using their own arguments; running the modules last flips the header's
`fast mode` flag to true and leaves a diff behind for anyone who only runs the
`.run` configurations.

Two byproducts of the module packages are deliberately not committed:
`module_a/lib/module_a_routes.dart` and `module_a_fast_routes.dart`. Nothing
consumes them, they were dropped in 5fc5c69, and the first one does not compile
(it references `TestMode` at module_a_routes.dart:84 while the import is
prefixed `as module_a`).
@AlexV525
AlexV525 requested a review from zmtzawqlp as a code owner September 12, 2026 18:21
go_router 17.5.0 turned `metadata` into a required named parameter of
`RouteMatchBase.buildState`, which the go_router example calls:

  error • The named parameter 'metadata' is required, but there's no
  corresponding argument • example_go_router/lib/src/router/
  go_router_route_lifecycle.dart:521:16 • missing_required_argument

The same call exists on master; it only started failing when the newest
go_router became 17.5.0+. The merged metadata accessor
(`RouteMatchList.metadataFor`) is annotated `internal`, so the metadata of
the matched route itself is passed instead.
`melos bootstrap` (via the `ide.intellij` section in melos.yaml) writes
platform-aware `analyzer.exclude` entries into every example's
analysis_options.yaml (`build/**`, plus `web/**` or `android/**`/`ios/**`
depending on the platform folders the package has). Because those nine
checked-in files were left dirty, the CI step `dart pub publish --dry-run`
failed with "9 checked-in files are modified in git".
@AlexV525
AlexV525 merged commit fb5e59f into master Sep 12, 2026
1 check passed
@AlexV525
AlexV525 deleted the chore/ignore-for-file-by-type branch September 12, 2026 18:30
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