Pub Package Build Status MIT License analyzer version 10.0.2

A useful collection of custom lints for Flutter & Dart projects. Uses the new analysis_server_plugin system for direct integration with dart analyze and IDEs.

Features

This package provides a set of custom lints to help you write better Flutter code.

Getting started

Requires Dart 3.10+ (Flutter 3.38+)

Add many_lints to the top-level plugins section in your analysis_options.yaml file (NOT under analyzer:):

plugins:
  many_lints: ^0.1.2

That's it — the analysis server will automatically download and resolve the plugin from pub.dev. There is no need to add it to your pubspec.yaml.

Local development

For local development or when using many_lints from a cloned repository, use the path option:

git clone https://github.com/Nikoro/many_lints.git /path/to/many_lints
plugins:
  many_lints:
    path: /path/to/many_lints

Note: Git dependencies are not directly supported by the plugin system. Clone the repository locally and use the path option instead.

Important: After any change to the plugins section, you must restart the Dart Analysis Server.

Configuring diagnostics

All rules are registered as warnings and enabled by default. You can enable or disable individual rules under the diagnostics key:

plugins:
  many_lints:
    diagnostics:
      prefer_center_over_align: true
      use_bloc_suffix: false

Available Lints

All lints are enabled by default as warnings.

  • avoid_single_child_in_multi_child_widgets: Avoid using a single child in widgets that can accept multiple children (e.g., Row, Column, Flex).
  • avoid_unnecessary_consumer_widgets: Ensures that a ConsumerWidget uses the ref parameter.
  • avoid_unnecessary_hook_widgets: Ensures that a HookWidget uses hooks.
  • prefer_align_over_container: Enforces the use of Align over Container with only the alignment parameter.
  • prefer_any_or_every: Prefer .any() or .every() over .where().isEmpty/.isNotEmpty.
  • prefer_center_over_align: Prefer Center over Align with alignment: Alignment.center.
  • prefer_padding_over_container: Enforces the use of Padding over Container with only margin.
  • use_bloc_suffix: Enforces the use of the Bloc suffix for classes that extend Bloc.
  • use_cubit_suffix: Enforces the use of the Cubit suffix for classes that extend Cubit.
  • use_dedicated_media_query_methods: Enforces the use of dedicated MediaQuery methods instead of MediaQuery.of(context).
  • use_gap: Prefer Gap widget instead of SizedBox or Padding for spacing in multi-child widgets.
  • use_notifier_suffix: Enforces the use of the Notifier suffix for classes that extend Notifier.

Quick fixes

The following rules include auto-fixable quick fixes:

  • avoid_unnecessary_consumer_widgets
  • avoid_unnecessary_hook_widgets
  • prefer_align_over_container
  • prefer_any_or_every
  • prefer_center_over_align
  • prefer_padding_over_container
  • use_bloc_suffix
  • use_cubit_suffix
  • use_dedicated_media_query_methods
  • use_gap
  • use_notifier_suffix

Available Assists

  • Convert to collection-for: Converts .map().toList() or .map().toSet() to collection-for syntax.

Suppressing Diagnostics

To suppress a specific lint, use comments:

// ignore: many_lints/prefer_center_over_align
const Align(...);

// ignore_for_file: many_lints/use_bloc_suffix

Example

See the example/ directory for a Flutter project that demonstrates every lint rule in action. Each file corresponds to a single rule and contains code that triggers the lint.

use_cubit_suffix

DO use Cubit suffix for your cubit names.

BAD:

class MyClass extends Cubit<bool> {}

GOOD:

class MyClassCubit extends Cubit<bool> {}

Libraries

main
Re-exports many_lints.dart for analysis_server_plugin discovery.
many_lints
Many Lints - A collection of useful lint rules for Dart and Flutter.