Skip to content

Migrate from custom_lint to the New Analyzer Plugin System #85

@naipaka

Description

@naipaka

Currently, lint rules and quick fixes are implemented using custom_lint.
However, custom_lint does not support Pub Workspaces and is unlikely to receive updates to address this limitation.

To ensure compatibility with Pub Workspaces and align with future improvements in the Dart Analyzer ecosystem, we should migrate to the new analyzer plugin system being developed.

Task

  • Refactor the existing lint rules and quick fixes to work with the new analyzer plugin system.

Goal

  • Retain current functionality while ensuring compatibility with Pub Workspaces and future Dart Analyzer features.

Here is the list of Lints and Assists included in the altive_lints package.

Lints

Rule ID Description Migrated
avoid_consecutive_sliver_to_box_adapter Detects consecutive use of SliverToBoxAdapter within CustomScrollView, etc., and encourages the use of SliverList or similar widgets.
avoid_hardcoded_color Warns against using hardcoded colors (e.g., Color(0xFF...) or Colors.red) directly in the code, recommending the use of Theme.of(context).colorScheme or similar.
avoid_hardcoded_japanese Detects hardcoded Japanese strings in the code and encourages the use of internationalization (l10n).
avoid_shrink_wrap_in_list_view Warns against using shrinkWrap: true in ListView. It causes performance degradation, so using Slivers or similar is recommended.
avoid_single_child Warns when widgets intended for multiple children, such as Column, Row, and Stack, have only one child.
prefer_clock_now Warns against using DateTime.now() and recommends using clock.now() (from the clock package) to improve testability.
prefer_dedicated_media_query_methods Recommends using dedicated methods like MediaQuery.sizeOf(context) instead of MediaQuery.of(context).size, etc., to prevent unnecessary rebuilds.
prefer_space_between_elements Enforces inserting a blank line between the constructor and fields, and between the constructor and the build method in class definitions.
prefer_to_include_sliver_in_name Recommends including Sliver in the class name or constructor name of widgets that return a Sliver widget.

Assists

Assist ID Description Migrated
add_macro_document_comments Adds documentation comments for macro templates (/// {@macro ...}) to functions or constructors.
add_macro_template_document_comment Adds documentation comments for macro template definitions (/// {@template ...}) to class declarations.
wrap_with_macro_template_document_comment Wraps existing documentation comments with a macro template (/// {@template ...} ... /// {@endtemplate}).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions