-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add flutter_lints package #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
073773a
03c11b0
5a9517c
b951aac
8470f96
7abc3d0
1c27034
10f9419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.1.0 | ||
|
||
* Initial release |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright 2021, The Flutter Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google LLC nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
This package contains a recommended set of lints for [Flutter] apps, packages, | ||
and plugins to 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`. | ||
|
||
## Usage | ||
|
||
Flutter apps, packages, and plugins created with `flutter create` starting with | ||
Flutter version 2.xx are already set up to use the lints defined in this | ||
package. Entities created before that version can use these lints by following | ||
these instructions: | ||
|
||
1. Depend on this package as a **dev_dependency** by running | ||
`flutter pub add --dev flutter_lints`. | ||
2. Create an `analyzer_options.yaml` file at the root of the package (alongside | ||
the `pubspec.yaml` file) and `include: package:flutter_lints/flutter.yaml` | ||
from it. | ||
|
||
Example `analyzer_options.yaml` file: | ||
|
||
```yaml | ||
# 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/flutter.yaml | ||
|
||
linter: | ||
# The lint rules applied to this project can be customized in the | ||
# section below to disable rules from the `package:lints/flutter.yaml` | ||
# included above or to enable additional rules. A list of all available lints | ||
# and their documentation is published at | ||
# https://dart-lang.github.io/linter/lints/index.html. | ||
# | ||
# 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 | ||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options | ||
``` | ||
|
||
[Flutter]: https://flutter.dev | ||
[dart analyzer]: https://dart.dev/guides/language/analysis-options | ||
[Dart-enabled IDEs]: https://dart.dev/tools#ides-and-editors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Recomended lints for Flutter apps, packages, and plugins. | ||
|
||
include: package:lints/recommended.yaml | ||
|
||
linter: | ||
rules: | ||
- avoid_print | ||
- avoid_unnecessary_containers | ||
- avoid_web_libraries_in_flutter | ||
- no_logic_in_create_state | ||
- prefer_const_constructors | ||
- prefer_const_constructors_in_immutables | ||
- prefer_const_declarations | ||
- prefer_const_literals_to_create_immutables | ||
- sized_box_for_whitespace | ||
- use_full_hex_values_for_flutter_colors | ||
- use_key_in_widget_constructors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: flutter_lints | ||
description: Recommended lints for Flutter apps, packages, and plugins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. End with a period? =>
|
||
version: 0.1.0 | ||
homepage: https://github.com/flutter/packages/tree/master/packages/flutter_lints | ||
publish_to: none | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want to remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ultimately, yes. However, while I pull in the "lints" dependency directly from github below, there's a lint telling me that I need this. 😝 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha! |
||
|
||
environment: | ||
sdk: '>=2.12.0 <3.0.0' | ||
|
||
dependencies: | ||
lints: # TODO(goderbauer): depend on released version before releasing the package | ||
git: https://github.com/dart-lang/lints.git | ||
# Code is not allowed in this package. Do not add any dependencies or dev_dependencies. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
filecount=`find . -name '*.dart' | wc -l` | ||
if [ $filecount -ne 0 ] | ||
then | ||
echo 'Dart sources are not allowed in this package:' | ||
find . -name '*.dart' | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> Recommended