Skip to content

A lint similar to always_specify_types, for always specifying all parameters of a function/constructor #58818

@rrousselGit

Description

@rrousselGit

Describe the rule you'd like to see implemented

The idea of this rule is to basically act as if every single parameter has the required keyword.
The idea is that as opposed to the required keyword, this lint would be an opinionated decision from the team maintaining using this lint.
In a way, this is very similar to that of always_specify_types. Teams enabling this voluntarily accept more verbose code for safer code.

Always passing all parameters of functions can help maintain code by making it explicit that a value isn't specified. For example:

fn(param: null);

vs:

fn();

With the former, you know for sure that this usage doesn't want to pass a value to param. With the later, the intention is less clear. The author of that code could've forgotten to pass the value. Or maybe the reader doesn't know about the existence of param.


While the required keyword exists, due to various constraints, it's not always possible to use it.

For example, the source that is being worked on may be a package. In this scenario, marking all parameters as required would have undesired consequences on the users of the package (such as unnecessary breaking changes, or bothering users who don't like this practice).

Similarly, not all code can be edited to have this required keyword, as some code may be coming from packages/SDK.
A codebase using this lint would expect all parameters of said package/SDK to also be "required", yet the implementation wouldn't match that.

Examples

Nothing special to say here. When this lint is enabled, both positional and named parameters would be required, even is marked as optional:

void fn([int? a]) {}
void fn2({int? a}) {}

void main() {
  fn(); // KO, expected 1 parameter but received 0
  fn2(); // KO, expected a named parameter "a" but it is missing
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions