An opinionated, community-driven set of lint rules for Dart and Flutter projects. Like pedantic but stricter

Overview

Pub style: lint

Lint for Dart/Flutter

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:lints or the discontinued package:pedantic for those who prefer stricter rules.

lint tries to be strict but not annoying.

Install

Add lint as dependency to your pubspec.yaml. Version ^1.0.0 means you're automatically getting the latest version for lint when running pub upgrade

dev_dependencies:
  lint: ^1.0.0

Create an analysis_options.yaml file in the root of your project with the following content:

# This file configures the analyzer to use the lint rule set from `package:lint`

# For apps, use the default set
include: package:lint/analysis_options.yaml

# Packages, that may be distributed (i.e. via pub.dev) should use the package 
# version, resulting in a better pub score.
# include: package:lint/analysis_options_package.yaml

# You might want to exclude auto-generated files from dart analysis
analyzer:
  exclude:
    #- '**.freezed.dart'

# You can customize the lint rules set to your own liking. A list of all rules
# can be found at https://dart-lang.github.io/linter/lints/options/options.html
linter:
  rules:
    # Util classes are awesome!
    # avoid_classes_with_only_static_members: false
    
    # Make constructors the first thing in every class
    # sort_constructors_first: true

    # Choose wisely, but you don't have to
    # prefer_double_quotes: true
    # prefer_single_quotes: true

Lint badge

You're using lint in your open-source project? Add the badge to your README.md show that you honor strict lint rules

style: lint

[![style: lint](https://img.shields.io/badge/style-lint-4BC0F5.svg)](https://pub.dev/packages/lint)

Comparison with other lint packages

A detailed comparison of all linting packages for dart can be found at https://rydmike.com/blog_flutter_linting.html

lint is among the strictest but not the strictest. It tires to find the right balance between useful and annoying.

Comparison to discontinued 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.
Comments
  • invalid_assignment rule

    invalid_assignment rule

    Hello. I have tried several different ways to get the linter to ignore this error but am unsure what the correct answer is.

    "A value of type ‘{0}’ can’t be assigned to a variable of type ‘{1}’" I have tried:

       invalid_assignment: true
       invalid_assignment: false
       invalid_assignment: ignore
       invalid_assignment: warn
    
    

    Nothing seems to prevent this from being a compile error in my project except removing [lint: ^1.0.0] completely What am I doing wrong? What do I need to do to use?

    opened by Storch72 10
  • Suggestion: const can be left out in more ways than the lints allow

    Suggestion: const can be left out in more ways than the lints allow

    Nice linter! Really appreciate the explanation for every rule choice.

    According to some resources, const is in some cases optional. Meaning it gets added by the runtime and you do not gain any performance benefits by adding const. But I am not 100% sure, as in some cases it ensures that const is definitely used and thus has better performance.

    IMO I would leave const out, trust the DartVM to optimize most of it and for that **VERY expensive ** constructor I would leave it to the developer to add it in.

    This should clean up code in flutter a lot, since a lot of widgets can be const.

    Some resources:

    const is optional inside of a constant context.

    Dart2 Migration guide: https://dart.dev/dart-2

    In short, even without the keyword, we can still unambiguously recognize the expressions that create objects. In that sense, the keywords are superfluous.

    Similarly, it may be important for developers to ensure that certain expressions are constant, because of the improved performance and the guaranteed canonicalization.

    https://github.com/dart-lang/sdk/blob/master/docs/language/informal/implicit-creation.md

    Here are some very good examples on where it is optional:

    https://stackoverflow.com/questions/52581148/when-is-const-optional-in-dart-2

    opened by nstrelow 6
  • analysis_options_package.yaml cannot be found

    analysis_options_package.yaml cannot be found

    I am using VSCode and I added lint:^1.2.0 as a dev_dependencies.

    Now trying to import analysis_options_package.yaml as shown below breaks the flutter analyze.

    include: package:lint/analysis_options_package.yaml

    Following warning is raise by flutter analyze.

    warning - The include file package:lint/analysis_options_package.yaml in
           C:\my\local\path\to\analysis_options.yaml cannot be found -
           analysis_options.yaml:1:11 - include_file_not_found
    

    Should it be added to normal dependencies instead dev_dependecies? In my case that didn't help either. Not sure if I am missing any step.

    opened by Abhilash-Chandran 6
  • avoid_redundant_argument_values ?

    avoid_redundant_argument_values ?

    So I'm getting avoid_redundant_argument_values but this is how Flutter widgets work in the UI for example flutter crossAxisAlignment shouldn't this be removed from the lint to set to false by default

    opened by isAlmogK 5
  • Install instructions should specify to put package in dev_dependencies and not dependencies

    Install instructions should specify to put package in dev_dependencies and not dependencies

    In the pub.dev install section of this package it is written to insert the dependency under dependencies. As this dependency is not running while the software is running (as far as I know) it should be placed under dev_dependencies.

    image

    Is it ok to place it under dev_dependencies and if it does can we change it in the pub.dev install page for the incoming users?

    opened by guyluz11 4
  • Exclude {Key? key} from 'Put required named parameters first' rule

    Exclude {Key? key} from 'Put required named parameters first' rule

    Since Flutter source code full of {Key? key, required ...} constructors, it would be better excluding this specific case.

    Screen Shot 2021-08-31 at 10 22 36

    Flutter example:

    const Padding({
        Key? key,
        required this.padding,
        Widget? child,
      }) : assert(padding != null),
           super(key: key, child: child);
    
    opened by esenmx 3
  • Comments in the analysis_options.yaml file break customization

    Comments in the analysis_options.yaml file break customization

    I am creating this issue after my comment here: https://github.com/passsy/dart-lint/issues/3#issuecomment-571707108

    After further testing, I have discovered that the comment ins the analysis_options.yaml file break the possibility of customization. This may occur due to some YAML library parsing problems, maybe some undocumented handling of comment nodes, no idea.

    I have done the following to determine this:

    1. Try to use pedenatic package and extend the rules adding and disabling - this works - pedantic has no comments in their files
    2. Copy the analysis_options.yaml file of this library to a local project file - customization does not work
    3. Remove all comments form the local file - customization works
    opened by kuhnroyal 3
  • Broken linter around enum and import order

    Broken linter around enum and import order

    Hello,

    I didn't find the reason, but the linter got confused around my import for no special reason (no double enum / class with the same name) and i got the following behavior which is funny :

    Enum is type DownloadType (good) Capture d’écran 2022-04-19 à 10 52 00

    Enum instance variable is dynamic... Capture d’écran 2022-04-19 à 10 52 05

    When playing with import order this issue disappear but as I used this rule : directives_ordering I can't. If i remove the comma just after DownloadType downloadType, error disappear... So seems like parsing error from the linter.

    opened by EArminjon2 2
  • `avoid_slow_async_io` is disabled, but the comments suggest it should exist

    `avoid_slow_async_io` is disabled, but the comments suggest it should exist

    # Might cause frame drops because of synchronous file access on mobile, especially on older phones with slow storage.
    # There are no known measurements sync access does *not* drop frames.
    #
    # https://dart-lang.github.io/linter/lints/avoid_slow_async_io.html
    # - avoid_slow_async_io
    

    From the comments, I guess we should enable this rule?

    opened by fzyzcjy 2
  • The include file `analysis_options_package.yaml` cannot be found while developing a Flutter plugin

    The include file `analysis_options_package.yaml` cannot be found while developing a Flutter plugin

    While developing a Flutter plugin, after adding

    dev_dependencies:
      lint: 1.6.0
    

    I'm getting a warning indicating that the analysis_options file cannot be found.

    image

    warning: The include file package:lint/analysis_options_package.yaml in /my/local/path/to/analysis_options.yaml cannot be found. (include_file_not_found at [my_project] analysis_options.yaml:1)
    
    opened by cdmunoz 2
  • How to turn off

    How to turn off "The argument type 'dynamic' can't be assigned to the parameter type x"?

    I want to disable the lint: "The argument type 'dynamic' can't be assigned to the parameter type x" but I can't find it.

    Update I used this and the problem is solved!

    analyzer:
      strong-mode:
        implicit-casts: true
    
    opened by Hassanmsaid 2
  • Create a casual lint

    Create a casual lint

    For coding dojos, examples and quick prototypes a more relaxed set of rules would be great.

    For that kind of apps it's irrelevant if const or prints are added or not.

    opened by passsy 0
  • abstract class override fields

    abstract class override fields

    I think these 2 errors contradict each other

    lint: ^1.6.0

    abstract class IContent {
      final String? name;
      IContent({
        this.name,
      });
    }
    
    class Content extends IContent {
      // 2 conflicting errors
      // Annotate overridden members.dart(annotate_overrides)
      // Don't override fields.dart(overridden_fields)
      final String? name;
    }
    
    opened by hadukin 1
  • field initializer and argument type not assignable

    field initializer and argument type not assignable

    I got massive errors from the analyzer includes:

    • argument_type_not_assignable
    • field_initializer_not_assignable

    Most of them are from the Map<String, dynamic> json parsing to a model class.

    I tried to turn them off in the analysis_options.yaml, but it didn't help.

    opened by SeanZom 5
  • Enable unawaited_futures, ship fireAndForget

    Enable unawaited_futures, ship fireAndForget

    Enables unawaited_futures.

    Where Futures are intentionally not awaited, users can disable this lint with fireAndForget which exists as top-level function and extension. It is identical to unawaited from pedantic.

    Future<void> logAsync(String msg) async { /*...*/ }
    
    Future<void> someOperation() async {
      await doSomething();
    
      // Warning: `Future` results in `async` function bodies must be `await`ed or marked `unawaited` using `package:pedantic`.
      logAsync('success');
    
      // The fireAndForget() extensions signals that await is intentionally missing
      logAsync('success').fireAndForget();
    
      // The fireAndForget() function signals that await is intentionally missing
      fireAndForget(logAsync('success'));
    }
    

    I explicitly did not name it unawaited as it causes naming conflicts. That's the main reason why unawaited was removed from meta again.

    Fixes #26

    Alternative names

    • notAwaited
    • runInParallel
    • ignoreUnawaitedFuture
    opened by passsy 3
  • The lint invariant_booleans is confused inside a switch statement.

    The lint invariant_booleans is confused inside a switch statement.

    When using lint 1.5.1

    In the following switch statement there are two cases that both check if char = ' '.

    The lint incorrectly marks the second test as invariant_booleans as it sees the if char = ' ' in the first case and assume that the test protects the second case from having a space.

    If you change the first char = ' ' in the first case to anything else the warning goes away.

    The lint should not fire in this scenario.

    
     enum _ParseState { starting, inQuote, inWord }
    
      /// parses the given command breaking them done into words
    void _parse2(String commandLine) {
        var state = _ParseState.starting;
    
        for (var i = 0; i < commandLine.length; i++) {
          final char = commandLine[i];
    
          switch (state) {
            case _ParseState.starting:
              if (char == ' ') {
                break;
              }
              break;
    
            case _ParseState.inWord:
              if (char == ' ')
              {
                break;
              }
          }
        }
      }
    
    opened by bsutton 1
Releases(v1.10.0)
Owner
Pascal Welsch
Google Developer Expert for Flutter / CTO of phntm.xyz / Co-founder of @wiredashio / speaker / cat-lover
Pascal Welsch
Lint rules for Dart and Flutter used internally at NetGlade.

NetGlade Analysis Developed with ?? by NetGlade This package provides lint rules for Dart and Flutter which are used at NetGlade. Usage To use the lin

NetGlade 3 Dec 4, 2022
A flutter boilerplate project containing bloc, pedantic, hive, easy_translations and more!

Flutter Production Boilerplate A flutter project containing bloc, flutter_lints, hive, easy_translations and more! This repository is the starting poi

Andreas Feichtinger 133 Dec 26, 2022
Flying Fish is full-stack Dart framework - a semi-opinionated framework for building applications exclusively using Dart and Flutter

Flying Fish is full-stack Dart framework - a semi-opinionated framework for building applications exclusively using Dart and Flutter.

Flutter Fish 3 Dec 27, 2022
A community-driven hot deals sharing app developed with Flutter.

hotdeals-app hotdeals-app is an online marketplace app developed with Flutter. The app's Backend can be found here. Table of Contents Screenshots Feat

Halil İbrahim Durmuş 21 Jan 4, 2023
Actively maintained, community-driven Firebase BaaS for chat applications with an optional chat UI.

Flutter Firebase Chat Core Actively maintained, community-driven Firebase BaaS for chat applications with an optional chat UI. Flyer Chat is a platfor

Flyer Chat 173 Jan 2, 2023
This is an opinionated code-generation tool from GraphQL to Dart/Flutter.

GraphQL Codegen This is an opinionated code-generation tool from GraphQL to Dart/Flutter. It'll allow you to generate Dart serializers and client help

United Traders 1 Dec 29, 2021
LakhanKumawat ᵖ⁺ 12 Dec 6, 2022
🎨 An opinionated, effective and correct way to provide multiple themes to your app.

theming This is an opinionated and effective way to provide multi-theme choice for your app. theming depends on provider and shared_preference for sta

Chinyeaka Chinonso 3 Nov 28, 2022
Rules - Powerful and feature-rich validation library for both Dart and Flutter.

Introduction Rules - Powerful and feature-rich validation library for both Dart and Flutter. Rules is a simple yet powerful and feature-rich validatio

Ganesh Rathinavel 24 Dec 12, 2022
Linter rules corresponding to the guidelines in Effective Dart

effective_dart This package is deprecated. Before it was deprecated, it was the way to provide analysis options corresponding to the guidelines in Eff

Honza Bittner 127 Dec 9, 2022
This is a set of small projects focused solely on the development of the graphical interface with Flutter

My Flutter Projects Flutter apps with cool design and animations Social Media Youtube Facebook Twitter Getting Started This project is a starting poin

Kevin Melendez 500 Dec 19, 2022
Git+ is your ultimate GitLab mobile app that lets you interact with your projects like as if you were using desktop.

Git+ for GitLab Git+ is your ultimate GitLab mobile app that lets you interact with your projects like as if you were using desktop. Git+ lets you see

Marek Gvora 38 Jan 7, 2023
A mobile application that allows you to search and fetch recipes using Flutter, TheMealDB and Domain Driven Design

recipe_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Johnny Nguyen 0 Dec 4, 2021
COVID-19 application made with Flutter, following Test Driven Development (TDD) and Clean Architecture along with Internationalization with JSON.

Covid App COVID-19 application made with Flutter, following Test Driven Development (TDD) and Clean Architecture along with Internationalization with

Sandip Pramanik 4 Aug 4, 2022
This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

Tomas B Sarmiento Abella 1 Jan 5, 2022
Flutter Architecture inspired by Domain Driven Design, Onion and Clean Architecture

Inspiring Domain Driven Design Flutter Architecture Please take a look at my slides to learn more Strategic Domain Driven Design For Improving Flutter

Majid Hajian 324 Dec 25, 2022
This is an open source Tips & Tricks for Flutter, that helps flutter Developers write simple but powerful dart codes.

Showcasing-flutter - This is an open source Tips & Tricks for Flutter, that helps flutter Developers write simple but powerful dart codes.

Paul Edeme'kong - Flutter Fairy 1 Jan 4, 2022
Crypto Loss Gain Calculator App build with Flutter. It developed with DDD (Domain Driven Design) principles.

Crypto Loss Gain Calculator Crypto Loss Gain Calculator App build with Flutter. It developed with DDD (Domain Driven Design) principles. Domain-Driven

Selim Üstel 9 Dec 27, 2022
Flutter_ddd - Experimental Flutter project with Domain-Driven Design

flutter_ddd Notes app sample in Dart / Flutter with DDD. This is an outcome of my attempt to understand Domain-Driven Design and consider how I can in

Kabo 90 Dec 18, 2022