lint 0.3.2+dart205

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

Lint for Dart/Flutter #

Pub

lint is a hand-picked, open-source, community-driven collection of lint rules for Dart and Flutter projects. The set of rules follows the Effective Dart: Style Guide.

This package can be used as a replacement for package:pedantic for those who prefer stricter rules.

Install #

Add lint as dependency to your pubspec.yaml

dev_dependencies:
  lint: ^0.3.0

Create a analysis_options.yaml file in the root of your project and import the lint rules:

include: package:lint/analysis_options.yaml

If you're writing a package with a public API you should use the package version instead

include: package:lint/analysis_options_package.yaml

Enable/Disable rules #

lint is customizable, you can add or remove rules, depending on your needs. To do so adjust your analysis_options.yaml.

include: package:lint/analysis_options.yaml

linter:
  rules:
    # ------ Disable individual rules ----- #
    #                 ---                   #
    # Turn off what you don't like.         #
    # ------------------------------------- #

    # Use parameter order as in json response
    always_put_required_named_parameters_first: false
    
    # Util classes are awesome!
    avoid_classes_with_only_static_members: false


    # ------ Enable individual rules ------ #
    #                 ---                   #
    # These rules here are good but too     #
    # opinionated to enable them by default #
    # ------------------------------------- #

    # Make constructors the first thing in every class
    sort_constructors_first: true

    # The new tabs vs. spaces. Choose wisely
    prefer_single_quotes: true
    prefer_double_quotes: true

    # Good packages document everything
    public_member_api_docs: true
    
    # Blindly follow the Flutter code style, which prefers types everywhere
    always_specify_types: true
  
    # Back to the 80s
    lines_longer_than_80_chars: true

Comparison to package:pedantic #

Google publicly shares their internal rules as package:pedantic in open-source. It represents what Google is enforcing internally throughout all Dart code. For a lint rule to be added to pedantic, Google has to change all code which doesn't follow the style.

This strict practice results in only 27/150+ rules to be enabled. While some are contradictory to each other and can not enabled together, a big chunk of rules isn't enabled because it requires too much work to update all of Googles existing code.

For developers outside Google, it is the norm to have separate lint rules per project. One project might enable more rules then others.

lint enables a majority of lint rules, leaving out contradictory and very opinionated rules.

License #

Copyright 2019 Pascal Welsch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Changlog #

0.3.1 #

0.3.0 #

  • Disable one_member_abstracts #2
  • Disable sort_constructors_first #1

New version schema:

  • 0.3.0+dart202: Dart 2.2 Release sdk: '>=2.2.0 <2.3.0'
  • 0.3.0+dart203: Dart 2.3 Release sdk: '>=2.3.0 <2.4.0'
  • 0.3.0+dart204: Dart 2.4 Release sdk: '>=2.4.0 <2.5.0'
  • 0.3.0+dart205: Dart 2.5 Release sdk: '>=2.5.0 <3.0.0'

0.2.3 #

  • Release for Dart 2.5 enables
    • avoid_print

0.2.2 #

  • Release for Dart 2.4 enables
    • prefer_if_null_operators
    • sort_child_properties_last
    • unsafe_html

0.2.1 #

  • Release for Dart 2.3 enables
    • prefer_for_elements_to_map_fromIterable
    • prefer_if_elements_to_conditional_expressions
    • prefer_inlined_adds
    • prefer_spread_collections

0.2.0 #

  • Fix analysis_options_package.yaml (wrong import)
  • Release for Dart 2.2. All incompatible rules are removed

0.1.1 #

  • pubspec.yaml homepage fix

0.1.0 #

  • app rule set analysis_options_package.yaml
  • package rule set analysis_options_package.yaml

example/README.md

Add lint as dependency to your pubspec.yaml

dev_dependencies:
  lint: ^0.3.0

Add a analysis_options.yaml to the root of you project.

include: package:lint/analysis_options.yaml

# Not happy with the default? Customize the rules depending on your needs. 
# Here are some examples:
linter:
  rules:
    # Make constructors the first thing in every class
    sort_constructors_first: true

    # The new tabs vs. spaces. Choose wisely
    prefer_single_quotes: true
    prefer_double_quotes: true

    # Good packages document everything
    public_member_api_docs: true

    # Blindly follow the Flutter code style, which prefers types everywhere
    always_specify_types: true

    # Back to the 80s
    lines_longer_than_80_chars: true

    # Use parameter order as in json response
    always_put_required_named_parameters_first: false

    # Util classes are awesome!
    avoid_classes_with_only_static_members: false

Hit save and see the dartanalyzer executing the lint checks in you favorite editor.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  lint: ^0.3.2+dart205

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

Popularity:
Describes how popular the package is relative to other packages. [more]
63
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

We analyzed this package on Oct 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0