dart-code-metrics
dart-code-metrics copied to clipboard
[Feature] Support `// ignore:` for metrics
- Dart code metrics version: 4.16.0
- Dart sdk version: >=2.17.0 <3.0.0
Please show your full configuration:
Configuration
include: package:lint/analysis_options.yaml
analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
exclude:
- "lib/generated/**"
- "lib/generated_*"
- "lib/i18n/messages_*.dart"
- "**/*.freezed.dart"
- "**/*.g.dart"
- "**/*.graphql.dart"
plugins:
- dart_code_metrics
dart_code_metrics:
anti-patterns:
- long-method
metrics:
cyclomatic-complexity: 20
lines-of-executable-code: 50
number-of-parameters: 6
maximum-nesting-level: 5
source-lines-of-code: 40
metrics-exclude:
- test/**
rules:
- avoid-unused-parameters
- newline-before-return
- no-boolean-literal-compare
- no-equal-then-else
- prefer-trailing-comma
- prefer-conditional-expressions
# flutter
- always-remove-listener
- avoid-returning-widgets
- avoid-unnecessary-setstate
- avoid-wrapping-in-padding
- prefer-extracting-callbacks
rules-exclude:
- "**/*.freezed.dart"
- "**/*.g.dart"
linter:
rules:
depend_on_referenced_packages: false
What did you do? Please include the source code example causing the issue.
extension GoRouterStateExt on GoRouterState {
// ignore: number-of-parameters
GoRouterState copyWith(
GoRouteInformationParser delegate, {
String? location,
String? subloc,
String? name,
String? path,
String? fullpath,
Map<String, String>? params,
Map<String, String>? queryParams,
Object? extra,
Exception? error,
ValueKey<String>? pageKey,
}) =>
GoRouterState(
delegate,
location: location ?? this.location,
subloc: subloc ?? this.subloc,
name: name ?? this.name,
path: path ?? this.path,
fullpath: fullpath ?? this.fullpath,
params: params ?? this.params,
queryParams: queryParams ?? this.queryParams,
extra: extra ?? this.extra,
error: error ?? this.error,
pageKey: pageKey ?? this.pageKey,
);
}
What did you expect to happen? Dart code metrics should ignore the issue
What actually happened?
Dart code metrics does not ignore the issue

Are you willing to submit a pull request to fix this bug? not for now
Checked the code and partial metric ignores are not supported at all. You can only ignore the whole file with the metrics-exclude: option. Could you add more details, why you need to ignore a specific metric in the report?
Hi. Thanks for response. I do not understand your question basically) There could be a different bunch of cases when I want to ignore something) I just tried to use what specified in documentation
I just tried to use what specified in documentation
Could you provide a link?
There could be a different bunch of cases when I want to ignore something)
Would be great to know why metrics-exclude: doesn't work for you? Also, why not to change the configuration for metrics instead of ignoring the report? Looks like you want to ignore since you don't want to fix this particular report.
https://dartcodemetrics.dev/docs/getting-started/configuration#ignoring-a-rule-or-anti-pattern
Would be great to know why metrics-exclude: doesn't work for you?
Cause I want to exclude only one particular place
https://dartcodemetrics.dev/docs/getting-started/configuration#ignoring-a-rule-or-anti-pattern
It doesn't say anything about ignoring metrics
sorry) my typo
anyway I still can't ignore particular place
i would like to add my vote for adding this feature.
yes, i could exclude the whole file to get around a specific warning, but that is not ideal. it might be only one function in a source file that has a problem, while i would prefer that all the remaining functions continue to get checked.
the other reason why it would be preferable to have partial excludes is because excluding a whole file effectively means that i have to maintain this preference in two places. suppose i edit the offending function so that it no longer violates the code metrics rules. if there was an exclusion comment right above it, i would for sure remember to remove that comment as well. but will i remember to go look at the analysis file to remove this file from the exclude list? doubtful!
if this feature doesn't get added, how about another one: give me an exception to the cyclomatic complexity rules to exclude switch statements. it is ridiculous for the analyzer to complain about a switch statement that has, say, 50 items. there is no realistic way to reduce that, if you've got an enum that legitimately has 50 separate items.
Sounds interested. I'll start implement this feature.
hey, great! seemed like an obvious addition, to me. heh
Any updates on this feature?
Nope, not yet
it will be very good.
I can ignore in this way:
// ignore: prefer-match-file-name, e.g.
Available in Teams 1.3.0