File tree Expand file tree Collapse file tree 11 files changed +115
-8
lines changed
Expand file tree Collapse file tree 11 files changed +115
-8
lines changed Original file line number Diff line number Diff line change 55# Avoid committing pubspec.lock for library packages; see
66# https://dart.dev/guides/libraries/private-files#pubspeclock.
77pubspec.lock
8+
9+ example /custom_lint.log
Original file line number Diff line number Diff line change 1+ ## 2.0.0
2+
3+ * Added rule [ flutter_style_todos] ( https://dart-lang.github.io/linter/lints/flutter_style_todos.html )
4+ * Created custom rules with the package [ custom_lint] ( https://pub.dev/packages/custom_lint )
5+ * ` avoid_as ` : Avoid using ` as ` keyword :warning :
6+ * ` avoid_non_null_assertion ` : Avoid using ` ! ` operator :warning :
7+
18## 1.1.1
29
310* Added rule invalid_annotation_target as ignored
Original file line number Diff line number Diff line change @@ -15,20 +15,25 @@ You can use 2 different sets of rules:
1515* ` dart ` : for Dart projects
1616* ` flutter ` : for Flutter projects (includes ` dart ` rules)
1717
18- ## Install
18+ ## Installing fd_lints
1919
20- Add the version you want to your ` pubspec.yaml ` :
20+ * Add both fd_lints and custom_lint to your ` pubspec.yaml ` file :
2121
2222``` yaml
2323dev_dependencies :
24- fd_lints : any
24+ custom_lint :
25+ fd_lints :
2526` ` `
2627
27- Creates an ` analysis_options.yaml` file in the root of your project and add the following content :
28+ * Include the set of rules you want to use and enable ` custom_lint`'s plugin in your `analysis_options.yaml` file :
2829
2930` ` ` yaml
30- include: package:fd_lints/dart.yaml # For Dart projects
31- # include: package:fd_lints/flutter.yaml # For Flutter projects
31+ include: package:fd_lints/dart.yaml # Recommended for Dart projects
32+ # include: package:fd_lints/flutter.yaml # Recommended for Flutter projects
33+
34+ analyzer:
35+ plugins:
36+ - custom_lint
3237` ` `
3338
3439# # Analyzer
@@ -55,6 +60,15 @@ The following files are excluded by default:
5560* :warning: : warning
5661* :x: : error
5762
63+ # ## Custom
64+
65+ Those rules were created by us by using the [custom_lint](https://pub.dev/packages/custom_lint) package.
66+
67+ | **Rule** | **Severity** |
68+ |----------------------------------------------------------|----------------------|
69+ | avoid_non_null_assertion | :warning : |
70+ | avoid_as | :warning : |
71+
5872# ## Dart
5973
6074| **Rule** | **Severity** |
Original file line number Diff line number Diff line change 1+ include : package:lints/recommended.yaml
Original file line number Diff line number Diff line change @@ -16,4 +16,8 @@ dev_dependencies:
1616
1717` ` ` yaml
1818include : package:fd_lints/dart.yaml
19+
20+ analyzer :
21+ plugins :
22+ - custom_lint
1923` ` `
Original file line number Diff line number Diff line change 11include : package:fd_lints/dart.yaml # For Dart projects
22# include: package:fd_lints/flutter.yaml # For Flutter projects
3+
4+ analyzer :
5+ plugins :
6+ - custom_lint
Original file line number Diff line number Diff line change @@ -6,5 +6,6 @@ environment:
66 sdk : " >=2.18.0 <3.0.0"
77
88dev_dependencies :
9+ custom_lint : ^0.4.0
910 fd_lints :
1011 path : ../
Original file line number Diff line number Diff line change 1+ import 'package:custom_lint_builder/custom_lint_builder.dart' ;
2+ import 'package:fd_lints/src/lints/avoid_as.dart' ;
3+ import 'package:fd_lints/src/lints/avoid_non_null_assertion.dart' ;
4+
5+ PluginBase createPlugin () => _FDLintsPlugin ();
6+
7+ class _FDLintsPlugin extends PluginBase {
8+ @override
9+ List <LintRule > getLintRules (CustomLintConfigs configs) {
10+ return [
11+ AvoidNonNullAssertion (),
12+ AvoidAs (),
13+ ];
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ import 'package:analyzer/error/error.dart' ;
2+ import 'package:analyzer/error/listener.dart' ;
3+ import 'package:custom_lint_builder/custom_lint_builder.dart' ;
4+
5+ class AvoidAs extends DartLintRule {
6+ AvoidAs () : super (code: _code);
7+
8+ static const _code = LintCode (
9+ name: 'avoid_as' ,
10+ problemMessage: 'Avoid using the "as" operator.' ,
11+ errorSeverity: ErrorSeverity .WARNING ,
12+ );
13+
14+ @override
15+ void run (
16+ CustomLintResolver resolver,
17+ ErrorReporter reporter,
18+ CustomLintContext context,
19+ ) {
20+ context.registry.addAsExpression ((node) {
21+ reporter.reportErrorForNode (code, node);
22+ });
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ import 'package:analyzer/error/error.dart' ;
2+ import 'package:analyzer/error/listener.dart' ;
3+ import 'package:custom_lint_builder/custom_lint_builder.dart' ;
4+
5+ class AvoidNonNullAssertion extends DartLintRule {
6+ AvoidNonNullAssertion () : super (code: _code);
7+
8+ static const _code = LintCode (
9+ name: 'avoid_non_null_assertion' ,
10+ problemMessage: 'Avoid using the "bang" operator (!).' ,
11+ errorSeverity: ErrorSeverity .WARNING ,
12+ );
13+
14+ @override
15+ void run (
16+ CustomLintResolver resolver,
17+ ErrorReporter reporter,
18+ CustomLintContext context,
19+ ) {
20+ context.registry.addPostfixExpression ((node) {
21+ if (node.operator .lexeme == '!' ) {
22+ reporter.reportErrorForNode (code, node);
23+ }
24+ });
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments