Skip to content
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

Make prefer_collection_literals less suggestive for LinkedHashMap and LinkedHashSet #57993

Closed
jamesderlin opened this issue Jul 15, 2019 · 20 comments
Assignees
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-set-recommended P3 A lower priority bug or feature request

Comments

@jamesderlin
Copy link
Contributor

I have code where insertion order is important, and even though Map's default implementation is a LinkedHashMap, I'd like to emphasize this in code by explicitly using LinkedHashMap:

final lruCache = LinkedHashMap<String, Stuff>();

This triggers the prefer_collection_literals lint.

I thought maybe I instead could do:

final LinkedHashMap<String, Stuff> lruCache = {};

but that runs afoul of --no-implicit-dynamic. I thought that I could give in and be redundant:

final LinkedHashMap<String, Stuff> lruCache = <String, Stuff>{};

but that doesn't work either:

error • A value of type 'Map<String, Stuff>' can't be assigned to a variable of type 'LinkedHashMap<String, Stuff>' at ... • invalid_assignment

So I think that there's no way for me to actually initialize a type declared as a LinkedHashMap while appeasing the linter.

I think that prefer_collection_literals should ignore LinkedHashMap (and LinkedHashSet). In #57905, @bwilkerson asked:

I'd like to drop the flagging of:

  1. LinkedHashSet constructors altogether, and

I'm not sure why. As I understand it, a set literal creates an instance of LinkedHashSet, so the two should be consistent.

I claim that if someone is explicitly using LinkedHashMap/LinkedHashSet instead of just Map or Set, then they care about being explicit. (And if we don't think that's important, then I'd argue that LinkedHashMap and LinkedHashSet shouldn't even exist as separate classes.)

@jamesderlin
Copy link
Contributor Author

I thought maybe I instead could do:

final LinkedHashMap<String, Stuff> lruCache = {};

but that runs afoul of --no-implicit-dynamic. I thought that I could give in and be redundant:

And that doesn't work because {} (a Map) isn't assignable to LinkedHashMap (the invalid_assignment error from the third attempt) and therefore the type isn't inferred.

So the fact that Map isn't assignable to LinkedHashMap suggests to me that the linter should not be suggesting that map literals replace a default construction of LinkedHashMap.

@bwilkerson
Copy link
Member

The situation is a bit strange, and I'm not sure what the right answer is here.

On the one hand, the specification states that a set or map literal will preserve the order in which the elements or entries appear in the code, so you're guaranteed to get exactly the behavior you're looking for without explicitly referencing LinkedHashMap or LinkedHashSet.

On the other hand, wanting to be explicit about the fact that the set or map preserves order seems perfectly reasonable.

Unfortunately, the specification only says that the static type of a set or map literal is either Set or Map, which means that we loose information that the type system could have used to help you.

It seems to me that we have two equally valid use cases:

  • a desire to use literals everywhere that doing so would not change the runtime semantics, and
  • a desire to use literals everywhere that doing so would not change the declared or inferred types of variables.

I expect that the tension we're running into here is from trying to make a single lint serve both use cases. The alternative is to have two lint rules, but that runs into the problem of making it harder for users to decide which rule is the one they want to use.

@pq
Copy link
Member

pq commented Jul 16, 2019

Thanks for the analysis Brian!

My gut is that the second use case is the most common:

  • a desire to use literals everywhere that doing so would not change the declared or inferred types of variables.

and that loosening this lint is a reasonable compromise.

If this frustrates users down the road we could consider the ultimate solution of 2 lints but I'm hoping it won't come to that...

WDYT?

@pq
Copy link
Member

pq commented Jul 16, 2019

FWIW: if we do poke this hole, I'd like to add a nice bit to the docs explaining the intent.

@natebosch
Copy link
Member

This lint is now included in package:pedantic which is widely used and the fact that {} is not assignable to a field which is statically a LinkedHashMap forces use to add // ignore comments.

Loosening this check should be a high priority.

natebosch referenced this issue in dart-archive/html Dec 10, 2019
- always_declare_return_types
- annotate_overrides
- omit_local_variable_types
- prefer_conditional_assignment
- prefer_if_null_operators
- prefer_single_quotes
- use_function_type_syntax_for_parameters

Ignore prefer_collection_literals lints since they would require
incorrect code where a `{}` (statically a `Map`) is assigned to a static
`LinkedHashMap`. See https://github.com/dart-lang/linter/issues/1649
@pq
Copy link
Member

pq commented Dec 10, 2019

Thanks @natebosch. I agree. I still lean towards adding the exception (with an explanatory doc). Unless there are any strong objections, I'll make the change.

@pq pq self-assigned this Dec 10, 2019
@pq
Copy link
Member

pq commented Dec 10, 2019

Looking a little at our tests, we do allow these cases:

  LinkedHashSet<int> ss6 = LinkedHashSet<int>(); // OK
  LinkedHashMap hashMap = LinkedHashMap(); // OK

Of course this then disagrees w/ omit_local_variable_types...

@pq
Copy link
Member

pq commented Dec 10, 2019

Thinking about this some more, I'm not convinced that

final lruCache = LinkedHashMap<String, Stuff>();

is sufficient to emphasize ordering. If I were to be reviewing that code, I'd probably ask for an explanatory comment. Of course in that case the explicit type is redundant.

I guess I'm now firmly back on the fence. 😬

@jamesderlin
Copy link
Contributor Author

Thinking about this some more, I'm not convinced that

final lruCache = LinkedHashMap<String, Stuff>();

is sufficient to emphasize ordering. If I were to be reviewing that code, I'd probably ask for an explanatory comment. Of course in that case the explicit type is redundant.

I guess I'm now firmly back on the fence. grimacing

I don't entirely agree. Using LinkedHashMap instead of Map should raise some suspicion in the reader. Possibly that suspicion doesn't convey intent, but it at least should give enough pause that discourages someone from haphazardly changing the type to HashMap.

Even with a comment, I think that using a Map warrants even more verbiage in the comments. For example, I would prefer:

// Ordering matters, so we must use a [LinkedHashMap].
final lruCache = LinkedHashMap<String, Stuff>();

instead of:

// Ordering matters, so we must use a [LinkedHashMap], which is the default [Map] implementation.
final lruCache = <String, Stuff>{};

natebosch referenced this issue in dart-archive/html Dec 11, 2019
- always_declare_return_types
- annotate_overrides
- omit_local_variable_types
- prefer_conditional_assignment
- prefer_if_null_operators
- prefer_single_quotes
- use_function_type_syntax_for_parameters

Ignore prefer_collection_literals lints since they would require
incorrect code where a `{}` (statically a `Map`) is assigned to a static
`LinkedHashMap`. See https://github.com/dart-lang/linter/issues/1649
@jamesderlin
Copy link
Contributor Author

jamesderlin commented Dec 12, 2019

Also, given that:

  LinkedHashSet<int> ss6 = LinkedHashSet<int>(); // OK
  LinkedHashMap hashMap = LinkedHashMap(); // OK

works, then I claim that:

  var ss6 = LinkedHashSet<int>();
  var hashMap = LinkedHashMap();

should work too, at least for consistency.

@natebosch
Copy link
Member

My primary concern right now is that the following code is impossible (AFAICT) to write while using this lint:

class Foo {
  LinkedHashMap m;
  void foo() {
    m = {}; // The map literal type 'Map<dynamic, dynamic>' isn't of expected type 'LinkedHashMap<dynamic, dynamic>'.
    m = LinkedHashMap(); // Use collection literals when possible.
  }
}

@dkwingsmt
Copy link

dkwingsmt commented Jul 10, 2020

This has brought some (visual) mess to the Flutter code as well, such as in flutter/flutter#61190 (comment).

The following code will report "invalid_assignment",

    final LinkedHashMap<MouseTrackerAnnotation, Matrix4> annotations = <MouseTrackerAnnotation, Matrix4>{};

The following code will report "prefer_collection_literals",

    final LinkedHashMap<MouseTrackerAnnotation, Matrix4> annotations =
        LinkedHashMap<MouseTrackerAnnotation, Matrix4>();

And this is what we ended up having to use, which is pretty clumsy,

    final LinkedHashMap<MouseTrackerAnnotation, Matrix4> annotations = <MouseTrackerAnnotation, Matrix4>{}
        as LinkedHashMap<MouseTrackerAnnotation, Matrix4>;

And it appears a lot.

I doubt if making "prefer_collection_literals" less suggestive will work, since the Flutter repo is pretty strict on lint errors. I would really hope that the literal {} is considered of type LinkedHashMap, so that the assignment is legal in the first place.

@bwilkerson
Copy link
Member

I would really hope that the literal {} is considered of type LinkedHashMap ...

The reason that it isn't is that the Dart Language Specification explicitly states that

The static type of a map literal of the form <K, V >e is Map<K, V >.

The fact that it's a LinkedHashMap in practice is an implementation detail that the implementors are free to change at will. Baking that implementation detail into the lint rule seems wrong.

There's probably a good reason for not doing so, but out of curiosity, have you considered writing

final Map<MouseTrackerAnnotation, Matrix4> annotations = {};

The specification also states that

A map is ordered: iteration over the keys, values, or key/value pairs occurs in the order in which the keys were added to the set.

So you don't need to give it a type of LinkedHashMap to ensure the ordered-ness of the map, and if you write it as above the type parameters will be inferred automatically, which reduces a lot of duplication. (I'm assuming you can't omit the type annotation because you're writing in the Flutter repo, but that would also be an alternative for some readers of this issue.)

@dkwingsmt
Copy link

The LinkedHashMap is used for a variable whose order matters, the same case as the issue owner's. I'm aware that the doc of Map says the default constructor gives an ordered map, but HashMap, which is unordered, also inherits Map, which means a Map parameter does not guarantee receiving an ordered map.

@natebosch
Copy link
Member

I doubt if making "prefer_collection_literals" less suggestive will work, since the Flutter repo is pretty strict on lint errors. I would really hope that the literal {} is considered of type LinkedHashMap, so that the assignment is legal in the first place.

With the change suggested in this issue you won't get a lint error. We won't make {} have a static type of LinkedHashMap since it would break a bunch of existing code which assigns a map literal and uses inference.

I'm not sure if the change requested here is difficult. @pq - is this something we can prioritize?

natebosch referenced this issue in dart-lang/linter Nov 7, 2020
Towards #1649

Allow using `LinkedHashSet` and `LinkedHashMap` for named arguments,
assignment to a variable, and when used in a binary expression where a
static type is pushed down to the arguments.

Refactor `_shouldSkipLinkedHashLint`. Extract a method to determine the
type that is enforced statically for the expression rather than
duplicate the subsequent check for each type of parent node.
@natebosch
Copy link
Member

dart-lang/linter#2340 should fix some of the false positives.

After that the only decision left will be whether to allow var s = LinkedHashSet() since the type is impacting inference in that case.

cbbraun referenced this issue in google/charts Mar 8, 2021
Use collection literals where possible.  Because a lot of this code
explicitly uses `LinkedHashMap` to indicate that order is important,
add appropriate `// ignore` comments until
https://github.com/dart-lang/linter/issues/1649 is addressed.

PiperOrigin-RevId: 360552809
cbbraun referenced this issue in google/charts Mar 9, 2021
Use collection literals where possible.  Because a lot of this code
explicitly uses `LinkedHashMap` to indicate that order is important,
add appropriate `// ignore` comments until
https://github.com/dart-lang/linter/issues/1649 is addressed.

PiperOrigin-RevId: 360552809
cbbraun referenced this issue in google/charts Mar 9, 2021
* Internal changes

PiperOrigin-RevId: 298455490

* Internal changes

PiperOrigin-RevId: 299212474

* Internal changes

PiperOrigin-RevId: 299384685

* Internal changes

PiperOrigin-RevId: 299911795

* Apply sort_child_properties_last lint so we can enable it in google3.

This enhances readability in *majority* of the cases by moving properties of a widget to the top. See: https://dart-lang.github.io/linter/lints/sort_child_properties_last.html

Tested:
    TAP --sample ran all affected tests and none failed
    http://test/OCL:300415528:BASE:300394685:1583970262840:214ae086
PiperOrigin-RevId: 300472053

* Internal changes

PiperOrigin-RevId: 300583916

* Internal changes

PiperOrigin-RevId: 301253904

* Internal changes

PiperOrigin-RevId: 301413179

* Correct the point location computation to be inside of scale's range if it is outside of scale range but only outside by less than epsilon in order to avoid potential mislocation caused by floating point computation.

PiperOrigin-RevId: 301644128

* Internal changes

PiperOrigin-RevId: 301919359

* Internal changes

PiperOrigin-RevId: 305070616

* Point renderer has now the option to select all points overlapping the interaction point

PiperOrigin-RevId: 306413187

* Internal Changes

PiperOrigin-RevId: 306960748

* Fix missing_return errors for anonymous closures.

These are mostly closures whose type dictates that a Future of something-or-other be returned. Fixes include:

* Make the closure async
* Add a return statement

Tested:
    TAP for global presubmit queue
    http://test/OCL:307493015:BASE:307542828:1587474095828:2c1a77e8
PiperOrigin-RevId: 308003343

* Internal change

PiperOrigin-RevId: 308058514

* Allow using up/down arrow keys to change the hovered bar in a chart. Also add preventDefault so the page doesn't scroll.

PiperOrigin-RevId: 308932972

* Internal change

PiperOrigin-RevId: 309073218

* Internal changes

PiperOrigin-RevId: 309494957

* Add TriangleSymbolRenderer

PiperOrigin-RevId: 310472091

* Expose additional classes

PiperOrigin-RevId: 310943783

* Change MaterialGray shade900 from blue to correct gray

PiperOrigin-RevId: 311587781

* Pass `DateTimeFactory` to `TimeSeriesChart`

PiperOrigin-RevId: 311764962

* Add setting to allow series to be always visible and unclickable in the chart legend.

PiperOrigin-RevId: 314159954

* Export additional classes

PiperOrigin-RevId: 314565994

* Add custom legend ordering by sorting the behaviors series list based on a list with ordered series IDs.

PiperOrigin-RevId: 315910283

* Add custom axis renderer for range ticks.

PiperOrigin-RevId: 315976899

* Internal changes.

PiperOrigin-RevId: 318221788

* Set datum index for legend entry

PiperOrigin-RevId: 319291348

* Internal changes

PiperOrigin-RevId: 322200941

* Internal changes

PiperOrigin-RevId: 322451897

* Internal changes.

PiperOrigin-RevId: 322661249

* Internal changes

PiperOrigin-RevId: 322671049

* Internal changes

PiperOrigin-RevId: 322827055

* Override setState fn with mounted check in baseChartState.

PiperOrigin-RevId: 325307554

* Internal changes

PiperOrigin-RevId: 326067746

* Internal changes

PiperOrigin-RevId: 328177790

* Internal changes

PiperOrigin-RevId: 331718263

* Internal changes

PiperOrigin-RevId: 331738992

* Internal changes

PiperOrigin-RevId: 331765706

* Automated g4 rollback of changelist 331765706.

*** Reason for rollback ***

Manually rolled back on behalf of: oreflow.
Reason Given: This CL auto rolled back a rollback. Rolling forward to a broken revision

*** Original change description ***

Automated g4 rollback of changelist 331738992.

*** Reason for rollback ***

TAP has detected 10 or more targets failed to build at cl/331738992.

TO ROLLFORWARD (without additional approval): Use go/undo-autorollback and consider filing a go/autorollback-bug.

To see all broken targets visit http://test/331738992 or go/newly-broken?p=cl:331738992 if the former is slow to load.
To prevent noise from flakes, TAP double-checked the following target fails to build:
https://sponge.corp.google.com/in...

***

PiperOrigin-RevId: 331767278

* Internal changes

PiperOrigin-RevId: 336974207

* Internal changes

PiperOrigin-RevId: 337212864

* Test-only change to prepare for new Flutter version

PiperOrigin-RevId: 339319134

* Internal changes

PiperOrigin-RevId: 340251505

* Internal changes

PiperOrigin-RevId: 340463455

* Internal changes

PiperOrigin-RevId: 340658840

* Internal changes

PiperOrigin-RevId: 342347503

* Internal changes

PiperOrigin-RevId: 345724352

* Internal changes

PiperOrigin-RevId: 347872889

* Internal changes

PiperOrigin-RevId: 350249482

* Clean up violations of Dart lint unnecessary_parenthesis

In preparation for null safety migration, I'm first fixing numerous
analysis complaints in the hope that it will make the migration go a
little bit more smoothly.

Remove unnecessary parentheses.

PiperOrigin-RevId: 360550907

* Clean up violations of Dart lint annotate_overrides

Add missing `@override` annotations.  This caught a bug where
`hashCode` was not overridden as intended because it was accidentally
mistyped as `hashcode`.

PiperOrigin-RevId: 360551084

* Clean up violations of Dart lint unnecessary_getters_setters

Replace trivial getters and setters with fields.

PiperOrigin-RevId: 360551490

* Clean up violations of Dart lint prefer_collection_literals

Use collection literals where possible.  Because a lot of this code
explicitly uses `LinkedHashMap` to indicate that order is important,
add appropriate `// ignore` comments until
https://github.com/dart-lang/linter/issues/1649 is addressed.

PiperOrigin-RevId: 360552809

* Clean up less trivial violations of miscellaneous Dart lints

* prefer_null_aware_operators
* hash_and_equals
* only_throw_errors
* avoid_bool_literals_in_conditional_expressions

Also replace usage of the deprecated zero-argument `List`
constructor.

PiperOrigin-RevId: 360552940

* Clean up trivial violations of miscellaneous Dart lints

* unnecessary_this
* prefer_final_fields
* avoid_single_cascade_in_expression_statements
* avoid_renaming_method_parameters

Also:
* Remove unused variables.
* Fix some cases where fields were implicitly `dynamic` because their
  type was omitted.
PiperOrigin-RevId: 360553040

* bump intl version to 0.18.0

intl: ">=0.15.2 < 0.18.0"

Closes #598

PiperOrigin-RevId: 361636495

* Internal changes

PiperOrigin-RevId: 361680107

Co-authored-by: nolankelly <nolankelly@google.com>
Co-authored-by: Googler <noreply@google.com>
Co-authored-by: mehmetf <mehmetf@google.com>
Co-authored-by: srawlins <srawlins@google.com>
Co-authored-by: rearnshaw <rearnshaw@google.com>
Co-authored-by: jiamingc <jiamingc@google.com>
Co-authored-by: jamesdlin <jamesdlin@google.com>
Co-authored-by: Artyom Sasin <artyom.sasin@gmail.com>
Co-authored-by: lorrainekan <lorrainekan@google.com>
@ghost
Copy link

ghost commented May 10, 2021

final orderedMap = LinkedHashMap.of(<String, String>{});

doesn't trigger this rule, and orderedMap type is LinkedHashMap<String, String>. That's I need.

jananitakumitech referenced this issue in jananitakumitech/charts_flutter Aug 13, 2021
* Internal changes

PiperOrigin-RevId: 298455490

* Internal changes

PiperOrigin-RevId: 299212474

* Internal changes

PiperOrigin-RevId: 299384685

* Internal changes

PiperOrigin-RevId: 299911795

* Apply sort_child_properties_last lint so we can enable it in google3.

This enhances readability in *majority* of the cases by moving properties of a widget to the top. See: https://dart-lang.github.io/linter/lints/sort_child_properties_last.html

Tested:
    TAP --sample ran all affected tests and none failed
    http://test/OCL:300415528:BASE:300394685:1583970262840:214ae086
PiperOrigin-RevId: 300472053

* Internal changes

PiperOrigin-RevId: 300583916

* Internal changes

PiperOrigin-RevId: 301253904

* Internal changes

PiperOrigin-RevId: 301413179

* Correct the point location computation to be inside of scale's range if it is outside of scale range but only outside by less than epsilon in order to avoid potential mislocation caused by floating point computation.

PiperOrigin-RevId: 301644128

* Internal changes

PiperOrigin-RevId: 301919359

* Internal changes

PiperOrigin-RevId: 305070616

* Point renderer has now the option to select all points overlapping the interaction point

PiperOrigin-RevId: 306413187

* Internal Changes

PiperOrigin-RevId: 306960748

* Fix missing_return errors for anonymous closures.

These are mostly closures whose type dictates that a Future of something-or-other be returned. Fixes include:

* Make the closure async
* Add a return statement

Tested:
    TAP for global presubmit queue
    http://test/OCL:307493015:BASE:307542828:1587474095828:2c1a77e8
PiperOrigin-RevId: 308003343

* Internal change

PiperOrigin-RevId: 308058514

* Allow using up/down arrow keys to change the hovered bar in a chart. Also add preventDefault so the page doesn't scroll.

PiperOrigin-RevId: 308932972

* Internal change

PiperOrigin-RevId: 309073218

* Internal changes

PiperOrigin-RevId: 309494957

* Add TriangleSymbolRenderer

PiperOrigin-RevId: 310472091

* Expose additional classes

PiperOrigin-RevId: 310943783

* Change MaterialGray shade900 from blue to correct gray

PiperOrigin-RevId: 311587781

* Pass `DateTimeFactory` to `TimeSeriesChart`

PiperOrigin-RevId: 311764962

* Add setting to allow series to be always visible and unclickable in the chart legend.

PiperOrigin-RevId: 314159954

* Export additional classes

PiperOrigin-RevId: 314565994

* Add custom legend ordering by sorting the behaviors series list based on a list with ordered series IDs.

PiperOrigin-RevId: 315910283

* Add custom axis renderer for range ticks.

PiperOrigin-RevId: 315976899

* Internal changes.

PiperOrigin-RevId: 318221788

* Set datum index for legend entry

PiperOrigin-RevId: 319291348

* Internal changes

PiperOrigin-RevId: 322200941

* Internal changes

PiperOrigin-RevId: 322451897

* Internal changes.

PiperOrigin-RevId: 322661249

* Internal changes

PiperOrigin-RevId: 322671049

* Internal changes

PiperOrigin-RevId: 322827055

* Override setState fn with mounted check in baseChartState.

PiperOrigin-RevId: 325307554

* Internal changes

PiperOrigin-RevId: 326067746

* Internal changes

PiperOrigin-RevId: 328177790

* Internal changes

PiperOrigin-RevId: 331718263

* Internal changes

PiperOrigin-RevId: 331738992

* Internal changes

PiperOrigin-RevId: 331765706

* Automated g4 rollback of changelist 331765706.

*** Reason for rollback ***

Manually rolled back on behalf of: oreflow.
Reason Given: This CL auto rolled back a rollback. Rolling forward to a broken revision

*** Original change description ***

Automated g4 rollback of changelist 331738992.

*** Reason for rollback ***

TAP has detected 10 or more targets failed to build at cl/331738992.

TO ROLLFORWARD (without additional approval): Use go/undo-autorollback and consider filing a go/autorollback-bug.

To see all broken targets visit http://test/331738992 or go/newly-broken?p=cl:331738992 if the former is slow to load.
To prevent noise from flakes, TAP double-checked the following target fails to build:
https://sponge.corp.google.com/in...

***

PiperOrigin-RevId: 331767278

* Internal changes

PiperOrigin-RevId: 336974207

* Internal changes

PiperOrigin-RevId: 337212864

* Test-only change to prepare for new Flutter version

PiperOrigin-RevId: 339319134

* Internal changes

PiperOrigin-RevId: 340251505

* Internal changes

PiperOrigin-RevId: 340463455

* Internal changes

PiperOrigin-RevId: 340658840

* Internal changes

PiperOrigin-RevId: 342347503

* Internal changes

PiperOrigin-RevId: 345724352

* Internal changes

PiperOrigin-RevId: 347872889

* Internal changes

PiperOrigin-RevId: 350249482

* Clean up violations of Dart lint unnecessary_parenthesis

In preparation for null safety migration, I'm first fixing numerous
analysis complaints in the hope that it will make the migration go a
little bit more smoothly.

Remove unnecessary parentheses.

PiperOrigin-RevId: 360550907

* Clean up violations of Dart lint annotate_overrides

Add missing `@override` annotations.  This caught a bug where
`hashCode` was not overridden as intended because it was accidentally
mistyped as `hashcode`.

PiperOrigin-RevId: 360551084

* Clean up violations of Dart lint unnecessary_getters_setters

Replace trivial getters and setters with fields.

PiperOrigin-RevId: 360551490

* Clean up violations of Dart lint prefer_collection_literals

Use collection literals where possible.  Because a lot of this code
explicitly uses `LinkedHashMap` to indicate that order is important,
add appropriate `// ignore` comments until
https://github.com/dart-lang/linter/issues/1649 is addressed.

PiperOrigin-RevId: 360552809

* Clean up less trivial violations of miscellaneous Dart lints

* prefer_null_aware_operators
* hash_and_equals
* only_throw_errors
* avoid_bool_literals_in_conditional_expressions

Also replace usage of the deprecated zero-argument `List`
constructor.

PiperOrigin-RevId: 360552940

* Clean up trivial violations of miscellaneous Dart lints

* unnecessary_this
* prefer_final_fields
* avoid_single_cascade_in_expression_statements
* avoid_renaming_method_parameters

Also:
* Remove unused variables.
* Fix some cases where fields were implicitly `dynamic` because their
  type was omitted.
PiperOrigin-RevId: 360553040

* bump intl version to 0.18.0

intl: ">=0.15.2 < 0.18.0"

Closes google/charts#598

PiperOrigin-RevId: 361636495

* Internal changes

PiperOrigin-RevId: 361680107

Co-authored-by: nolankelly <nolankelly@google.com>
Co-authored-by: Googler <noreply@google.com>
Co-authored-by: mehmetf <mehmetf@google.com>
Co-authored-by: srawlins <srawlins@google.com>
Co-authored-by: rearnshaw <rearnshaw@google.com>
Co-authored-by: jiamingc <jiamingc@google.com>
Co-authored-by: jamesdlin <jamesdlin@google.com>
Co-authored-by: Artyom Sasin <artyom.sasin@gmail.com>
Co-authored-by: lorrainekan <lorrainekan@google.com>
@robert-j-webb
Copy link

Any update on this? I don't think the PR to fix this has been touched since 2021

@pq
Copy link
Member

pq commented May 17, 2022

There are some unaddressed comments on that PR. Either we need to fix them or start fresh...

/fyi @natebosch @bwilkerson

@natebosch
Copy link
Member

There were some comments that I think I got stuck on but I can't recall which, I haven't looked at this in a long time.

@srawlins srawlins added the P3 A lower priority bug or feature request label Sep 22, 2022
copybara-service bot referenced this issue Sep 1, 2023
There is a basic premise in this rule which we cannot satisfy exactly:
we need to disallow `LinkedHashSet()` unless the context type requires
the developer to use `LinkedHashSet`. But the context type is long
gone when the lint rule is run.

This CL adds some logic to try to attempt figuring out the context
type in the cases where users have filed bugs, but it will never be
super accurate.

Fixes https://github.com/dart-lang/linter/issues/4736
Fixes https://github.com/dart-lang/linter/issues/3057
Fixes https://github.com/dart-lang/linter/issues/1649
Fixes https://github.com/dart-lang/linter/issues/2795

Change-Id: I3e6c6de81084dca2825488c89830ab3e7ea63186
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323680
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot referenced this issue Sep 4, 2023
…pe more"

This reverts commit cd8a337.

Reason for revert: lint starts barking at the wrong tree: b/298917960

Original change's description:
> linter: Refactor prefer_collection_literals to use context type more
>
> There is a basic premise in this rule which we cannot satisfy exactly:
> we need to disallow `LinkedHashSet()` unless the context type requires
> the developer to use `LinkedHashSet`. But the context type is long
> gone when the lint rule is run.
>
> This CL adds some logic to try to attempt figuring out the context
> type in the cases where users have filed bugs, but it will never be
> super accurate.
>
> Fixes https://github.com/dart-lang/linter/issues/4736
> Fixes https://github.com/dart-lang/linter/issues/3057
> Fixes https://github.com/dart-lang/linter/issues/1649
> Fixes https://github.com/dart-lang/linter/issues/2795
>
> Change-Id: I3e6c6de81084dca2825488c89830ab3e7ea63186
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323680
> Reviewed-by: Phil Quitslund <pquitslund@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Commit-Queue: Samuel Rawlins <srawlins@google.com>

Change-Id: I980053dd51ffd4447721e0ad7436b07ca704b554
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324021
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
copybara-service bot referenced this issue Sep 5, 2023
…ntext type more""

This reverts commit cbdae14.

In addition, Fix prefer_collection_literals for methods with expression bodies

Original description:

linter: Refactor prefer_collection_literals to use context type more

There is a basic premise in this rule which we cannot satisfy exactly:
we need to disallow `LinkedHashSet()` unless the context type requires
the developer to use `LinkedHashSet`. But the context type is long
gone when the lint rule is run.

This CL adds some logic to try to attempt figuring out the context
type in the cases where users have filed bugs, but it will never be
super accurate.

Fixes https://github.com/dart-lang/linter/issues/4736
Fixes https://github.com/dart-lang/linter/issues/3057
Fixes https://github.com/dart-lang/linter/issues/1649
Fixes https://github.com/dart-lang/linter/issues/2795

Change-Id: I958ba69a56866c18523ce6cbf62645ef8e028f6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324260
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
mosuem referenced this issue in dart-lang/tools Oct 25, 2024
- always_declare_return_types
- annotate_overrides
- omit_local_variable_types
- prefer_conditional_assignment
- prefer_if_null_operators
- prefer_single_quotes
- use_function_type_syntax_for_parameters

Ignore prefer_collection_literals lints since they would require
incorrect code where a `{}` (statically a `Map`) is assigned to a static
`LinkedHashMap`. See https://github.com/dart-lang/linter/issues/1649
@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-set-recommended P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

8 participants