Skip to content

Should prefer_collection_literals take SDK version into account? #57941

Closed
@jamesderlin

Description

@jamesderlin

My pubspec.yaml has:

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

Using dartanalyzer version 2.2.1-edge.a8f3a5dae6203d1064726a5953cf06a7d484249c against the following code triggers:

final mySet = Set<String>();

lint • Use collection literals when possible at ... • prefer_collection_literals

But if I change the code to:

final mySet = <String>{};

then I get:

hint • Set literals were not supported until version 2.2, but this code is required to be able to run on earlier versions at ... • sdk_version_set_literal

So I can't win. I could add // ignore: prefer_collection_literals, but then I won't get the lint when I do upgrade the minimum SDK version.

Should the prefer_collection_literals lint should take the minimum SDK version into account to restrict "when possible"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestdevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.linter-false-positivelinter-set-recommendedtype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions