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

docs: improve rule checklist for contributors #1085

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* feat: add static code diagnostic [`arguments-ordering`](https://dartcodemetrics.dev/docs/rules/common/arguments-ordering).
* feat: add method call chains support for [`ban-name`](https://dartcodemetrics.dev/docs/rules/common/ban-name).
* fix: update `dart_all.yaml` preset to contain missing rules.
* docs: improve rule checklist for contributors
* feat: add static code diagnostic [`prefer-static-class`](https://dartcodemetrics.dev/docs/rules/common/prefer-static-class).
* feat: ignore `hcwidget` annotations in ['avoid-returning-widgets'](https://dartcodemetrics.dev/docs/rules/common/avoid-returning-widgets) rule by default.

Expand Down
21 changes: 12 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ PR titles should follow the format below:
To create a new rule:

1. Choose a rule name according to our naming guide or take it from existing issue for the rule.
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
3. Create a rule `.dart` file under `lib/src/analyzers/lint_analyzer/rules/rules_list`.
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.
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.
3. Add rule entry into rule index file `website/docs/rules/index.mdx`.
4. Create a rule `.dart` file under `lib/src/analyzers/lint_analyzer/rules/rules_list`.
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.

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:

Expand All @@ -35,10 +36,10 @@ To create a new rule:
);
```

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.
6. Add methods overrides to the visitor class for nodes that you want to check (ex. `visitBinaryExpression`, `visitBlock`).
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).
8. In the rule class add override to `check` method. Create a visitor instance and visit all compilation unit children with it.
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.
7. Add methods overrides to the visitor class for nodes that you want to check (ex. `visitBinaryExpression`, `visitBlock`).
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).
9. In the rule class add override to `check` method. Create a visitor instance and visit all compilation unit children with it.

Convert data to `Issue`'s and return them from the method. Example:

Expand All @@ -63,7 +64,8 @@ To create a new rule:
}
```

9. Add the rule to the `lib/src/analyzers/lint_analyzer/rules/rules_factory.dart`. Example:
> Override `toJson` method if the rule is configurable.
10. Add the rule to the `lib/src/analyzers/lint_analyzer/rules/rules_factory.dart`. Example:

```dart
final _implementedRules = <String, Rule Function(Map<String, Object>)>{
Expand All @@ -74,7 +76,8 @@ To create a new rule:
}
```

10. Add the rule tests under `test/analyzers/lint_analyzer/rules/rules_list/`. Prefer to split test examples to a correct/incorrect groups.
11. Add the rule tests under `test/analyzers/lint_analyzer/rules/rules_list/`. Prefer to split test examples to a correct/incorrect groups.
12. Add rule into appropriate presets file: `lib/presets/dart_all.yaml` or `lib/presets/flutter_all.yaml`.

## Run the plugin in IDE

Expand Down