What’s new in DCM 1.27.0
Today we’re excited to announce the release of DCM 1.27.0!
This release includes 4 new rules, new built-in presets, reworked metrics console reporter, support for disabling ignore comments for particular rules, closed beta for DCM Dashboards, and more! 🚀
Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)
DCM Dashboards (Closed Beta)
We’re thrilled to share that DCM Dashboards are now available in a closed beta!
DCM Dashboards is a new part of our product (available as a new separate page in DCM Teams Console) that will help you get a clear view of all open issues (from lint rules and code quality commands) and metrics, and how the numbers change over time.
Learn more about the dashboard in our latest announcement.
New Built-in Presets
All rule tags are now available as built-in presets (for example, async
, collections
). This means you can easily include sets of rules by referencing these presets in your analysis_options.yaml
.
dart_code_metrics:
extends:
- async
- collections
Check out our Rules pages to see all tags available.
Support for Disabling Ignore Comments per Rule
The analyze
command now supports disabling ignore comments for a particular rule. This is helpful if you want to ensure certain critical rules are always enforced, even if someone added an ignore
comment in the code.
To disable ignore comments for a particular rule, set ignorable
:
dart_code_metrics:
rules:
- newline-before-return:
ignorable: false
Preview Improvements
-
New
recommended
tag. We added a dedicated tag for recommended rules, making it simpler to discover rules that are generally beneficial across a wide range of projects. -
More flexible empty violations output. The
--empty-violations
and--no-empty-violations
flags let you filter the preview results based on whether they return issues or not.
Check out the command's documentation page if you are not familiar with dcm init preview
.
Reworked Metrics Console Reporter
This update brings significant enhancements to the console reporter when running dcm calculate-metrics
.
One of the improvements is the console reporter which now displays each metric violation separately and show the threshold used to calculate the violation level.
There are more so that you can check in our changelog.
New Rules
Common
prefer-redirecting-superclass-constructor. Suggests using redirecting constructors when extending a superclass, making code more reliable and reducing duplication.
void fn() {
// LINT: Prefer using the redirecting constructor declared in the superclass.
LoadEvent();
// LINT: Prefer using the redirecting constructor declared in the superclass.
Intermediate.named();
}
sealed class MarksEvent {
const factory MarksEvent.load() = LoadEvent;
const factory MarksEvent.something() = Intermediate.named;
}
final class Intermediate implements MarksEvent {
Intermediate();
const Intermediate.named();
}
final class LoadEvent implements Intermediate {
const LoadEvent();
}
prefer-expect-later. Warns when a Future is passed to expect without it being awaited.
Not awaiting a Future passed to expect can lead to unexpected results. Replacing it with expectLater
will show a warning for a not awaited Future.
Future<void> main() async {
// LINT: Prefer using 'expectLater' with Futures.
expect(Future.value(1), 1);
}
avoid-nested-try-statements. Warns when multiple try
blocks are nested directly within each other. Consider refactoring your code to reduce nesting complexity.
For example:
try {
// ...
try {
// ...
// LINT: Avoid nested try statements. Try rewriting the code to remove nesting.
try {
throw Error();
} catch (_) {}
} catch (_) {}
} catch (_) {}
This rules come with configuration to define preferred acceptable level:
dart_code_metrics:
rules:
- avoid-nested-try-statements:
acceptable-level: 2
The acceptable-level
by default is 2.
avoid-unnecessary-block. Suggests removing unnecessary blocks ({ ... }
). Blocks that do not introduce a variable that shadows an existing variable are usually unnecessary. Consider removing such blocks to reduce code nesting.
void fn() {
// LINT: Avoid unnecessary code block. Try removing this block to reduce nesting.
{
print('hi');
}
}
What’s next
To learn more about upcoming features, keep an eye on our public roadmap. We have exciting plans to expand the DCM Dashboards beta, introduce additional rule configuration options, and continue improving the performance of all DCM commands.
And to learn more about our upcoming videos and "Rules of the Week" content, subscribe to our Youtube Channel.
Sharing your feedback
If there is something you miss from DCM right now, want us to make something better, or have any general feedback — join our Discord server! We’d love to hear from you.