Skip to main content

What’s new in DCM 1.6.0

· 6 min read

Cover

Today we’re excited to announce the release of DCM 1.6.0! New Individuals version, customizable formatter with project-wide configuration 😱, complete rewrite of IntelliJ plugin, new rules and more! 🚀

Let’s go on a quick journey together to explore all the new features!

New Individuals version (based on the Teams version)

Today we're announcing a new paid Individuals version that is based on the Teams version codebase, but has fewer features.

The documentation for both versions is now also unified with features that are available only for the Teams version now having a special "Teams" label.

With the new Individuals version we're also announcing the beginning of the analyzer plugins based open source Individuals version sunset. Please read this dedicated blog post to learn more about the reasons behind this decision.

From now on, every new release will affect both versions.

Customizable formatter with project-wide config

An ability to customize the formatter line length and indentation-level is one of the most requested features for dart format and dart_style in particular (first, second).

We're excited to announce that DCM now provides a new command dcm format and the IDE integrations (formatting on save and by a command), allowing you to format your code with the global configuration listed in the analysis_options.yaml.

Here is the config example:

dart_code_metrics:
formatter:
indent: 2
line-length: 160

And here is how it works from the CLI:

For those of you who write Flutter widgets with extensions, the formatter supports an cascading-widget-extensions option, that helps you achieve a more readable way when it comes to extensions.

Here is an example of such formatting:

It's the first release of the configurable formatter and we're looking forward to your feedback on how it works and what else can be added to improve your overall experience with the formatting options we provide.

dcm fix support for Check Dependencies

Previously added Check Dependencies command that helps you check whether some dependencies in your projects are missing, under-promoted, over-promoted, or unused how has a fix available with the --type=dependencies option supported by dcm fix.

Note, that missing dependencies version resolution is not yet supported, so if you have missing dependencies that are no added to the pubspec file, the command will add them, but it's up to you to specify the correct version.

IntelliJ / AS plugin update

After getting several reports that our IntelliJ / AS plugin has some performance issues, we're happy to release the completely rewritten version (1.4.2) that has all of the problems solved!

If you have not yet updated to the latest version, we encourage you to update and try it out. 🚀

Improved FVM support

In the previous version release we announced general support for FVM and now it's time to support even more cases.

If you use fvm global, now DCM executable is capable of picking this version up with no need from you to explicitly set the SDK path!

Improved baseline

Along side with several bug fixes, DCM now provides a new code action to update the baseline for the focused file. It should help you update the baseline with less effort.

Note, that this action is visible only if you have the baseline file created.

New rules

Common

avoid-unnecessary-return. Helps you spot unnecessary return statements that can be removed without breaking the code.

For example,

void function() {
if (someCondition) {
...

return;
}
}

the return type of this function is void and it has only one statement which makes the return meaningless. It can be successfully removed with no side effects.

avoid-future-tostring. Warns when a Future is a target of the toString method or is used in an interpolation.

You may encounter this problem when working with Futures and error reporting or serialization, but calling toString on a Future is rarely the thing you actually needed.

For example,

void main() {
final myFuture = Future.value(1);

print(myFuture.toString());
}

if you run this code, the output will be Instance of '_Future<int>', but most likely you'd expect to see 1.

avoid-unassigned-late-fields. Warns when a late field is not assigned a value.

For example,

class Test {
late final field = 'string';

late int uninitializedField;

late int _privateLate;
}

here uninitializedField and _privateLate are not assigned a value which usually a sign of a mistake. This rule helps find cases like that.

prefer-test-matchers. Warns when the second argument of an expect or expectLater is not a subclass of a Matcher.

Even though matchers might require more code to write, they produce a more readable message when the test fails.

For example,

void main() {
final array = [1, 2, 3];

expect(array.length, 1);
expectLater(array.length, 1);
}

when it comes to arrays length, you might want to use hasLength matcher instead.

So the correct version is:

void main() {
final array = [1, 2, 3];

expect(array, hasLength(1));
expectLater(array, hasLength(1));
}

Intl

prefer-number-format. Warns when int, num or double values are formatted with toString instead of NumberFormat.format().

When it comes to internalization, countries might have their specific rules on how numbers are displayed. To be able to take this rules into account without learning them, it's preferable to use NumberFormat.format() when it comes to formatting the numbers.

For example,

void main() {
const int intValue = 5;

final intString = intValue.toString();
}

the correct version is to call NumberFormat().format(intValue); instead to get the locale-aware output.

Other rules that got updates

Rules below got several updates (including bug fixes, new options and new use-cases supported):

  • avoid-shadowing
  • member-ordering
  • collection-methods-with-unrelated-types
  • prefer-return-await
  • prefer-multi-bloc-provider
  • avoid-redundant-else
  • avoid-self-assignment
  • function-always-returns-null
  • avoid-watch-outside-build
  • avoid-unrelated-type-assertions
  • dispose-fields
  • list-all-equatable-fields
  • arguments-ordering

What’s next

More quick fixes. With all the new rules introduced in DCM it's time to revisit them and add quick fixes where appropriate!

Bringing the unused code check to the next level. What if the unused code check was available not only as a command, but was also integrated into the IDE providing real-time info on the unused parts? Let’s find out how this will change the overall experience.

Move performance improvements. We received a several reports about DCM performance issues on very large codebase. This is a serious problems that we also want to address. There is still some room to make DCM better.

New commands. Reworking metric HTML reports unblocked other commands that need an HTML report as well. We hope to add them in the upcoming release to make DCM cover even more use-cases.

Sharing your feedback

If there is something you miss from DCM right now or want us to make something better or have any general feedback - join our Discord server!