Skip to content

dart-common-toolkit/dart-enum-to-string-check

Repository files navigation

ATTENTION

Because last Dart version supports name parameter this plugin is recommended to use on old Dart revisions. Right now repository is not in Archive because plugin have some bugs that can be fixed in future. After all checks and fully compatible understanding, repository can be placed to Archive.

dart_enum_to_string_check

GitHubActions Coverage pub.dev

About

Plugin for Dart Analyzer to check enum.toString() usages.

Motivation

Default enum.toString() method represents an enum constant as class name + constant name (for example, when we call color.toString() we have Colors.green but not green). In some cases this cast is not valid for an app logic (parse values to DB or JSON and vice versa) and can causing some problems (when from DB you get a strings without class names, "green" == Colors.green.toString() is not as we need). Plugin helps to prevent described problem.

How to use

From Dart Analyzer Server

Add plugin as development dependency in pubspec.yml:

dev_dependencies:
  dart_enum_to_string_check: ^0.8.3

Add plugin to analysis_options.yaml:

analyzer:
  plugins:
    - dart_enum_to_string_check

Then restart Dart Analyzer Server.

From CLI

With pub

To get dart_enum_to_string_check from pub run:

$ dart pub global activate dart_enum_to_string_check

Then run from project folder:

$ dart_enum_to_string_check

Without pub

Download plugin to your machine and provide bin/ location to PATH. Then run from project folder:

$ dart dart_enum_to_string_check.dart

References

Solutions from dart-code-metrics by Wrike:

How to contribute

Read Commit Convention. Make sure your build is green before you contribute your pull request. Then:

$ dart analyze
$ dart test

If you don't see any error messages, submit your pull request.

Contributors