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

Effective Dart

Effective Dart

Agenda:

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

Birju Vachhani

March 25, 2021
Tweet

More Decks by Birju Vachhani

Other Decks in Programming

Transcript

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

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

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

    guidelines derived and learned from code written over the past several years.
  4. • 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?
  5. 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.
  6. constant_identifier_names 8 STYLE GUIDE EXAMPLE OF Constants are often changed

    to final non-const variables, which would necessitate a name change.
  7. 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.
  8. 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.
  9. 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.
  10. PROJECT SETUP & CUSTOMIZATION Let’s see how we can enable

    analyzer and linter to use effective_dart for our project and customize it. 12
  11. 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
  12. 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
  13. 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
  14. 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
  15. CHANGING SEVERITY Customizing rules is fine, but could you change

    the severity of the rule? Let’s see how... 19 TAKING CONTROL
  16. 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
  17. 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