-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work ondevexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.linter-lint-proposaltype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
Proposal for New Dart Lint Rule
TLDR
Add a lint rule to prefer wildcard variables (_) over multiple underscores (_, __, ___) in unused parameters.
Motivation
The upcoming Dart 3.7.0 release introduces support for wildcard variables (_) that can be reused for multiple unused parameters. Previously, developers commonly relied on distinct variables like _, __, ___ to indicate unused parameters. This practice is now redundant with the introduction of _, which improves clarity and reduces visual noise in the codebase.
Reference
Lint Rule Implementation
Rule Name: prefer_wildcard_variables
Description: Warns when distinct variable names such as __, ___, etc. are used for unused parameters, recommending the use of _ instead.
Severity Level: WARNING (as it’s a stylistic improvement and non-breaking).
Code Examples
Bad
ListView.builder(
itemCount: 10,
itemBuilder: (_, __) {
return ListTile(
title: Text('Item'),
);
},
);
Good
ListView.builder(
itemCount: 10,
itemBuilder: (_, _) {
return ListTile(
title: Text('Item'),
);
},
);Behavior
- Triggers a warning: When multiple distinct unused variable names (
__, ___) are declared. - Does not trigger: For valid wildcard use cases, such as
(_, _, _).
Benefits
- Improved Code Readability: Reduces unnecessary differentiation in unused parameter names.
- Consistent Dart Style: Encourages developers to adopt features introduced in newer Dart versions.
- Simpler Refactoring: Avoids subtle issues where
_,__, and___might accidentally be referenced or misinterpreted.
pq, FMorschel and lishaduck
Metadata
Metadata
Assignees
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work ondevexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.linter-lint-proposaltype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug