-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Should prefer_collection_literals take SDK version into account? #57941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
IMO, yes, it should. |
I've been thinking about this a bit. @bwilkerson: would this be a reasonable approach: @override
void registerNodeProcessors(NodeLintRegistry registry,
[LinterContext context]) {
final versionConstraint = context?.analysisOptions?.sdkVersionConstraint;
if (versionConstraint != null && before_2_2_0.intersect(versionConstraint).isEmpty) {
return;
}
final visitor = new _Visitor(this);
registry.addInstanceCreationExpression(this, visitor);
registry.addMethodInvocation(this, visitor);
} where, taking the cue from analyzer, VersionRange get before_2_2_0 =>
new VersionRange(max: Version.parse('2.2.0'), includeMax: false); If it is, I can generalize a bit and propose something concrete. (We'll want to do similarly for UI-as-code features short term and new experiments moving forward.) |
I'm not sure what the effect is when a lint rule doesn't register. It probably effectively disables it, which is what I think you're going for. @stereotype441 is planning a re-design of the sdk version checking support, so we might want to wait for that work to be done. |
Yes. If the visitors don't get registered, the lint will never get reported. @stereotype441: is the re-design something you have in mind for soon? And will it be API? |
I've been thinking about this a bunch over the last few days and though I have a prototype working that would solve the immediate problem, I'm more and more convinced that we should probably sit tight until the language versioning conversation shakes out (see, e.g., dart-lang/language#311). Ideally a good approach here will shake out of that and minimally we'll need to be compatible. Thanks for your patience! |
See also the conversation in #58394. |
Since language versions before this syntax existed aren’t supported anymore, I’m going to close this in favor of #36677 and other similar issues. They discuss a generic way to handle language versions in lints. I do think the situation is much better today now that language versioning does exist. |
My pubspec.yaml has:
Using dartanalyzer version 2.2.1-edge.a8f3a5dae6203d1064726a5953cf06a7d484249c against the following code triggers:
But if I change the code to:
then I get:
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"?The text was updated successfully, but these errors were encountered: