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

add additional lints to dart_flutter_team_lints #167

Merged
merged 6 commits into from
Sep 13, 2023

Conversation

devoncarew
Copy link
Member

This adds 7 of the lints that we've commonly enabled on dart-lang packages; see #110 for the full list and counts from our repos.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@github-actions
Copy link

github-actions bot commented Sep 12, 2023

Package publishing

Package Version Status Publish tag (post-merge)
package:dart_flutter_team_lints 2.0.0 ready to publish dart_flutter_team_lints-v2.0.0
package:firehose 0.3.27 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@github-actions
Copy link

github-actions bot commented Sep 12, 2023

PR Health

Package publish validation ✔️

Details
Package Version Status
package:dart_flutter_team_lints 2.0.0 ready to publish
package:firehose 0.3.27 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

License Headers ✔️

Details
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Changelog Entry ❗

Details
Package Changed Files
package:firehose pkgs/firehose/lib/firehose.dart
pkgs/firehose/lib/src/github.dart
pkgs/firehose/lib/src/health/health.dart
pkgs/firehose/lib/src/repo.dart

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check

Coverage ⚠️

Details
File Coverage
pkgs/firehose/lib/firehose.dart 💔 Not covered
pkgs/firehose/lib/src/github.dart 💚 10 %
pkgs/firehose/lib/src/health/health.dart 💔 Not covered
pkgs/firehose/lib/src/repo.dart 💚 87 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check

@github-actions github-actions bot added the type-infra A repository infrastructure change or enhancement label Sep 12, 2023
@devoncarew
Copy link
Member Author

Here are the lint results from this repo:

   info • pkgs/blast_repo/lib/src/top_level.dart:9:8 • Use relative imports for files in the 'lib' directory. Try converting the URI to a
          relative URI. • prefer_relative_imports
   info • pkgs/corpus/bin/deps.dart:60:50 • Use 'const' with the constructor to improve performance. Try adding the 'const' keyword to
          the constructor invocation. • prefer_const_constructors
   info • pkgs/corpus/lib/api.dart:52:28 • Use 'const' with the constructor to improve performance. Try adding the 'const' keyword to the
          constructor invocation. • prefer_const_constructors
   info • pkgs/corpus/lib/api.dart:74:9 • Use 'const' with the constructor to improve performance. Try adding the 'const' keyword to the
          constructor invocation. • prefer_const_constructors
   info • pkgs/corpus/lib/report.dart:7:8 • Use relative imports for files in the 'lib' directory. Try converting the URI to a relative
          URI. • prefer_relative_imports
   info • pkgs/corpus/test/api_test.dart:21:11 • Use 'const' with the constructor to improve performance. Try adding the 'const' keyword
          to the constructor invocation. • prefer_const_constructors
   info • pkgs/corpus/test/api_test.dart:24:13 • Use 'const' with the constructor to improve performance. Try adding the 'const' keyword
          to the constructor invocation. • prefer_const_constructors
   info • pkgs/corpus/test/api_test.dart:46:13 • Use 'const' with the constructor to improve performance. Try adding the 'const' keyword
          to the constructor invocation. • prefer_const_constructors
   info • pkgs/firehose/lib/firehose.dart:10:8 • Use relative imports for files in the 'lib' directory. Try converting the URI to a
          relative URI. • prefer_relative_imports
   info • pkgs/firehose/lib/src/github.dart:9:8 • Use relative imports for files in the 'lib' directory. Try converting the URI to a
          relative URI. • prefer_relative_imports
   info • pkgs/firehose/lib/src/health/health.dart:11:8 • Use relative imports for files in the 'lib' directory. Try converting the URI
          to a relative URI. • prefer_relative_imports
   info • pkgs/firehose/lib/src/repo.dart:7:8 • Use relative imports for files in the 'lib' directory. Try converting the URI to a
          relative URI. • prefer_relative_imports
   info • pkgs/repo_manage/lib/issue_transfer.dart:202:34 • Use 'const' with the constructor to improve performance. Try adding the
          'const' keyword to the constructor invocation. • prefer_const_constructors
   info • pkgs/repo_manage/lib/weekly.dart:62:47 • Use 'const' with the constructor to improve performance. Try adding the 'const'
          keyword to the constructor invocation. • prefer_const_constructors
   info • pkgs/repo_manage/lib/weekly.dart:65:48 • Use 'const' with the constructor to improve performance. Try adding the 'const'
          keyword to the constructor invocation. • prefer_const_constructors

So, 8 prefer_const_constructorss and 6 prefer_relative_importss. Both of those have dart fixes available.


linter:
rules:
# consistency
- avoid_empty_else
- avoid_shadowing_type_parameters
- avoid_types_as_parameter_names
- avoid_unused_constructor_parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one could lead to forced breaking API changes if a constructor parameter stops being used but is still passed by callers.

I don't know if it would ever occur that a constructor argument starts being ignored and it's not already a breaking behavior change, but I'm a little paranoid about lints that could suggest breaking API changes because an author applying a quick fix is less likely to consider impact on usages than an author manually changing arguments...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, people will feel the need to address these issues, and will assume that the lint is telling them the right thing to do.

@@ -35,8 +37,10 @@ linter:
- lines_longer_than_80_chars
- omit_local_variable_types
- prefer_asserts_in_initializer_lists
- prefer_const_constructors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sigmundch - is there any risk of degrading IPL or any other negative impacts by making too many values const in widely used packages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion with this lint, but note that we do have it enabled in 22 of 29 sampled dart-lang packages, and flutter turns this lint on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it moves initialization of each of those values to be done eagerly during the IPL as you noted (as opposed to being lazy or on-demand at the time you need it.). The question comes down to how many constants we are talking about. If it's just a handful of them, it's fine, but if all the sudden this will increase the total number of constants by 2x, that's more concerning.

cc @rakudrama, although he is about to be on PTO for a while.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will degrade IPL but a few small constants will not make much difference. It is really hard to give advice here since it depends a lot on the number and qualities of the constants. A few moderate sized class constants would be fine, unless one of their fields were initialized with, say, a gargantuan map.

I'd like to make dart2js be smarter about the impact of larger constants on IPL (e.g. dart-lang/sdk#32943) but I don't think it will ever be zero.

I would say go ahead since constant widgets, being identical each frame, help the flutter framework more efficiently detect parts of the widget tree that are invariant. It can translate to better frame rate.


# correctness
- always_declare_return_types
- avoid_catching_errors
- avoid_dynamic_calls
- await_only_futures
- cancel_subscriptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this lint is reliable enough - there are false positives.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm - will remove

Copy link
Member Author

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to remove avoid_unused_constructor_parameters and cancel_subscriptions.

Note that I also added in conditional_uri_does_not_exist - not in the original PR.

@devoncarew devoncarew merged commit babf5d1 into main Sep 13, 2023
@devoncarew devoncarew deleted the update_dart_flutter_team_lints branch September 13, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

general updates to package:dart_flutter_team_lints
4 participants