Skip to content

Commit b17875f

Browse files
authored
Add flutter_lints package (#343)
1 parent 9e8f522 commit b17875f

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

packages/flutter_lints/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0-dev.0
2+
3+
* Initial pre-release

packages/flutter_lints/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2021, The Flutter Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/flutter_lints/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[![pub package](https://img.shields.io/pub/v/flutter_lints.svg)](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
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Recommended lints for Flutter apps, packages, and plugins.
2+
3+
include: package:lints/recommended.yaml
4+
5+
linter:
6+
rules:
7+
- avoid_print
8+
- avoid_unnecessary_containers
9+
- avoid_web_libraries_in_flutter
10+
- no_logic_in_create_state
11+
- prefer_const_constructors
12+
- prefer_const_constructors_in_immutables
13+
- prefer_const_declarations
14+
- prefer_const_literals_to_create_immutables
15+
- sized_box_for_whitespace
16+
- use_full_hex_values_for_flutter_colors
17+
- use_key_in_widget_constructors

packages/flutter_lints/pubspec.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: flutter_lints
2+
description: Recommended lints for Flutter apps, packages, and plugins.
3+
version: 1.0.0-dev.0
4+
homepage: https://github.com/flutter/packages/tree/master/packages/flutter_lints
5+
6+
environment:
7+
sdk: '>=2.12.0 <3.0.0'
8+
9+
dependencies:
10+
lints: ^1.0.0-dev.0
11+
# Code is not allowed in this package. Do not add any dependencies or dev_dependencies.

packages/flutter_lints/run_tests.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
filecount=`find . -name '*.dart' | wc -l`
4+
if [ $filecount -ne 0 ]
5+
then
6+
echo 'Dart sources are not allowed in this package:'
7+
find . -name '*.dart'
8+
exit 1
9+
fi

0 commit comments

Comments
 (0)