Skip to content

Commit f18ba69

Browse files
authored
Add example to flutter_lints package (#354)
1 parent 1b5a369 commit f18ba69

File tree

8 files changed

+99
-3
lines changed

8 files changed

+99
-3
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ task:
3232
- name: format+analyze
3333
format_script: ./script/tool_runner.sh format --fail-on-change --clang-format=clang-format-5.0
3434
license_script: pub global run flutter_plugin_tools license-check
35-
analyze_script: ./script/tool_runner.sh analyze --custom-analysis=web_benchmarks/testing/test_app
35+
analyze_script: ./script/tool_runner.sh analyze --custom-analysis=web_benchmarks/testing/test_app,flutter_lints/example
3636
- name: publishable
3737
version_script: ./script/tool_runner.sh version-check
3838
publishable_script: ./script/tool_runner.sh publish-check

packages/flutter_lints/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.1
2+
3+
* Added an example project
4+
15
## 1.0.0
26

37
* Initial release
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
An example project that showcases how to enable the lint set from
2+
`package:flutter_lints`, which contains recommended lints for Flutter apps,
3+
packages, and plugins.
4+
5+
The `flutter_lints` packages is listed as a dev_dependency in the `pubspec.yaml`
6+
file.
7+
8+
The lint set provided by the package is activated in the `analysis_options.yaml`
9+
file. The lints enforced for this project can be further customized in that
10+
file.
11+
12+
The Dart code in this project (e.g. `lib/main.dart`) is analyzed using the
13+
lint configuration provided by `package:flutter_lints`.
14+
15+
The issues identified by the analyzer are surfaced in IDEs with Dart support or
16+
by invoking `flutter analyze` from the command line.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at
17+
# https://dart-lang.github.io/linter/lints/index.html.
18+
#
19+
# Instead of disabling a lint rule for the entire project in the
20+
# section below, it can also be suppressed for a single line of code
21+
# or a specific dart file by using the `// ignore: name_of_lint` and
22+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23+
# producing the lint.
24+
rules:
25+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27+
28+
# Additional information about this file can be found at
29+
# https://dart.dev/guides/language/analysis-options
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// The code in this file (and all other dart files in the package) is
6+
// analyzed using the rules activated in `analysis_options.yaml`.
7+
8+
// The following syntax deactivates a lint for the entire file:
9+
// ignore_for_file: avoid_renaming_method_parameters
10+
11+
void main() {
12+
const String partOne = 'Hello';
13+
const String partTwo = 'World';
14+
15+
// The following syntax deactivates a lint on a per-line bases:
16+
print('$partOne $partTwo'); // ignore: avoid_print
17+
}
18+
19+
abstract class Base {
20+
int methodA(int foo);
21+
String methodB(String foo);
22+
}
23+
24+
// Normally, the parameter renaming from `foo` to `bar` in this class would
25+
// trigger the `avoid_renaming_method_parameters` lint, but it has been
26+
// deactivated for the file with the `ignore_for_file` comment above.
27+
class Sub extends Base {
28+
@override
29+
int methodA(int bar) => bar;
30+
31+
@override
32+
String methodB(String bar) => bar;
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: example
2+
description: A project that showcases how to enable the recommended lints for Flutter apps, packages, and plugins.
3+
4+
publish_to: none
5+
6+
environment:
7+
sdk: '>=2.12.0 <3.0.0'
8+
9+
# Add the latest version of `package:flutter_lints` as a dev_dependency. The
10+
# lint set provided by this package is activated in the `analysis_options.yaml`
11+
# file located next to this `pubspec.yaml` file.
12+
dev_dependencies:
13+
flutter_lints: ^1.0.0 # Check https://pub.dev/packages/flutter_lints for latest version number.

packages/flutter_lints/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_lints
22
description: Recommended lints for Flutter apps, packages, and plugins to encourage good coding practices.
3-
version: 1.0.0
3+
version: 1.0.1
44
homepage: https://github.com/flutter/packages/tree/master/packages/flutter_lints
55

66
environment:

packages/flutter_lints/run_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
55

6-
filecount=`find . -name '*.dart' | wc -l`
6+
# Dart sources are only allowed in the example directory.
7+
filecount=`find . -name '*.dart' ! -path './example/*' | wc -l`
78
if [ $filecount -ne 0 ]
89
then
910
echo 'Dart sources are not allowed in this package:'

0 commit comments

Comments
 (0)