very_good_analysis

repository·main·Indexed 19 days ago

https://github.com/verygoodopensource/very_good_analysis

A curated set of lint rules for Dart and Flutter projects used by Very Good Ventures to maintain code quality and consistency. The package provides configuration for analysis_options.yaml and includes tools for managing rule exclusions and removing deprecated Dart linter rules.

Tokens
4.1K
Snippets
11
Records
15
Agent score
64%

What's inside very_good_analysis

  1. Automated maintenance via GitHub workflows

    main

    Linter rule maintenance is automated via a GitHub workflow (.github/workflows/bot_updater.yaml) that runs on a weekday schedule or can be triggered manually. It performs two tasks:

    1. Update Exclusion Table: Regenerates the exclusion table in the README if changes are detected and opens a PR titled docs: update exclusion table.
    2. Remove Deprecated Rules: Automatically removes deprecated rules, creates a new version, and opens a PR titled feat: remove deprecated rules.
  2. Install very_good_analysis

    main

    To use these lint rules in your project, add very_good_analysis as a development dependency using either dart or flutter CLI.

    After adding the dependency, you must include the package's configuration in your analysis_options.yaml file to activate the rules.

    # For Dart projects
    dart pub add dev:very_good_analysis
    
    # For Flutter projects
    flutter pub add dev:very_good_analysis
  3. Generate the Exclusion Reason Table

    main

    The Exclusion Reason Table is a markdown table in the README that lists linter rules not enabled by default in Very Good Analysis, along with the reason why. The reasons are sourced from exclusion_reasons.json.

    To regenerate this table for the latest version of Very Good Analysis, run the exclusion_reason_table.dart script from the tool/linter_rules directory. Note that you must run dart pub get before executing the script. The command does not format the output, so you should run your preferred formatter on the README and the JSON file afterward.

    cd tool/linter_rules
    dart pub get
    dart lib/exclusion_reason_table.dart
  4. Check and remove deprecated linter rules

    main

    The remove_deprecated_rules.dart script automates the maintenance of the rule set by handling deprecated Dart linter rules.

    When executed, the script:

    1. Fetches the latest rules from the official Dart SDK.
    2. Identifies deprecated rules used in Very Good Analysis.
    3. Removes those rules from the analysis options file.
    4. Creates a new minor version of Very Good Analysis.
    5. Updates lib/analysis_options.yaml to set the new version as the latest.
    6. Adds the removed rules to the exclusion table with the reason 'Deprecated'.

    Run this script from the tool/linter_rules directory.

    cd tool/linter_rules
    dart bin/remove_deprecated_rules.dart
  5. Analyze the health of Very Good Analysis rule sets

    main

    The analyze.dart script allows you to inspect the health of a specific version of Very Good Analysis. It provides metrics on:

    • The number of Dart linter rules fetched.
    • The number of rules declared in the specified Very Good Analysis version.
    • The number of deprecated Dart rules currently in use within that version.

    Run the script from the tool/linter_rules directory after running dart pub get.

    # Analyze the latest version
    dart bin/analyze.dart
    
    # Analyze a specific version (e.g., 10.0.0)
    dart bin/analyze.dart 10.0.0
  6. Configure analysis_options.yaml

    main

    To activate the lints, add an include statement to your analysis_options.yaml file.

    By default, including package:very_good_analysis/analysis_options.yaml ensures you always use the latest version of the lints. If you need to pin the lint rules to a specific version for stability, you can include a versioned YAML file instead.

    # Use the latest version
    include: package:very_good_analysis/analysis_options.yaml
    
    # OR: Restrict to a specific version
    include: package:very_good_analysis/analysis_options.10.0.0.yaml
  7. Reference excluded lint rules

    main

    The following rules are intentionally excluded from very_good_analysis due to conflicts, experimental status, or other reasons. If you need these rules, you must enable them manually in your analysis_options.yaml.

    | Rule | Reason |
    | --- | --- |
    | [`always_put_control_body_on_new_line`](https://dart.dev/tools/linter-rules/always_put_control_body_on_new_line) | [Can conflict with the Dart formatter](https://dart.dev/tools/linter-rules/always_put_control_body_on_new_line) |
    | [`always_specify_types`](https://dart.dev/tools/linter-rules/always_specify_types) | Incompatible with [omit_local_variable_types](https://dart.dev/tools/linter-rules/omit_local_variable_types) |
    | [`annotate_redeclares`](https://dart.dev/tools/linter-rules/annotate_redeclares) | Experimental |
    | [`avoid_annotating_with_dynamic`](https://dart.dev/tools/linter-rules/avoid_annotating_with_dynamic) | Not specified |
    | [`avoid_classes_with_only_static_members`](https://dart.dev/tools/linter-rules/avoid_classes_with_only_static_members) | Not specified |
    | [`avoid_futureor_void`](https://dart.dev/tools/linter-rules/avoid_futureor_void) | Experimental |
    | [`avoid_implementing_value_types`](https://dart.dev/tools/linter-rules/avoid_implementing_value_types) | We need to implement value types for mocks/fakes in tests |
    | [`avoid_null_checks_in_equality_operators`](https://dart.dev/tools/linter-rules/avoid_null_checks_in_equality_operators) | Has been deprecated and [will be removed](https://github.com/dart-lang/sdk/issues/59514) |
    | [`close_sinks`](https://dart.dev/tools/linter-rules/close_sinks) | [Has unresolved false positives](https://dart.dev/tools/linter/issues/1381) |
    | [`diagnostic_describe_all_properties`](https://dart.dev/tools/linter-rules/diagnostic_describe_all_properties) | Not specified |
    | [`do_not_use_environment`](https://dart.dev/tools/linter-rules/do_not_use_environment) | Not specified |
    | [`library_names`](https://dart.dev/tools/linter-rules/library_names) | [Superseded by `unnecessary_library_name`](https://dart.dev/tools/linter-rules/unnecessary_library_name) |
    | [`omit_obvious_local_variable_types`](https://dart.dev/tools/linter-rules/omit_obvious_local_variable_types) | Experimental |
    | [`omit_obvious_property_types`](https://dart.dev/tools/linter-rules/omit_obvious_property_types) | Incompatible with [type_annotate_public_apis](https://dart.dev/tools/linter-rules/type_annotate_public_apis) |
    | [`package_prefixed_library_names`](https://dart.dev/tools/linter-rules/package_prefixed_library_names) | [Broken; superseded by `unnecessary_library_name`](https://dart.dev/tools/linter-rules/unnecessary_library_name) |
    | [`prefer_double_quotes`](https://dart.dev/tools/linter-rules/prefer_double_quotes) | Incompatible with [prefer_single_quotes](https://dart.dev/tools/linter-rules/prefer_single_quotes) |
    | [`prefer_expression_function_bodies`](https://dart.dev/tools/linter-rules/prefer_expression_function_bodies) | Not specified |
    | [`prefer_final_parameters`](https://dart.dev/tools/linter-rules/prefer_final_parameters) | Incompatible with [avoid_final_parameters](https://dart.dev/tools/linter-rules/avoid_final_parameters) |
    | [`prefer_for_elements_to_map_fromiterable`](https://dart.dev/tools/linter-rules/prefer_for_elements_to_map_fromiterable) | Not specified |
    | [`prefer_relative_imports`](https://dart.dev/tools/linter-rules/prefer_relative_imports) | Incompatible with [always_use_package_imports](https://dart.dev/tools/linter-rules/always_use_package_imports) |
    | [`prefer_void_to_null`](https://dart.dev/tools/linter-rules/prefer_void_to_null) | [Has unresolved false positives](https://dart.dev/tools/linter/issues/4758) |
    | [`specify_nonobvious_local_variable_types`](https://dart.dev/tools/linter-rules/specify_nonobvious_local_variable_types) | Experimental |
    | [`unnecessary_async`](https://dart.dev/tools/linter-rules/unnecessary_async) | Experimental |
    | [`unnecessary_final`](https://dart.dev/tools/linter-rules/unnecessary_final) | Incompatible with [prefer_final_locals](https://dart.dev/tools/linter-rules/prefer_final_locals) |
    | [`unsafe_variance`](https://dart.dev/tools/linter-rules/unsafe_variance) | Experimental |
    | [`use_decorated_box`](https://dart.dev/tools/linter-rules/use_decorated_box) | [Has unresolved malfunctions](https://dart.dev/tools/linter/issues/3286) |