|
| 1 | +[](https://pub.dev/packages/flutter_lints) |
| 2 | + |
| 3 | +This package contains a recommended set of lints for [Flutter] apps, packages, |
| 4 | +and plugins to encourage good coding practices. |
| 5 | + |
| 6 | +Lints are surfaced by the [dart analyzer], which statically checks dart code. |
| 7 | +[Dart-enabled IDEs] typically present the issues identified by the analyzer in |
| 8 | +their UI. Alternatively, the analyzer can be invoked manually by running |
| 9 | +`flutter analyze`. |
| 10 | + |
| 11 | +This package is built on top of Dart's `recommended.yaml` set of lints from |
| 12 | +[package:lints]. |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +Flutter apps, packages, and plugins created with `flutter create` starting with |
| 17 | +Flutter version 2.xx are already set up to use the lints defined in this |
| 18 | +package. Entities created before that version can use these lints by following |
| 19 | +these instructions: |
| 20 | + |
| 21 | +1. Depend on this package as a **dev_dependency** by running |
| 22 | + `flutter pub add --dev flutter_lints`. |
| 23 | +2. Create an `analyzer_options.yaml` file at the root of the package (alongside |
| 24 | + the `pubspec.yaml` file) and `include: package:flutter_lints/flutter.yaml` |
| 25 | + from it. |
| 26 | + |
| 27 | +Example `analyzer_options.yaml` file: |
| 28 | + |
| 29 | +```yaml |
| 30 | +# This file configures the analyzer, which statically analyzes Dart code to |
| 31 | +# check for errors, warnings, and lints. |
| 32 | +# |
| 33 | +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled |
| 34 | +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be |
| 35 | +# invoked from the command line by running `flutter analyze`. |
| 36 | + |
| 37 | +# The following line activates a set of recommended lints for Flutter apps, |
| 38 | +# packages, and plugins designed to encourage good coding practices. |
| 39 | +include: package:flutter_lints/flutter.yaml |
| 40 | + |
| 41 | +linter: |
| 42 | + # The lint rules applied to this project can be customized in the |
| 43 | + # section below to disable rules from the `package:flutter_lints/flutter.yaml` |
| 44 | + # included above or to enable additional rules. A list of all available lints |
| 45 | + # and their documentation is published at |
| 46 | + # https://dart-lang.github.io/linter/lints/index.html. |
| 47 | + # |
| 48 | + # Instead of disabling a lint rule for the entire project in the |
| 49 | + # section below, it can also be suppressed for a single line of code |
| 50 | + # or a specific dart file by using the `// ignore: name_of_lint` and |
| 51 | + # `// ignore_for_file: name_of_lint` syntax on the line or in the file |
| 52 | + # producing the lint. |
| 53 | + rules: |
| 54 | + # avoid_print: false # Uncomment to disable the `avoid_print` rule |
| 55 | + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule |
| 56 | + |
| 57 | +# Additional information about this file can be found at |
| 58 | +# https://dart.dev/guides/language/analysis-options |
| 59 | +``` |
| 60 | + |
| 61 | +[Flutter]: https://flutter.dev |
| 62 | +[dart analyzer]: https://dart.dev/guides/language/analysis-options |
| 63 | +[Dart-enabled IDEs]: https://dart.dev/tools#ides-and-editors |
| 64 | +[package:lints]: https://pub.dev/packages/lints |
0 commit comments