Skip to content

About

Recommended lints for Flutter apps, packages, and plugins to encourage good coding practices.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pub package

This package contains a recommended set of lints for Flutter apps, packages, and plugins to encourage good coding practices.

It is essentially a combination of three sources:

  1. Dart's package:lints — its recommended set (which itself includes the core set). This package depends on lints directly, so it picks up every compatible release of lints; a new major version of lints needs a new release of this package.
  2. Flutter's package:flutter_lints — its Flutter-specific rules (for example use_key_in_widget_constructors and use_build_context_synchronously). These are enabled directly rather than by depending on flutter_lints, because flutter_lints tends to lag behind lints, and depending on it has at times held lints back to an older version.
  3. A curated selection of additional lints from the full list of Dart linter rules that further encourage good coding practices.

Lints are surfaced by the Dart analyzer, which statically checks Dart code. Dart-enabled IDEs typically present the issues identified by the analyzer in their UI. Alternatively, the analyzer can be invoked manually by running flutter analyze.

Analyzer settings

Besides lint rules, the included file also configures the analyzer:

  • It turns on the strict-inference type check, which reports code where the analyzer can't infer a type and would otherwise fall back to dynamic.
  • It reports implicit casts from dynamic (no_dynamic_casts) as errors and generic types without type arguments, such as List (no_raw_types), as warnings. These two lints replace the older strict-casts and strict-raw-types type checks.
  • It raises missing_required_param, missing_return, and record_literal_one_positional_no_trailing_comma to errors, and collection_methods_unrelated_type and unrelated_type_equality_checks to warnings.
  • It excludes generated_plugin_registrant.dart and .test_coverage.dart files from analysis.

Any of these can be changed in your own analysis_options.yaml. For example, no_dynamic_casts: false under linter: rules: turns off the check for implicit casts from dynamic, and no_raw_types: info under analyzer: errors: lowers that check to an info.

Reading flutter.yaml

lib/flutter.yaml lists every Dart lint rule in alphabetical order, so it shows what this package leaves off as well as what it turns on:

  • - rule_name is enabled by this package. A trailing # flutter-lints means the rule also comes from package:flutter_lints.
  • # - rule_name # dart-lang core (or # dart-lang recommended) is already enabled by package:lints, so it's listed only for completeness.
  • # DISABLE - rule_name is deliberately left off. # NEW, DISABLE (or # NEW, DISABLE FOR NOW) marks a rule that was left off when it was added to Dart.
  • # EXPERIMENTAL - rule_name is experimental in Dart and left off. A few experimental rules that work well, such as unnecessary_async, are enabled.
  • # DEPRECATED - rule_name and # REMOVED - rule_name have been deprecated or removed from Dart.
  • # NEW! marks a rule enabled in the latest release of this package; the changelog lists them.

To turn on a rule that this package leaves off, add rule_name: true under linter: rules: in your own analysis_options.yaml.

Usage

Enable these lints by following these instructions:

  1. Depend on this package as a dev_dependency by running flutter pub add --dev flutter_lints_plus.
  2. Create an analysis_options.yaml file at the root of the package (alongside the pubspec.yaml file) and include: package:flutter_lints_plus/flutter.yaml from it.

Example analysis_options.yaml file:

# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints_plus/flutter.yaml

linter:
  # The lint rules applied to this project can be customized in the
  # section below to disable rules from the `package:flutter_lints_plus/flutter.yaml`
  # included above or to enable additional rules. A list of all available lints
  # and their documentation is published at
  # https://dart.dev/tools/linter-rules/all.
  #
  # Instead of disabling a lint rule for the entire project in the
  # section below, it can also be suppressed for a single line of code
  # or a specific dart file by using the `// ignore: name_of_lint` and
  # `// ignore_for_file: name_of_lint` syntax on the line or in the file
  # producing the lint.
  rules:
    # avoid_print: false  # Uncomment to disable the `avoid_print` rule
    # public_member_api_docs: true  # Uncomment to enable the `public_member_api_docs` rule

# Additional information about this file can be found at
# https://dart.dev/tools/analysis

About

Recommended lints for Flutter apps, packages, and plugins to encourage good coding practices.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors