Skip to content

MadBrains/mad_lint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MAD Lint 2.0

A comprehensive Dart/Flutter lint plugin that enforces best practices and catches common issues in your codebase.

Features

Code Quality Rules

  • New Line Before Return: Ensures a blank line before return statements for better readability.
  • No Magic Numbers: Catches usage of magic numbers in code.
  • No Bang Operator: Prevents the use of the null assertion operator (!).
  • Use Wildcard for Unused Parameters: Enforces using underscore (_) for unused parameters in function declarations.

State Management Rules

  • Full Copy-With for State: Ensures all state classes have a complete copyWith method implementation.

    • Detects missing copyWith methods in state classes.
    • Verifies all properties are included in copyWith methods.
  • Mapped Fields Validation: Validates mappedFields getters in state classes.

    • Ensures mappedFields getter exists where required.
    • Validates that mappedFields returns a Map.
    • Ensures all fields are included in the mapping.
    • Validates key-value pairs in the mapping.

Object Comparison & Equality

  • Required Full Props: Ensures all properties are included in the props getter when using Equatable. This helps prevent bugs where properties might be accidentally omitted from the equality comparison.
    • Example:
      // Good:
      class User extends Equatable {
        final String name;
        final int age;
        
        @override
        List<Object?> get props => [name, age]; // All fields included
      }
      
      // Will trigger the rule:
      class User extends Equatable {
        final String name;
        final int age;
        
        @override
        List<Object?> get props => [name]; // 'age' is missing
      }

Resource Management

  • Stream Subscription Disposal: Ensures proper disposal of StreamSubscription objects.
  • Ensure Dispose Called: Verifies that dispose methods are called on objects that require cleanup.

Installation

Add the following to your analysis_options.yaml:

plugins:
  mad_lint:
    version: ^2.0.0

Configuration

You can enable/disable specific rules:

plugins:
  mad_lint:
    version: ^2.0.0
    diagnostics:
      stream_subscription_must_be_disposed: true
      newline_before_return: true
      required_full_props: true
      ensure_dispose_called: true
      no_magic_number: true
      no_bang_operator: true
      missing_copy_with_for_states: true
      incomplete_copy_with_for_states: true
      missing_mapped_fields_getter: true
      mapped_fields_must_be_expression: true
      mapped_fields_must_return_map: true
      mapped_fields_not_all_fields: true
      mapped_fields_key_value_mismatch: true
      use_wildcard_for_unused_parameters: true

Migration from custom_lint to analysis_server_plugin

This guide describes how to migrate from custom_lint (and mad_lint) to the official Dart analyzer plugin system based on analysis_server_plugin.

The goal is to:

  • Completely remove dev_dep_common
  • Remove all mentions of mad_lint
  • Stop using custom_lint
  • Configure analyzer plugins according to the official documentation

1. Remove dev_dep_common and mad_lint

1.1 Delete the package

  • Delete the package directory (e.g. packages/dev_dep_common/)
  • Remove it from any workspace/monorepo tooling configuration (melos, scripts, etc.)

1.2 Remove all references

Search the entire repository and remove all references to:

  • dev_dep_common
  • mad_lint

Places to check:

  • pubspec.yaml (dependencies, dev_dependencies, dependency_overrides)
  • analysis_options.yaml
  • CI scripts
  • README and internal documentation

2. Remove custom_lint

In all packages where it was used:

2.1 Remove dependencies

Delete the following from pubspec.yaml:

  • custom_lint
  • custom_lint_builder
  • Any *_lint packages that were implemented specifically for custom_lint

3. Configure analyzer plugins via analysis_options.yaml

Analyzer plugins are now configured directly in analysis_options.yaml.

If the plugin is published on pub.dev:

# analysis_options.yaml
plugins:
  mad_lint: ^2.0.0

About

A comprehensive Dart/Flutter lint plugin with rules for state management, resource disposal, and code quality

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages