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

DO type annotate fields ... bad example #6118

Open
srawlins opened this issue Sep 30, 2024 · 3 comments
Open

DO type annotate fields ... bad example #6118

srawlins opened this issue Sep 30, 2024 · 3 comments
Labels
a.effective-dart Relates to the best practices explained in Effective Dart p.design

Comments

@srawlins
Copy link
Member

The bad example, and the first example, under "DO type annotate fields and top-level variables if the type isn't obvious
"
use a method, and don't contain a field or top-level variable anywhere.

And none of the text in the rule can really apply to methods, unless you maybe count a method with an expression body (=> ...) as "having" an "obvious type".

@srawlins srawlins added the a.effective-dart Relates to the best practices explained in Effective Dart label Sep 30, 2024
@srawlins
Copy link
Member Author

Or looked at the other way, maybe the method example, specifically the return type, hints that the text of the rule should be changed to include methods ("DO type annotate fields, top-level variables, enum values, functions, methods, constructors, and typedefs ...")

@antfitch
Copy link

antfitch commented Mar 4, 2025

What would an ideal example look like? Can you add that here?

@srawlins
Copy link
Member Author

srawlins commented Mar 4, 2025

We could use pretty simple fields like:

// BAD
var setting = defaultSetting;

// GOOD
String setting = defaultSetting;

The "if the type isn't obvious" component does make for a tricky simple example. The value on the right could be something like importedValue or complicated.expression(with, arguments);.

I would defer to @munificent or @natebosch as to whether the rule should be changed to fit the examples.

@antfitch antfitch changed the title Effective Dart "DO type annotate fields and top-level variables ..." example uses a method Effective Dart "DO type annotate fields ..." bad example Mar 5, 2025
@antfitch antfitch changed the title Effective Dart "DO type annotate fields ..." bad example DO type annotate fields ... bad example Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.effective-dart Relates to the best practices explained in Effective Dart p.design
Projects
None yet
Development

No branches or pull requests

2 participants