Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Effective Dart

Effective Dart


- What is Effective Dart?
- Guides
- Project Setup
- Customization & Control


Birju Vachhani

March 25, 2021



  2. HELLO! I am Birju Vachhani I am here because I

    love clean code. You can find me on Twitter at @birjuvachhani 2
  3. AGENDA 3 ∎ What is Effective Dart? ∎ Guides ∎

    Project Setup ∎ Customization & Control
  4. WHAT IS EFFECTIVE DART? 4 A set of rules and

    guidelines derived and learned from code written over the past several years.
  5. • To Be Consistent: If two pieces of code look

    different it should be because they are different in some meaningful way. • To Be Brief: If there are multiple ways to say something, you should generally pick the most concise one. 5 WHY?
  6. EXAMPLE 6 prefer_collection_literals

  7. GUIDES 7 • Style Guide: For laying out and organizing

    code. • Documentation Guide: For doc comments and regular comments. • Usage Guide: For using language features in best way to implement behavior. • Design Guide: For designing consistent, usable APIs for libraries.
  8. constant_identifier_names 8 STYLE GUIDE EXAMPLE OF Constants are often changed

    to final non-const variables, which would necessitate a name change.
  9. slash_for_doc_comments 9 DOCUMENTATION GUIDE EXAMPLE OF The /// syntax is

    also easier to read in some situations, such as when a doc comment contains a bulleted list that uses * to mark list items.
  10. prefer_is_empty 10 USAGE GUIDE EXAMPLE OF When testing whether an

    iterable or map is empty, prefer isNotEmpty over !isEmpty to improve code readability.
  11. omit_local_variable_types 11 DESIGN GUIDE EXAMPLE OF Omitting the type focuses

    the reader’s attention on the more important name of the variable and its initialized value.
  12. PROJECT SETUP & CUSTOMIZATION Let’s see how we can enable

    analyzer and linter to use effective_dart for our project and customize it. 12
  13. ADD DEPENDENCY Add effective_dart under your dev_dependencies section in pubspec.yaml.

    13 STEP 1
  14. CREATE CONFIGURATION Create configuration file analysis_options.yaml in the root of

    the project. 14 STEP 2
  15. EXCLUDE FILES To avoid unrelated warnings, you can exclude files

    which you don’t want analyzer to analyze. e.g. auto-generated code/files. 15 STEP 3
  16. CUSTOMIZING LINT RULES Rules are organized into familiar rule groups:

    errors, style and pub. Rules can be selectively enabled in the analyzer using analysis options or through an analysis options file. 16
  17. ENABLE / DISABLE RULES As some lints may contradict each

    other, only a subset of these will be enabled in practice. Some rules may be marked experimental to indicate that they are under review. 17 DART LINT
  18. RULES IN ACTION If the rule is enabled, linter shows

    warning when the rule is broken like this one. 18 DART LINT public_member_api_docs
  19. CHANGING SEVERITY Customizing rules is fine, but could you change

    the severity of the rule? Let’s see how... 19 TAKING CONTROL
  20. CHANGING SEVERITY Severity can be defined under errors section and

    can be error, warning, info or ignore. This way you’re in control of what is considered error or warning by dart analyzer. 20 TAKING CONTROL
  21. THAT’S ALL YOU NEED TO KNOW Don’t forget to keep

    an eye on Dart Analysis section in your Android Studio. It can save you a lot of trouble! 21
  22. THANKS! Any questions? You can find me on Twitter at

    @birjuvachhani or mail me on brvachhani@gmail.com 22
  23. REFERENCES ➔ Effective Dart https://dart.dev/guides/language/effective-dart ➔ Linter for Dart https://dart-lang.github.io/linter/lints/

    ➔ Customizing Static Analysis https://dart.dev/guides/language/analysis-options 23