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

Adjust documentation of prefer_void_to_null #58908

Open
eernstg opened this issue Oct 27, 2022 · 2 comments
Open

Adjust documentation of prefer_void_to_null #58908

eernstg opened this issue Oct 27, 2022 · 2 comments
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 P2 A bug or feature request we're likely to work on type-documentation A request to add or improve documentation

Comments

@eernstg
Copy link
Member

eernstg commented Oct 27, 2022

The lint prefer_void_to_null has a very concise motivation section. #58906 raised the issue that it isn't helpful to recommend that a local variable of type Null is changed such that the type is void. An extended motivation section could clarify more broadly in which situations the lint is useful.

Another part of the documentation that needs an update is at the end:

empty literals which are safe to pass into read-only locations for any type of map or list

Today, with null safety, such collection literals should have the actual type argument Never (like const <Never>[]). The type argument could also be Null, but the collection would then only be usable when the required type has a nullable type argument.

Note that a type variable is never a nullable type, which means that <Null>[] could never be passed when the required type is List<X> where X is a type variable; this seems to make <Null>[] nearly useless as a "universal empty list", so we probably don't even want to mention <Null>[] in the documentation for this lint.

@eernstg eernstg added type-documentation A request to add or improve documentation linter-set-recommended labels Oct 27, 2022
@pq
Copy link
Member

pq commented Oct 27, 2022

This is great. Thank you! (A PR would be more than welcome too! 😉)

@eernstg
Copy link
Member Author

eernstg commented Oct 28, 2022

I can see that the lint was created by @MichaelRFairhurst.

@MichaelRFairhurst, I know you've moved on, but it would be great if you could comment a little bit on important situations flagged by this lint!

I think Future<Null> that ought to be Future<void> is a good example, and perhaps T<... Null ...> that ought to be T<... void ...> for any T, but even in those cases it isn't obvious to me how it is possible to detect that the use of Null is actually not a good choice. For example:

class OperationThatMayFail {
  Future<Object?> doit() async {...} // The result is an error specification, null means 'no issues'.
}

class OperationThatWillNeverFail extends OperationThatMayFail {
  Future<Null> doit() async {...} // No need to check whether there are any issues.
}

@srawlins srawlins added the P2 A bug or feature request we're likely to work on label Oct 28, 2022
@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 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 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 P2 A bug or feature request we're likely to work on type-documentation A request to add or improve documentation
Projects
None yet
Development

No branches or pull requests

4 participants