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

Commit 37503b5

Browse files
authored
docs: update README, remove folder (#534)
1 parent 75fc716 commit 37503b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+129
-2995
lines changed

README.md

Lines changed: 128 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[Anti-patterns](https://dartcodemetrics.dev/docs/anti-patterns/overivew)
1717

1818
<img
19-
src="https://raw.githubusercontent.com/dart-code-checker/dart-code-metrics/master/doc/.assets/logo.svg"
19+
src="https://raw.githubusercontent.com/dart-code-checker/dart-code-metrics/master/assets/logo.svg"
2020
alt="Dart Code Metrics logo"
2121
height="120" width="120"
2222
align="right">
@@ -36,144 +36,167 @@ Dart Code Metrics is a static analysis tool that helps you analyse and improve y
3636
- To contribute, please read [CONTRIBUTING.md](./CONTRIBUTING.md) first.
3737
- 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.
3838

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
4096
4197
### Analyzer plugin
4298
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.
100+
101+
![Highlighted issue example](https://raw.githubusercontent.com/dart-code-checker/dart-code-metrics/master/assets/plugin-example.png)
102+
103+
Rules that marked with a `has auto-fix` badge have auto-fixes available through the IDE context menu. VS Code example:
104+
105+
![VS Code example](https://raw.githubusercontent.com/dart-code-checker/dart-code-metrics/master/assets/quick-fix.gif)
100106

101107
### CLI
102108

103-
The package can be used as a command-line tool.
104-
It will produce a result in one of the supported formats:
109+
The package can be used as CLI and supports multiple commands:
110+
111+
| Command | Example of use | Short description |
112+
| ------------------ | --------------------------------------------------------- | --------------------------------------------------------- |
113+
| analyze | dart run dart_code_metrics:metrics analyze lib | Reports code metrics, rules and anti-patterns violations. |
114+
| check-unused-files | dart run dart_code_metrics:metrics check-unused-files lib | Checks unused \*.dart files. |
115+
| 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
130+
```
131+
132+
It will produce a result in one of the format:
105133

106134
- Console
107135
- GitHub
108136
- Codeclimate
109137
- HTML
110138
- JSON
111139

112-
#### Usage
140+
Console report example:
141+
142+
![Console report example](https://raw.githubusercontent.com/dart-code-checker/dart-code-metrics/master/assets/analyze-console-report.png)
113143

114-
Install the package as listed in the [Analyzer plugin usage example](#analyzer-plugin).
144+
#### Check unused files
115145

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 in the `analysis_options.yaml` first.
146+
Checks unused `*.dart` files. To execute the command, run
117147

118148
```sh
119-
dart pub run dart_code_metrics:metrics lib
149+
$ dart run dart_code_metrics:metrics check-unused-files lib
120150
121151
# 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
123153
```
124154

125-
#### Multi-package repositories usage
155+
It will produce a result in one of the format:
126156

127-
If you use [Melos](https://pub.dev/packages/melos), you can add custom command to `melos.yaml`.
157+
- Console
158+
- JSON
128159

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.
137-
```
160+
Console report example:
161+
162+
![Console report example](https://raw.githubusercontent.com/dart-code-checker/dart-code-metrics/master/assets/unused-files-console-report.png)
138163

139-
#### Options
164+
#### Check unused localization
140165

141-
```text
142-
Usage: metrics [arguments...] <directories>
166+
Checks unused Dart class members, that encapsulates the app’s localized values.
143167

144-
-h, --help Print this usage information.
168+
An example of such class:
145169

170+
```dart
171+
class ClassWithLocalization {
172+
String get title {
173+
return Intl.message(
174+
'Hello World',
175+
name: 'title',
176+
desc: 'Title for the Demo application',
177+
locale: localeName,
178+
);
179+
}
180+
}
181+
```
146182

147-
-r, --reporter=<console> The format of the output of the analysis.
148-
[console (default), console-verbose, codeclimate, github, gitlab, html, json]
149-
-o, --output-directory=<OUTPUT> Write HTML output to OUTPUT.
150-
(defaults to "metrics")
183+
To execute the command, run
151184

185+
```sh
186+
$ dart run dart_code_metrics:metrics check-unused-l10n lib
152187
153-
--cyclomatic-complexity=<20> Cyclomatic Complexity threshold.
154-
--halstead-volume=<150> Halstead Volume threshold.
155-
--lines-of-code=<100> Lines of Code threshold.
156-
--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+
```
162191

192+
It will produce a result in one of the format:
163193

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
169196

197+
Console report example:
170198

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.
176-
```
199+
![Console report example](https://raw.githubusercontent.com/dart-code-checker/dart-code-metrics/master/assets/unused-l10n-console-report.png)
177200

178201
## Troubleshooting
179202

assets/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* -text

assets/analyze-console-report.png

571 KB
Loading
File renamed without changes.

assets/plugin-example.png

95.5 KB
Loading

assets/quick-fix.gif

322 KB
Loading
24.6 KB
Loading

assets/unused-l10n-console-report.png

60.5 KB
Loading
-31.8 KB
Binary file not shown.

doc/anti-patterns/long-method.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

doc/anti-patterns/long-parameter-list.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

doc/metrics/cyclomatic-complexity.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)