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?
Linter for DartThe Dart Linter package defines lint rules that identify and report on "lints" found in Dart code. Linting is performed by the Dart analysis server and the dart analyze command in the Dart command-line tool.
A linter is great for identifying errors when you use standard rules. Remember, a linter analyzes your code for stylistic and programming errors against the rules it knows. If part of your code breaks the standard rules, this can pose a problem.
Linting is the process of checking the source code for Programmatic as well as Stylistic errors and unformatted code. It's helpful in identifying some common and uncommon mistakes that are made during coding like logical errors, unused variables, empty if-else statements among others.
Dart is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can also be used to build server and desktop applications. It is an object-oriented, class-based, garbage-collected language with C-style syntax.
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
There is an open issue you can star to vote for adding the feature to Dart Editor:
https://code.google.com/p/dart/issues/detail?id=2059
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With