Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 49aca89

Browse files
Roman Petrovincendial
andauthored
docs: improve rule checklist for contributors (#1085)
* docs: improve rule checklist for contributors * fix: address review comment Co-authored-by: Dmitry Zhifarsky <[email protected]>
1 parent 4900412 commit 49aca89

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* feat: add static code diagnostic [`arguments-ordering`](https://dartcodemetrics.dev/docs/rules/common/arguments-ordering).
66
* feat: add method call chains support for [`ban-name`](https://dartcodemetrics.dev/docs/rules/common/ban-name).
77
* fix: update `dart_all.yaml` preset to contain missing rules.
8+
* docs: improve rule checklist for contributors
89
* feat: add static code diagnostic [`prefer-static-class`](https://dartcodemetrics.dev/docs/rules/common/prefer-static-class).
910
* feat: ignore `hcwidget` annotations in ['avoid-returning-widgets'](https://dartcodemetrics.dev/docs/rules/common/avoid-returning-widgets) rule by default.
1011

CONTRIBUTING.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ PR titles should follow the format below:
1919
To create a new rule:
2020

2121
1. Choose a rule name according to our naming guide or take it from existing issue for the rule.
22-
2. Add an `.md` file with the rule documentation to `website/docs/rules`. If the rule supports configuration add ![Configurable](https://img.shields.io/badge/-configurable-informational) badge, if it has auto-fixes add ![Has auto-fix](https://img.shields.io/badge/-has%20auto--fix-success) badge
23-
3. Create a rule `.dart` file under `lib/src/analyzers/lint_analyzer/rules/rules_list`.
24-
4. Create a class that extends an abstract rule class depending on your rule type. Available classes: `FlutterRule`, `CommonRule`, `IntlRule`, `AngularRule`. Add a public field with rule id, documentation url.
22+
2. Add an `.md` file with the rule documentation to `website/docs/rules`. If the rule supports configuration add ![Configurable](https://img.shields.io/badge/-configurable-informational) badge, if it has auto-fixes add ![Has auto-fix](https://img.shields.io/badge/-has%20auto--fix-success) badge.
23+
3. Add rule entry into rule index file `website/docs/rules/index.mdx`.
24+
4. Create a rule `.dart` file under `lib/src/analyzers/lint_analyzer/rules/rules_list`.
25+
5. Create a class that extends an abstract rule class depending on your rule type. Available classes: `FlutterRule`, `CommonRule`, `IntlRule`, `AngularRule`. Add a public field with rule id, documentation url.
2526

2627
The class constructor should take `Map<String, Object> config` parameter which represents config that is passed to the rule from the `analysis_options.yaml`. Example:
2728

@@ -35,10 +36,10 @@ To create a new rule:
3536
);
3637
```
3738
38-
5. Add a visitor class which extends any of the base visitors. Usually you will need `RecursiveAstVisitor`. All visitors are [listed there](https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/dart/ast/visitor.dart). Visitor should be added to a separate file and imported with `part` directive.
39-
6. Add methods overrides to the visitor class for nodes that you want to check (ex. `visitBinaryExpression`, `visitBlock`).
40-
7. Collect all data needed for the rule (we usually use a private field for data storage and public getter to access it from the `check` method).
41-
8. In the rule class add override to `check` method. Create a visitor instance and visit all compilation unit children with it.
39+
6. Add a visitor class which extends any of the base visitors. Usually you will need `RecursiveAstVisitor`. All visitors are [listed there](https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/dart/ast/visitor.dart). Visitor should be added to a separate file and imported with `part` directive.
40+
7. Add methods overrides to the visitor class for nodes that you want to check (ex. `visitBinaryExpression`, `visitBlock`).
41+
8. Collect all data needed for the rule (we usually use a private field for data storage and public getter to access it from the `check` method).
42+
9. In the rule class add override to `check` method. Create a visitor instance and visit all compilation unit children with it.
4243
4344
Convert data to `Issue`'s and return them from the method. Example:
4445
@@ -63,7 +64,8 @@ To create a new rule:
6364
}
6465
```
6566
66-
9. Add the rule to the `lib/src/analyzers/lint_analyzer/rules/rules_factory.dart`. Example:
67+
> Override `toJson` method if the rule is configurable.
68+
10. Add the rule to the `lib/src/analyzers/lint_analyzer/rules/rules_factory.dart`. Example:
6769
6870
```dart
6971
final _implementedRules = <String, Rule Function(Map<String, Object>)>{
@@ -74,7 +76,8 @@ To create a new rule:
7476
}
7577
```
7678
77-
10. Add the rule tests under `test/analyzers/lint_analyzer/rules/rules_list/`. Prefer to split test examples to a correct/incorrect groups.
79+
11. Add the rule tests under `test/analyzers/lint_analyzer/rules/rules_list/`. Prefer to split test examples to a correct/incorrect groups.
80+
12. Add rule into appropriate presets file: `lib/presets/dart_all.yaml` or `lib/presets/flutter_all.yaml`.
7881
7982
## Run the plugin in IDE
8083

0 commit comments

Comments
 (0)