regen readme
1 file changed
tree: 2b01b038073fdf26391888a96f65932ce76fdc77
  1. .github/
  2. example/
  3. lib/
  4. tool/
  5. .gitignore
  6. CHANGELOG.md
  7. LICENSE
  8. pubspec.yaml
  9. README.md
README.md

Build Status pub package package publisher

Official Dart lint rules

The Dart linter is a static analyzer for identifying possible problems in your Dart source code. More than a hundred linter rules are available, checking anything from potential typing issues, coding style, and formatting. This package - package:lints - contains the lint settings recommended by the Dart team.

Lint sets

This package includes two sets of lints:

  • Core lints: Lints that help identify critical issues that are likely to lead to problems when running or consuming Dart code. All code should pass these lints.

  • Recommended lints: Lints that help identify additional issues that may lead to problems when running or consuming Dart code, and lints that enforce writing Dart using a single, idiomatic style and format. All code is encouraged to pass these lints. The recommended lints include all the core lints.

Additionally, a third lint set - package:flutter_lints - extends the recommended set with additional recommended Flutter-specific lints.

The Dart team will likely not provide recommendations past the core and recommended sets (e.g., a strict rule set). However, there are many such rule sets in the ecosystem (available at pub.dev).

Rule set authors: consider adding the lints topic to your pubspec to allow easier discovery (e.g., pub.dev/packages?q=topic:lints). For more information about topics, see dart.dev/tools/pub/pubspec#topics.

Where these lints are used

When creating new Dart project using the dart create command, the lints from package:lints are enabled by default.

When uploading a package to the pub.dev package repository, packages are awarded pub points based on how many of the ‘core’ lints pass.

Enabling the lints

For new apps created with dart create the recommended set of lints are enabled by default.

For existing apps or packages, you can enable these lints via:

  1. In a terminal, located at the root of your package, run this command:

    dart pub add --dev lints
    
  2. Create a new analysis_options.yaml file, next to the pubspec, that includes the lints package:

    include: package:lints/recommended.yaml
    

    or:

    include: package:lints/core.yaml
    

Customizing the predefined lint sets

For details on customizing static analysis above and beyond the predefined lint sets, see customizing static analysis.

Evolving the lint sets

The Dart language changes and the ecosystem continues to develop new best practices, so the lint sets must be periodically updated to reflect the best way we know to write Dart code. The process we use is:

  1. Anyone can file an issue to discuss a potential change to a lint set (i.e., adding or removing a lint from one or both sets; if you're proposing an entirely new lint, the place to suggest that is at the linter repo). Feedback is welcome from any Dart user.

  2. Periodically, a group of Dart and Flutter team members meet to review the suggestions and decide what to adopt.

  3. The lists are updated and a new version of the package is published.

Lint set contents

Core lints

To use these lints create an analysis_options.yaml file with: include: package:lints/core.yaml.

Lint RulesDescription
avoid_empty_elseAvoid empty else statements.
avoid_relative_lib_importsAvoid relative imports for files in lib/.
avoid_shadowing_type_parametersAvoid shadowing type parameters.
avoid_types_as_parameter_namesAvoid types as parameter names.
await_only_futuresAwait only futures.
camel_case_extensionsName extensions using UpperCamelCase.
camel_case_typesName types using UpperCamelCase.
collection_methods_unrelated_typeInvocation of various collection methods with arguments of unrelated types.
curly_braces_in_flow_control_structuresDO use curly braces for all flow control structures.
depend_on_referenced_packagesDepend on referenced packages.
empty_catchesAvoid empty catch blocks.
file_namesName source files using lowercase_with_underscores.
hash_and_equalsAlways override hashCode if overriding ==.
no_duplicate_case_valuesDon't use more than one case with same value.
non_constant_identifier_namesName non-constant identifiers using lowerCamelCase.
null_check_on_nullable_type_parameterDon't use null check on a potentially nullable type parameter.
package_prefixed_library_namesPrefix library names with the package name and a dot-separated path.
prefer_generic_function_type_aliasesPrefer generic function type aliases.
prefer_is_emptyUse isEmpty for Iterables and Maps.
prefer_is_not_emptyUse isNotEmpty for Iterables and Maps.
prefer_iterable_whereTypePrefer to use whereType on iterable.
prefer_typing_uninitialized_variablesPrefer typing uninitialized variables and fields.
provide_deprecation_messageProvide a deprecation message, via @Deprecated(“message”).
unnecessary_overridesDon't override a method to do a super method invocation with the same parameters.
unrelated_type_equality_checksEquality operator == invocation with references of unrelated types.
valid_regexpsUse valid regular expression syntax.
void_checksDon't assign to void.

Recommended lints

To use these lints create an analysis_options.yaml file with: include: package:lints/recommended.yaml.

Lint RulesDescription
annotate_overridesAnnotate overridden members.
avoid_function_literals_in_foreach_callsAvoid using forEach with a function literal.
avoid_init_to_nullDon't explicitly initialize variables to null.
avoid_null_checks_in_equality_operatorsDon't check for null in custom == operators.
avoid_renaming_method_parametersDon't rename parameters of overridden methods.
avoid_return_types_on_settersAvoid return types on setters.
avoid_returning_null_for_voidAvoid returning null for void.
avoid_single_cascade_in_expression_statementsAvoid single cascade in expression statements.
constant_identifier_namesPrefer using lowerCamelCase for constant names.
control_flow_in_finallyAvoid control flow in finally blocks.
empty_constructor_bodiesUse ; instead of {} for empty constructor bodies.
empty_statementsAvoid empty statements.
exhaustive_casesDefine case clauses for all constants in enum-like classes.
implementation_importsDon't import implementation files from another package.
library_namesName libraries using lowercase_with_underscores.
library_prefixesUse lowercase_with_underscores when specifying a library prefix.
library_private_types_in_public_apiAvoid using private types in public APIs.
no_leading_underscores_for_library_prefixesAvoid leading underscores for library prefixes.
no_leading_underscores_for_local_identifiersAvoid leading underscores for local identifiers.
null_closuresDo not pass null as an argument where a closure is expected.
overridden_fieldsDon't override fields.
package_namesUse lowercase_with_underscores for package names.
prefer_adjacent_string_concatenationUse adjacent strings to concatenate string literals.
prefer_collection_literalsUse collection literals when possible.
prefer_conditional_assignmentPrefer using ??= over testing for null.
prefer_containsUse contains for List and String instances.
prefer_equal_for_default_valuesUse = to separate a named parameter from its default value.
prefer_final_fieldsPrivate field could be final.
prefer_for_elements_to_map_fromIterablePrefer ‘for’ elements when building maps from iterables.
prefer_function_declarations_over_variablesUse a function declaration to bind a function to a name.
prefer_if_null_operatorsPrefer using if null operators.
prefer_initializing_formalsUse initializing formals when possible.
prefer_inlined_addsInline list item declarations where possible.
prefer_interpolation_to_compose_stringsUse interpolation to compose strings and values.
prefer_is_not_operatorPrefer is! operator.
prefer_null_aware_operatorsPrefer using null aware operators.
prefer_spread_collectionsUse spread collections when possible.
prefer_void_to_nullDon‘t use the Null type, unless you are positive that you don’t want void.
recursive_gettersProperty getter recursively returns itself.
slash_for_doc_commentsPrefer using /// for doc comments.
type_init_formalsDon't type annotate initializing formals.
unnecessary_brace_in_string_interpsAvoid using braces in interpolation when not needed.
unnecessary_constAvoid const keyword.
unnecessary_constructor_nameUnnecessary .new constructor name.
unnecessary_getters_settersAvoid wrapping fields in getters and setters just to be “safe”.
unnecessary_lateDon't specify the late modifier when it is not needed.
unnecessary_newUnnecessary new keyword.
unnecessary_null_aware_assignmentsAvoid null in null-aware assignment.
unnecessary_null_in_if_null_operatorsAvoid using null in if null operators.
unnecessary_nullable_for_final_variable_declarationsUse a non-nullable type for a final variable initialized with a non-nullable value.
unnecessary_string_escapesRemove unnecessary backslashes in strings.
unnecessary_string_interpolationsUnnecessary string interpolation.
unnecessary_thisDon't access members with this unless avoiding shadowing.
use_function_type_syntax_for_parametersUse generic function type syntax for parameters.
use_rethrow_when_possibleUse rethrow to rethrow a caught exception.