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

☂️ Update lint set for Flutter applications #78432

Closed
7 of 15 tasks
goderbauer opened this issue Mar 17, 2021 · 19 comments
Closed
7 of 15 tasks

☂️ Update lint set for Flutter applications #78432

goderbauer opened this issue Mar 17, 2021 · 19 comments
Assignees
Labels
dependency: dart Dart team may need to help us framework flutter/packages/flutter repository. See also f: labels. P0 Critical issues such as a build break or regression tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@goderbauer
Copy link
Member

goderbauer commented Mar 17, 2021

The lints currently applied by flutter analyze to flutter applications created with flutter create is outdated: analysis_options_user.yaml received its last meaningful update in October 2019. This umbrella issue tracks the work necessary to update those lints and align the set of lints recommended for Flutter application with the Dart universe.

Details of the approach are discussed in http://flutter.dev/go/flutter-lints.

Work Items

Punted

We've decided to remove unawaited_futures and prefer_mixins from the lint set for now so the following issues are no longer blocking and can be addressed later.

/cc @pq @Hixie @mit-mit @munificent @devoncarew I think these are the work items that came out of our meeting the other day.

@goderbauer goderbauer added tool Affects the "flutter" command-line tool. See also t: labels. framework flutter/packages/flutter repository. See also f: labels. dependency: dart Dart team may need to help us P2 labels Mar 17, 2021
@devoncarew
Copy link
Member

One comment:

core.yaml, recommend.yaml, and potentially a Flutter-specific lint file are published in a package

If we do decide that we need a Flutter specific lint file (if we're not able to in-line everything into core and recommended), the flutter specific lints could just be shipped as part of the flutter package (e.g., packages/flutter/lib/flutter_recommended.yaml).

@goderbauer
Copy link
Member Author

I believe that would cause versioning issues: Whenever you upgrade your version of flutter you'd be forced to also upgrade your code base to the latest lints in packages/flutter/lib/flutter_recommended.yaml. If it ships as part of a separate (versioned) package, updating flutter and updating the set of recommended lints can happen independently.

@devoncarew
Copy link
Member

It would definitely be a decision in terms of how we want these to roll out. We could version them with the sdk and ship changes as part of new stable versions.

@pq
Copy link
Contributor

pq commented Mar 17, 2021

/fyi also @davidmorgan @bwilkerson

@goderbauer goderbauer self-assigned this Mar 17, 2021
@davidmorgan
Copy link
Contributor

Thanks everyone!

Commented on the doc re: versioning. package_pedantic solves this by having versioned files within the package, so everyone can always be on the latest version and still choose which version they want. Additionally, there is one file that always includes the latest lints, in case you want to auto update rather than pin.

That model seems to work :)

@goderbauer
Copy link
Member Author

goderbauer commented Mar 18, 2021

It is not clear to me why you'd need the double versioning (pub package version + yaml version). If the package doesn't contain any code, wouldn't it be enough to just use the package version? Whenever a new lint is added, it's treated as a breaking change and the MAJOR version number is bumped. If you're ready to upgrade to the latest set of recommended lints (and fix the warnings produced by it), you bump the package version in you package's pubspec.

@davidmorgan
Copy link
Contributor

Sorry, my mistake--I checked: the analyzer has no problems resolving different yaml versions from different packages. Please ignore :)

@lrhn
Copy link
Contributor

lrhn commented Apr 7, 2021

The reason for double-versioning is that it allows you to not use the most recent version of the lints.

That's not important if the lints package is only a dev-dependency for all packages. If any package you depend on uses the lints package as a non-dev-dependency, you'll need to use a version accepted by that other package.

If we make a change to the lints file, by adding a lint, your code might no longer be lint-warning-free. Some build systems might consider that an error. That means that you need to migrate your code to the new lints, and until then, you might want to keep your lints at the previous version.

Again, if everybody uses the lints package as a dev-dependency only, you can just lock yourself to an older version of the lints package. If not, you might need to depend on a newer version of the lints package, and the versioned yaml files allows you to still use the older lints file.

(Arguably, you can also just add the_new_lint: ignore to analysis_options.yaml to override the import, but that requires more work for the user to figure out which precise lints have changed between versions).

@goderbauer
Copy link
Member Author

The above was assuming that the package is added as a dev-dependency, which I think is the right thing to do for this package. If you don't do that correctly, it will cause problems, yes. But that's also true for other dev-dependencies that were accidentally added as a regular dependency, no? E.g. if I accidentally add package:test as a regular dependency I am also forcing the hands of other packages that depend on me...

@davidmorgan
Copy link
Contributor

We know from pedantic that making it a full dependency is a bad idea ;) we don't have an example for publishing yaml in a dev dependency always working well, but as far as I can tell it should :)

@Hixie
Copy link
Contributor

Hixie commented Apr 8, 2021

Can we put something in a package's pubspec.yaml that would make it impossible to include as a regular (non-dev) dependency?

@pq
Copy link
Contributor

pq commented Apr 8, 2021

Can we put something in a package's pubspec.yaml that would make it impossible to include as a regular (non-dev) dependency?

@jonasfj ?

@jonasfj
Copy link
Member

jonasfj commented Apr 8, 2021

No such thing exists, but we could introduce it.

I think it's a bit strong to say "never". Perhaps it's sufficient to introduce something that:

  1. Changes dart pub add <package> to add it as dev_dependency
  2. Produces a warning in dartanalyzer.

Maybe it's just as simple as having is_dev_dependency: true, we can always deprecate such a feature without side-effects.


The downside of completely forbidding consumption as non-dev dependency is that any package intended to be used as a dev-dependency could certainly be used by another tool that is itself a dev-dependency.

@pq
Copy link
Contributor

pq commented Apr 8, 2021

Maybe it's just as simple as having is_dev_dependency: true, we can always deprecate such a feature without side-effects.

FWIW, I really like this proposal. 👍

@davidmorgan
Copy link
Contributor

davidmorgan commented Apr 9, 2021

SGTM.

Prior art for is_dev_dependency: bazel's testonly attribute (no direct link, sorry, please search that table). Note that would suggest that an is_dev_dependency package can use other is_dev_dependency packages as a full dependency.

So e.g. package:test can be marked is_dev_dependency, and my package:more_awesome_test can be marked is_dev_dependency and depend on package:test as a full dependency.

This is a big step beyond the simple non-transitive version we need for lints yaml, but maybe worth a thought :) could be added to the simple version later, so doesn't need to block anything.

@goderbauer
Copy link
Member Author

Updated the top comment with the current status.

@mit-mit
Copy link
Member

mit-mit commented May 12, 2021

@goderbauer I created tracking issues for the punted lints in the package:lints repo:
https://github.com/dart-lang/lints/issues?q=is%3Aissue+is%3Aopen+label%3Atype-lint

@goderbauer
Copy link
Member Author

The main goal of this issue has been achieved, a migration guide for existing projects is published at https://flutter.dev/docs/release/breaking-changes/flutter-lints-package.

What's left to do is to update DartPad (tracked in dart-lang/dart-pad#1881) and actively nudging existing/established projects to upgrade to pkg:flutter_lints (this is tracked in #82948).

I am going to close this umbrella issue since the main work is done and the remaining auxiliary work is tracked separately.

@github-actions
Copy link

github-actions bot commented Aug 1, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
@flutter-triage-bot flutter-triage-bot bot added P0 Critical issues such as a build break or regression and removed P2 labels Jun 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependency: dart Dart team may need to help us framework flutter/packages/flutter repository. See also f: labels. P0 Critical issues such as a build break or regression tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

No branches or pull requests

9 participants