How to get the most value from Dart static analysis

Last update: May 20, 2022

Pub

This package is deprecated.

Before it was deprecated, it was the way to get analysis options matching those used internally at Google. This was useful because it was a good starting point for which lints to enable.

Instead, please see package:lints which is the lint recommendation from the Dart team, or package:flutter_lints which extends that for Flutter. These are better than the Google lint set because they take into account the needs of all Dart users, not just Google engineers.

To migrate away from package:pedantic please see the instructions here.

GitHub

https://github.com/dart-lang/pedantic
Comments
  • 1. Omit type annotations for local variables make code harder to understand.

    The latest version of the 'default' google analyser settings emit the warning:

    Omit type annotations for local variables (omit_local_variables_types).

    In many cases this improves the readability of code by removing redundant information.

    e.g.

    var  i = 1;
    

    The removal of the type (int) here doesn't affect the codes readability as the type of i is obvious.

    There are however many cases where removing the type actually makes the code harder to read and for a human to do static analysis.

    e.g.

        var code = _extractCode(monetaryAmount, codeLength);
    

    There is no information on this line that tells a reader what type 'code' is. The lack of type information forces the reader to stop and check what type _extractCode returns.

    If you are analysing a class of some complexity, having to stop and check the type of numerous variables significantly slows down the process.

    In a world of auto completion the reduction of a type to 'var' provides little reduction in typing.

    The only other argument for reducing a type to 'var' is visual clutter. Reduction in visual clutter should focus on removing redundant information, in the examples given the information being removed is not redundant.

    I would suggest that the Omit type annotations warning should only be emitted when it is obvious what the type is.

    Reviewed by bsutton at 2019-12-21 22:49
  • 2. Provide an options file which includes `package:lints/recommended.yaml`

    Now that a Dart team-recommended set of lint rules has been published, I think it makes sense to think of pedantic as the layer on top of those rules which we value highly internally.

    (I know that that is not the actual situation; the pedantic rules are just completely separate, but in terms of analysis options files for users, I think it would be pragmatic to think of pedantic this way.)

    Only one analysis options file can be included into another; you cannot include a list of analysis options files. Perhaps you can some day, but there is some hashing out w.r.t. merging that needs doing, and it might not be a high priority item. In the meantime, the only way to include multiple analysis options files into your own is by daisy chaining them. package:lints/recommended.yaml includes package:lints/core.yaml, so you get the lint rules from each.

    It would be great for pedantic to provide a new analysis options file which includes package:lints/recommended.yaml. Something like package:pedantic/recommended.yaml. WDYT?

    Reviewed by srawlins at 2021-05-17 22:53
  • 3. Allow future.unawaited aside unawaited(future)

    future.unawaited vs. unawaited(future) is a matter of taste :) . Both could silent unawaited_futures. What do you think of adding the following extension?

    extension FutureExt<T> on Future<T> {
      void get unawaited {}
    }
    
    Reviewed by a14n at 2021-03-10 21:43
  • 4. migrate to null safety

    ~I am not sure what the unawaited_futures lint would do with a Future? type. If it triggers we may want to allow Future<void>? as the argument here.~

    I went ahead and made the api nullable, at least with the current lint implementation it does trigger and I think it makes sense to.

    I also added an example since I needed to do that to test the lint behavior anyways.

    Reviewed by jakemac53 at 2020-04-10 15:14
  • 5. consider bumping pedantic by major versions when adding a lint

    I've seen CIs for several projects break after the release of the latest package:pedantic - v1.6.0.

    In the readme for this project, I see:

    This example uses a pinned version because every added lint rule could break a build for projects using it.

    You might consider either

    • making this more explicit - only recommend that consumers use specific versions, or pin to narrow ranges (>=1.5.0 <1.6.0).
    • or, only make pedantic more restrictive - adding more rules - on upgrades to major versions. That would allow projects to use deps like ^1.0.0 and adjust to new versions of pedantic at a more leisurely pace. That would probably also follow the guidance of semver more closely.
    Reviewed by devoncarew at 2019-05-06 21:51
  • 6. Unable to use 1.9.0 on Flutter stable 1.12.13+hotfix.5

    Because every version of flutter_test from sdk depends on pedantic 1.8.0+1 and beyond depends on pedantic ^1.9.0, flutter_test from sdk is forbidden.
    
    So, because beyond depends on flutter_test any from sdk, version solving failed.
    pub get failed (1; So, because beyond depends on flutter_test any from sdk, version solving failed.
    

    Is this intentional? We need to wait until the Flutter test SDK uses 1.9.0 before we can use it in our projects?

    Reviewed by MisterJimson at 2020-01-06 15:28
  • 7. Bump SDK constraints for pub

    Use a 2.12.0 lower bound since pub does not understand allowed experiments for earlier versions.

    Use a 3.0.0 upper bound to avoid a warning in pub and to give some flexibility in publishing for stable.

    Reviewed by natebosch at 2020-11-03 20:18
  • 8. make unawaited a generic function

    I just recently hit a snag using unawaited that I believe could have been avoided were it generic.

    Thoughts? Reservations?

    /cc @davidmorgan @bwilkerson

    Reviewed by pq at 2020-09-17 20:13
  • 9. unawaited with void return

    The unawaited check doesn't flag calls to async methods which return plain void rather than Future<void>, ie:

    void main() async {
      try {
        doThing(); // No unawaited error here
      } catch (e) {
        print("caught $e");
      }
    }
    
    // Returns void instead of Future<void>
    void doThing() async {
      await Future.delayed(Duration(seconds: 1));
      throw Exception("oops");
    }
    

    I'm not really clear on the semantics of returning void instead of Future from doThing(). IIRC the compiler used to always require returning a Future from async methods and at some point changed to allow just void, but that still seems to function as an awaitable future.

    In the example above, awaiting doThing() results in the exception being caught while not awaiting does not.

    Seems like this should be flagged?

    Reviewed by jklint-g at 2019-09-17 21:16
  • 10. sort_constructors_first shows improper suggestions in Flutter

    const ValueSlider(
          {Key key,
          @required this.onChanged,
          @required this.labels,
          @required this.values,
          @required this.type,
          this.status = AttendanceStatus.none})
          : super(key: key);
    

    this is caught by the linter even though Flutter puts Key first by default.

    Reviewed by ThinkDigitalSoftware at 2019-07-05 15:32
  • 11. Who lints the lints?

    Vague title, but I couldn't resist it sorry.

    Here's my situation: I want to use pedantic but I've also got quite a few extra lints that I want enabled. Some of those will almost certainly be included in pedantic itself at some point. Since the point of pedantic is to adhere to Google's standard, the lints I add are useful as a point of difference. However, nothing guarantees that they are a point of difference.

    What's the guidance in this situation? It would be nice to know that if my lint configuration becomes redundant at some point (due to a newer pedantic release) that I would be notified, but it seems that this is not the case (I just tried adding a lint that pedantic has already enabled). Is my only recourse to manually pick through the lints I have enabled and see whether they're redundant? Seems finicky.

    Reviewed by kentcb at 2019-05-28 02:41

Related

A fast, extra light and synchronous key-value storage to Get framework
A fast, extra light and synchronous key-value storage to Get framework

get_storage A fast, extra light and synchronous key-value in memory, which backs up data to disk at each operation. It is written entirely in Dart and

May 14, 2022
Get or set persistent storage value based on MMKV framework.

mmkv_flutter Plugin that allow Flutter to read value from persistent storage or save value to persistent storage based on MMKV framework Getting Start

Jan 17, 2022
Apr 7, 2022
soTired is an application for cognitive fatigue assessment. It includes a stand-alone Android app for fatigue detection and an additional part for data management and further analysis.
soTired is an application for cognitive fatigue assessment. It includes a stand-alone Android app for fatigue detection and an additional part for data management and further analysis.

Motivation soTired is an application for cognitive fatigue assessment. It includes a stand-alone Android app for fatigue detection and an additional p

Oct 22, 2021
Customizable heat map interface analysis library
Customizable heat map interface analysis library

Round Spot Customizable heat map interface analysis library Round Spot simplifies the UI accessibility and behaviour analysis for Flutter applications

May 16, 2022
Dart library for creating static trees of execution.

Processing tree Dart library for building and executing static trees of execution created in runtime. When to use it The main idea behind usage of thi

Dec 20, 2021
Superpowers for Dart. Collection of useful static extension methods.

If you miss an extension, please open an issue or pull request Resources: Documentation Pub Package GitHub Repository On this page you can find some o

May 17, 2022
A most easily usable Duolingo API wrapper in Dart. Duolingo4D is an open-sourced Dart library.

A most easily usable Duolingo API wrapper in Dart! 1. About Duolingo4D Duolingo4D is an open-sourced Dart library. With Duolingo4D, you can easily int

Mar 1, 2022
Lightweight and blazing fast key-value database written in pure Dart.
Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

May 17, 2022
Lightweight and blazing fast key-value database written in pure Dart.
Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

May 23, 2022
A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.
A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Simplify Equality Comparisons Overview Being able to compare objects in Dart often involves having to override the == operator as well as hashCode. No

May 17, 2022
A Flutter widget to create an iOS settings-table (static TableView).
A Flutter widget to create an iOS settings-table (static TableView).

flutter_cupertino_settings A Flutter widget to create an iOS settings-table (static TableView). import 'package:flutter_cupertino_settings/flutter_cup

May 6, 2022
Flutter plugin for creating static & dynamic app shortcuts on the home screen.
Flutter plugin for creating static & dynamic app shortcuts on the home screen.

Flutter Shortcuts Show some ❤️ and ⭐ the repo Why use Flutter Shortcuts? Flutter Shortcuts Plugin is known for : Flutter Shortcuts Fast, performant &

Apr 27, 2022
Flutter plugin for creating static & dynamic app shortcuts on the home screen.
Flutter plugin for creating static & dynamic app shortcuts on the home screen.

Flutter Shortcuts Compatibility ✅ Android ❌ iOS (active issue: iOS support for quick actions) Show some ❤️ and ⭐ the repo Why use Flutter Shortcuts? F

Apr 27, 2022
The read-a-book app is using static data. the application I developed has a homepage and detail page

book_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 this

Nov 12, 2021
A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)

flutter_html A Flutter widget for rendering HTML and CSS as Flutter widgets. Screenshot 1 Screenshot 2 Screenshot 3 Table of Contents: Installing Curr

May 23, 2022
Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.
Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

body_detection A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmen

Apr 26, 2022
Feb 13, 2022