Skip to content

proposal: specify_parameter_names #59047

@goderbauer

Description

@goderbauer

specify_parameter_names

Description

Specify names for the parameters of Function types.

Details

Dart allows omitting the name of parameters in function types:

class LayoutBuilder {
  LayoutBuilder({this.builder});

  final Widget Function(BuildContext, ConstraintType) builder;
}

While that is legal, it degrades the experience of anyone using this widget with code completion in IDEs:

image

Since no names were given, unhelpful names are generated. This can be avoided by giving the parameters proper names:

class LayoutBuilder {
  LayoutBuilder({this.builder});

  final Widget Function(BuildContext context, ConstraintType constraints) builder;
}

The proposed lint would enforce that function types must always contain names for the parameters to improve the experience for anyone using IDE and code completion.

See also flutter/flutter#119877.

Kind

Maybe style? It's kinda a usability thing when people work with IDEs, though.

Bad Examples

Widget Function(BuildContext, ConstraintType) builder;
typedef BuilderCallback = Widget Function(BuildContext, ConstraintType);

Good Examples

Widget Function(BuildContext context, ConstraintType constraints) builder;
typedef BuilderCallback = Widget Function(BuildContext context, ConstraintType constraints);

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.customer-flutterdevexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposallinter-status-pendingtype-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