You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
@@ -36,144 +36,167 @@ Dart Code Metrics is a static analysis tool that helps you analyse and improve y
36
36
- To contribute, please read [CONTRIBUTING.md](./CONTRIBUTING.md) first.
37
37
- Please [open an issue](https://github.com/dart-code-checker/dart-code-metrics/issues/new?assignees=dkrutskikh&labels=question&template=question.md&title=%5BQuestion%5D+) if anything is missing or unclear in this documentation.
38
38
39
-
## Quick start
39
+
## Installation
40
+
41
+
```sh
42
+
$ dart pub add --dev dart_code_metrics
43
+
44
+
# or for a Flutter package
45
+
$ flutter pub add --dev dart_code_metrics
46
+
```
47
+
48
+
**OR**
49
+
50
+
add it manually to `pubspec.yaml`
51
+
52
+
```yaml
53
+
dev_dependencies:
54
+
dart_code_metrics: ^4.5.0
55
+
```
56
+
57
+
and then run
58
+
59
+
```sh
60
+
$ dart pub get
61
+
62
+
# or for a Flutter package
63
+
$ flutter pub get
64
+
```
65
+
66
+
## Basic configuration
67
+
68
+
Add configuration to `analysis_options.yaml`
69
+
70
+
```yaml
71
+
dart_code_metrics:
72
+
anti-patterns:
73
+
- long-method
74
+
- long-parameter-list
75
+
metrics:
76
+
cyclomatic-complexity: 20
77
+
maximum-nesting-level: 5
78
+
number-of-parameters: 4
79
+
source-lines-of-code: 50
80
+
metrics-exclude:
81
+
- test/**
82
+
rules:
83
+
- newline-before-return
84
+
- no-boolean-literal-compare
85
+
- no-empty-block
86
+
- prefer-trailing-comma
87
+
- prefer-conditional-expressions
88
+
- no-equal-then-else
89
+
```
90
+
91
+
Reload IDE to allow the analyzer to discover the plugin config.
92
+
93
+
You can read more about the configuration [on the website](https://dartcodemetrics.dev/docs/getting-started/configuration).
94
+
95
+
## Usage
40
96
41
97
### Analyzer plugin
42
98
43
-
A plugin for the Dart `analyzer`[package](https://pub.dev/packages/analyzer) providing additional rules from Dart Code Metrics. All issues produced by rules or anti-patterns will be highlighted in IDE.
44
-
45
-
1. Install package as a dev dependency
46
-
47
-
```sh
48
-
$ dart pub add --dev dart_code_metrics
49
-
50
-
# or for a Flutter package
51
-
$ flutter pub add --dev dart_code_metrics
52
-
```
53
-
54
-
**OR**
55
-
56
-
add it manually to `pubspec.yaml`
57
-
58
-
```yaml
59
-
dev_dependencies:
60
-
dart_code_metrics: ^4.5.0
61
-
```
62
-
63
-
and then run
64
-
65
-
```sh
66
-
$ dart pub get
67
-
68
-
# or for a Flutter package
69
-
$ flutter pub get
70
-
```
71
-
72
-
2. Add configuration to `analysis_options.yaml`
73
-
74
-
```yaml
75
-
analyzer:
76
-
plugins:
77
-
- dart_code_metrics
78
-
79
-
dart_code_metrics:
80
-
anti-patterns:
81
-
- long-method
82
-
- long-parameter-list
83
-
metrics:
84
-
cyclomatic-complexity: 20
85
-
maximum-nesting-level: 5
86
-
number-of-parameters: 4
87
-
source-lines-of-code: 50
88
-
metrics-exclude:
89
-
- test/**
90
-
rules:
91
-
- newline-before-return
92
-
- no-boolean-literal-compare
93
-
- no-empty-block
94
-
- prefer-trailing-comma
95
-
- prefer-conditional-expressions
96
-
- no-equal-then-else
97
-
```
98
-
99
-
3. Reload IDE to allow the analyzer to discover the plugin
99
+
Dart Code Metrics can be used as a plugin for the Dart `analyzer` [package](https://pub.dev/packages/analyzer) providing additional rules. All issues produced by rules or anti-patterns will be highlighted in IDE.
| check-unused-l10n | dart run dart_code_metrics:metrics check-unused-l10n lib | Check unused localization in *.dart files. |
116
+
117
+
For additional help on any of the commands, enter `dart run dart_code_metrics:metrics help <command>`
118
+
119
+
**Note:** if you're setting up Dart Code Metrics for multi-package repository, check out [this website section](https://dartcodemetrics.dev/docs/cli/overview#multi-package-repositories-usage).
120
+
121
+
#### Analyze
122
+
123
+
Reports code metrics, rules and anti-patterns violations. To execute the command, run
124
+
125
+
```sh
126
+
$ dart run dart_code_metrics:metrics analyze lib
127
+
128
+
# or for a Flutter package
129
+
$ flutter pub run dart_code_metrics:metrics analyze lib
Install the package as listed in the [Analyzer plugin usage example](#analyzer-plugin).
144
+
#### Check unused files
115
145
116
-
If you want the command-line tool to check rules, you [should configure](https://dartcodemetrics.dev/docs/getting-started/configuration#configuring-a-rules-entry) `rules` entry inthe `analysis_options.yaml` first.
146
+
Checks unused `*.dart` files. To execute the command, run
117
147
118
148
```sh
119
-
dart pub run dart_code_metrics:metrics lib
149
+
$ dart run dart_code_metrics:metrics check-unused-files lib
120
150
121
151
# or for a Flutter package
122
-
flutter pub run dart_code_metrics:metrics lib
152
+
$ flutter pub run dart_code_metrics:metrics check-unused-files lib
123
153
```
124
154
125
-
#### Multi-package repositories usage
155
+
It will produce a result in one of the format:
126
156
127
-
If you use [Melos](https://pub.dev/packages/melos), you can add custom command to `melos.yaml`.
157
+
- Console
158
+
- JSON
128
159
129
-
```yaml
130
-
metrics:
131
-
run: |
132
-
melos exec -c 1 --ignore="*example*" -- \
133
-
flutter pub run dart_code_metrics:metrics lib
134
-
description: |
135
-
Run `dart_code_metrics`in all packages.
136
-
- Note: you can also rely on your IDEs Dart Analysis / Issues window.
--maximum-nesting-level=<5> Maximum Nesting Level threshold.
157
-
--number-of-methods=<10> Number of Methods threshold.
158
-
--number-of-parameters=<4> Number of Parameters threshold.
159
-
--source-lines-of-code=<50> Source lines of Code threshold.
160
-
--weight-of-class=<0.33> Weight Of a Class threshold.
161
-
--maintainability-index=<50> Maintainability Index threshold.
188
+
# or for a Flutter package
189
+
$ flutter pub run dart_code_metrics:metrics check-unused-l10n lib
190
+
```
162
191
192
+
It will produce a result in one of the format:
163
193
164
-
--root-folder=<./> Root folder.
165
-
(defaults to current directory)
166
-
--sdk-path=<directory-path> Dart SDK directory path. Should be provided only when you run the application as compiled executable(https://dart.dev/tools/dart-compile#exe) and automatic Dart SDK path detection fails.
167
-
--exclude=<{/**.g.dart,/**.template.dart}> File paths in Glob syntax to be exclude.
168
-
(defaults to "{/**.g.dart,/**.template.dart}")
194
+
- Console
195
+
- JSON
169
196
197
+
Console report example:
170
198
171
-
--set-exit-on-violation-level=<warning> Set exit code 2 if code violations same or higher level than selected are detected.
172
-
[noted, warning, alarm]
173
-
--[no-]fatal-style Treat style level issues as fatal.
174
-
--[no-]fatal-performance Treat performance level issues as fatal.
175
-
--[no-]fatal-warnings Treat warning level issues as fatal.
0 commit comments