linter icon indicating copy to clipboard operation
linter copied to clipboard

A less stringent always_specify_types

Open uldall opened this issue 5 years ago • 1 comments

In our Flutter project we have enabled always_specify_types since we prefer type annotations in general.

This linter rule is however a bit too verbose in our opinion.

Specifically the rule enforces:

  • Requires types on calling contructors/methods: ChangeNotifierProvider<MyModel>
  • Requires types on collection/array initialization: <ChangeNotifierProvider<dynamic>>[]
  • Conflicts with avoid_types_on_closure_parameters

The following code:

void main() => runApp(
      MultiProvider(
        providers: <ChangeNotifierProvider<dynamic>>[
          ChangeNotifierProvider<MyModel>(
              builder: (BuildContext context) => MyModel()),
        ],
        child: MainApp(),
      ),
    );

Would be nicer as:

void main() => runApp(
      MultiProvider(
        providers: [
          ChangeNotifierProvider(
              builder: (context) => MyModel()),
        ],
        child: MainApp(),
      ),
    );

It would be nice if there was a less stringent version of always_specify_types that only enforces types on variables, method parameters and class members.

uldall avatar Jun 20 '19 08:06 uldall

We also like always_specify_types because we too prefer the clarity of type annotations. But like @uldall mentions, the current lint rule always_specify_types is indeed a bit over verbose in the above examples, a less verbose lint rule as suggested would offer the perfect balance.

rydmike avatar Feb 02 '21 02:02 rydmike