pass-optional-argument
Warns when the configured invocation does not have the configured optional argument.
This rule helps with cases when an external declaration (e.g. a pub package or SDK code) has optional parameters that you'd want to always pass. Alternatively, you might want to use this rule to gradually migrate to a required parameter.
For other cases try using the built-in required keyword to make parameters required.
⚙️ Config
Set entries (default is empty) to configure the list of entries for invocations.
Each entry is an object with 2 fields: args and name:
- Set
nameto configure the name of the invocation. - Set
argsto configure a list of arguments that should be always passed.
analysis_options.yaml
dcm:
rules:
- pass-optional-argument:
entries:
- name: SomeClass
args:
- label
Example
❌ Bad:
class SomeClass {
final int regular;
final String? label;
const SomeClass(this.regular, {this.label});
}
void fn() {
// LINT: This invocation is missing required optional arguments: label. Try passing them.
final instance = SomeClass(1);
}
✅ Good:
class SomeClass {
final int regular;
final String? label;
const SomeClass(this.regular, {this.label});
}
void fn() {
final instance = SomeClass(1, label: 'value');
}