Samuel Hapak Samuel Hapak - 3 months ago 12
Dart Question

Is there a lint tool to check the code against the Dart style guide?

I would like to write code that conforms to the Dart style guide. Therefore I am curios, whether there is any automatic way to check the coding style for Dart.

Do you know about any way to do this?

Answer

Since Dart 1.13 (currently release candidate) you can enable lint checks, strong mode and other features by adding an .analysis_options file to your Dart project (the folder with the pubspec.yaml file)

analyzer:
  strong-mode: true
  exclude:
  - test/data/**
  language:
    enableSuperMixins: true
linter:
  rules:
    # see http://dart-lang.github.io/linter/lints/
    - always_declare_return_types
    - always_specify_types
    - camel_case_types
    - constant_identifier_names
    - empty_constructor_bodies
    - implementation_imports
    - library_names
    - library_prefixes
    - non_constant_identifier_names
    - one_member_abstracts
    - package_api_docs
    - package_prefixed_library_names
    - slash_for_doc_comments
    - super_goes_last
    - type_init_formals
#    - unnecessary_brace_in_string_interp
    - unnecessary_getters_setters
    - package_names

The available lint rules are listed in http://dart-lang.github.io/linter/lints/

See also https://pub.dartlang.org/packages/linter

Comments