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

feat: exclude .freezed.dart files by default #1139

Merged
merged 2 commits into from
Jan 8, 2023
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 @@ -2,6 +2,7 @@

## Unreleased

* feat: exclude `.freezed.dart` files by default.
* fix: handle try and switch statements for [`use-setstate-synchronously`](https://dartcodemetrics.dev/docs/rules/flutter/use-setstate-synchronously)
* chore: restrict `analyzer` version to `>=5.1.0 <5.4.0`.

Expand Down
4 changes: 3 additions & 1 deletion lib/src/analyzers/lint_analyzer/lint_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,7 @@ class LintAnalyzer {
}

bool _isSupported(FileResult result) =>
result.path.endsWith('.dart') && !result.path.endsWith('.g.dart');
result.path.endsWith('.dart') &&
!result.path.endsWith('.g.dart') &&
!result.path.endsWith('.freezed.dart');
}
4 changes: 2 additions & 2 deletions lib/src/cli/commands/base_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ abstract class BaseCommand extends Command<void> {
argParser.addOption(
FlagNames.exclude,
help: 'File paths in Glob syntax to be exclude.',
valueHelp: '{/**.g.dart,/**.template.dart}',
defaultsTo: '{/**.g.dart,/**.template.dart}',
valueHelp: '{/**.g.dart,/**.freezed.dart}',
defaultsTo: '{/**.g.dart,/**.freezed.dart}',
);
}

Expand Down
60 changes: 30 additions & 30 deletions test/src/cli/commands/analyze_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@ import 'package:test/test.dart';
const _usage = 'Collect code metrics, rules and anti-patterns violations.\n'
'\n'
'Usage: metrics analyze [arguments] <directories>\n'
'-h, --help Print this usage information.\n'
'-h, --help Print this usage information.\n'
'\n'
'\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), console-verbose, checkstyle, codeclimate, github, gitlab, html, json]\n'
'-o, --output-directory=<OUTPUT> Write HTML output to OUTPUT.\n'
' (defaults to "metrics")\n'
' --json-path=<path/to/file.json> Path to the JSON file with the output of the analysis.\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), console-verbose, checkstyle, codeclimate, github, gitlab, html, json]\n'
'-o, --output-directory=<OUTPUT> Write HTML output to OUTPUT.\n'
' (defaults to "metrics")\n'
' --json-path=<path/to/file.json> Path to the JSON file with the output of the analysis.\n'
'\n'
'\n'
' --cyclomatic-complexity=<20> Cyclomatic Complexity threshold.\n'
' --halstead-volume=<150> Halstead Volume threshold.\n'
' --lines-of-code=<100> Lines of Code threshold.\n'
' --maximum-nesting-level=<5> Maximum Nesting Level threshold.\n'
' --number-of-methods=<10> Number of Methods threshold.\n'
' --number-of-parameters=<4> Number of Parameters threshold.\n'
' --source-lines-of-code=<50> Source lines of Code threshold.\n'
' --weight-of-class=<0.33> Weight Of a Class threshold.\n'
' --maintainability-index=<50> Maintainability Index threshold.\n'
' --technical-debt=<0> Technical Debt threshold.\n'
' --cyclomatic-complexity=<20> Cyclomatic Complexity threshold.\n'
' --halstead-volume=<150> Halstead Volume threshold.\n'
' --lines-of-code=<100> Lines of Code threshold.\n'
' --maximum-nesting-level=<5> Maximum Nesting Level threshold.\n'
' --number-of-methods=<10> Number of Methods threshold.\n'
' --number-of-parameters=<4> Number of Parameters threshold.\n'
' --source-lines-of-code=<50> Source lines of Code threshold.\n'
' --weight-of-class=<0.33> Weight Of a Class threshold.\n'
' --maintainability-index=<50> Maintainability Index threshold.\n'
' --technical-debt=<0> Technical Debt threshold.\n'
'\n'
'\n'
'-c, --print-config Print resolved config.\n'
'-c, --print-config Print resolved config.\n'
'\n'
'\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.template.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.template.dart}")\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.freezed.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.freezed.dart}")\n'
'\n'
'\n'
" --no-congratulate Don't show output even when there are no issues.\n"
" --no-congratulate Don't show output even when there are no issues.\n"
'\n'
'\n'
' --[no-]verbose Show verbose logs.\n'
' --[no-]verbose Show verbose logs.\n'
'\n'
'\n'
' --set-exit-on-violation-level=<warning> Set exit code 2 if code violations same or higher level than selected are detected.\n'
' [noted, warning, alarm]\n'
' --[no-]fatal-style Treat style level issues as fatal.\n'
' --[no-]fatal-performance Treat performance level issues as fatal.\n'
' --[no-]fatal-warnings Treat warning level issues as fatal.\n'
' (defaults to on)\n'
' --set-exit-on-violation-level=<warning> Set exit code 2 if code violations same or higher level than selected are detected.\n'
' [noted, warning, alarm]\n'
' --[no-]fatal-style Treat style level issues as fatal.\n'
' --[no-]fatal-performance Treat performance level issues as fatal.\n'
' --[no-]fatal-warnings Treat warning level issues as fatal.\n'
' (defaults to on)\n'
'\n'
'Run "metrics help" to see global options.';

Expand Down
28 changes: 14 additions & 14 deletions test/src/cli/commands/check_unnecessary_nullable_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ const _usage =
'Check unnecessary nullable parameters in functions, methods, constructors.\n'
'\n'
'Usage: metrics check-unnecessary-nullable [arguments] <directories>\n'
'-h, --help Print this usage information.\n'
'-h, --help Print this usage information.\n'
'\n'
'\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), json]\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), json]\n'
'\n'
'\n'
'-c, --print-config Print resolved config.\n'
'-c, --print-config Print resolved config.\n'
'\n'
'\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.template.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.template.dart}")\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.freezed.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.freezed.dart}")\n'
'\n'
'\n'
" --no-congratulate Don't show output even when there are no issues.\n"
" --no-congratulate Don't show output even when there are no issues.\n"
'\n'
'\n'
' --[no-]verbose Show verbose logs.\n'
' --[no-]verbose Show verbose logs.\n'
'\n'
'\n'
' --[no-]monorepo Treat all exported code with parameters as non-nullable by default.\n'
' --[no-]monorepo Treat all exported code with parameters as non-nullable by default.\n'
'\n'
'\n'
' --[no-]fatal-found Treat found unnecessary nullable parameters as fatal.\n'
' (defaults to on)\n'
' --[no-]fatal-found Treat found unnecessary nullable parameters as fatal.\n'
' (defaults to on)\n'
'\n'
'Run "metrics help" to see global options.';

Expand Down
28 changes: 14 additions & 14 deletions test/src/cli/commands/check_unused_code_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ import 'package:test/test.dart';
const _usage = 'Check unused code in *.dart files.\n'
'\n'
'Usage: metrics check-unused-code [arguments] <directories>\n'
'-h, --help Print this usage information.\n'
'-h, --help Print this usage information.\n'
'\n'
'\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), json]\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), json]\n'
'\n'
'\n'
'-c, --print-config Print resolved config.\n'
'-c, --print-config Print resolved config.\n'
'\n'
'\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.template.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.template.dart}")\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.freezed.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.freezed.dart}")\n'
'\n'
'\n'
" --no-congratulate Don't show output even when there are no issues.\n"
" --no-congratulate Don't show output even when there are no issues.\n"
'\n'
'\n'
' --[no-]verbose Show verbose logs.\n'
' --[no-]verbose Show verbose logs.\n'
'\n'
'\n'
' --[no-]monorepo Treat all exported code as unused by default.\n'
' --[no-]monorepo Treat all exported code as unused by default.\n'
'\n'
'\n'
' --[no-]fatal-unused Treat find unused code as fatal.\n'
' (defaults to on)\n'
' --[no-]fatal-unused Treat find unused code as fatal.\n'
' (defaults to on)\n'
'\n'
'Run "metrics help" to see global options.';

Expand Down
30 changes: 15 additions & 15 deletions test/src/cli/commands/check_unused_files_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ import 'package:test/test.dart';
const _usage = 'Check unused *.dart files.\n'
'\n'
'Usage: metrics check-unused-files [arguments] <directories>\n'
'-h, --help Print this usage information.\n'
'-h, --help Print this usage information.\n'
'\n'
'\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), json]\n'
'-r, --reporter=<console> The format of the output of the analysis.\n'
' [console (default), json]\n'
'\n'
'\n'
'-c, --print-config Print resolved config.\n'
'-c, --print-config Print resolved config.\n'
'\n'
'\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.template.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.template.dart}")\n'
' --root-folder=<./> Root folder.\n'
' (defaults to current directory)\n'
' --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.\n'
' --exclude=<{/**.g.dart,/**.freezed.dart}> File paths in Glob syntax to be exclude.\n'
' (defaults to "{/**.g.dart,/**.freezed.dart}")\n'
'\n'
'\n'
" --no-congratulate Don't show output even when there are no issues.\n"
" --no-congratulate Don't show output even when there are no issues.\n"
'\n'
'\n'
' --[no-]verbose Show verbose logs.\n'
' --[no-]verbose Show verbose logs.\n'
'\n'
'\n'
' --[no-]monorepo Treat all exported files as unused by default.\n'
' --[no-]monorepo Treat all exported files as unused by default.\n'
'\n'
'\n'
' --[no-]fatal-unused Treat find unused file as fatal.\n'
' (defaults to on)\n'
' --[no-]fatal-unused Treat find unused file as fatal.\n'
' (defaults to on)\n'
'\n'
'\n'
'-d, --[no-]delete-files Delete all unused files.\n'
'-d, --[no-]delete-files Delete all unused files.\n'
'\n'
'Run "metrics help" to see global options.';

Expand Down
Loading