ATTENTION

dart_enum_to_string_check

GitHubActions Coverage pub.dev

About

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

Motivation

Default Enum.toString() method represents an enum constant as class name + constant name (example: Colors.green but not green). In some cases this cast is not valid for a program 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 needed). 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 name 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 from the shell:

Dart

pub global activate dart_enum_to_string_check

Flutter

flutter pub global activate dart_enum_to_string_check

Then run from project folder:

Dart

dart_enum_to_string_check

Flutter

flutter pub global run 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