Skip to main content

no-equal-arguments

added in: 1.6.0
⚙️
Pro+

Warns when equal arguments passed to a function or method invocation.

Passing the same argument (for example, a variable) to a function or method invocation more than once is usually a sign of a bug.

⚙️ Config

Set ignored-parameters (default is empty) to ignore specific named parameters (example).

Set ignored-arguments (default is empty) to ignore specific argument names (example).

Set ignore-inline-functions (default is false) to ignore inline functions that are passed as arguments (example).

analysis_options.yaml
dart_code_metrics:
rules:
- no-equal-arguments:
ignored-parameters:
- height
- width
ignored-arguments:
- someName
ignore-inline-functions: false

Example

❌ Bad:

class User {
final String firstName;
final String lastName;

const User(this.firstName, this.lastName);
}

User createUser(String firstName, String lastName) {
return User(
firstName,
firstName, // LINT: Target expression already has an argument with the same value. Try checking it for a potential mistake.
);
}

void getUserData(User user) {
String getFullName(String firstName, String lastName) {
return firstName + ' ' + lastName;
}

final fullName = getFullName(
user.firstName,
user.firstName, // LINT: Target expression already has an argument with the same value. Try checking it for a potential mistake.
);
}

✅ Good:

class User {
final String firstName;
final String lastName;

const User(this.firstName, this.lastName);
}

User createUser(String firstName, String lastName) {
return User(
firstName,
lastName,
);
}

void getUserData(User user) {
String getFullName(String firstName, String lastName) {
return firstName + ' ' + lastName;
}

final fullName = getFullName(
user.firstName,
user.lastName,
);
}

Example with "ignored-parameters"

Config
analysis_options.yaml
dart_code_metrics:
rules:
- no-equal-arguments:
ignored-parameters:
- lastName

✅ Good:

class User {
final String firstName;
final String lastName;

const User({required this.firstName, required this.lastName});
}

User createUser(String firstName, String lastName) {
return User(
firstName: firstName,
lastName: firstName, // Correct, 'lastName' is ignored
);
}

Example with "ignored-arguments"

Config
analysis_options.yaml
dart_code_metrics:
rules:
- no-equal-arguments:
ignored-arguments:
- firstName

✅ Good:

class User {
final String firstName;
final String lastName;

const User({required this.firstName, required this.lastName});
}

User createUser(String firstName, String lastName) {
return User(
firstName: firstName,
lastName: firstName, // Correct, 'firstName' is ignored
);
}

Example with "ignore-inline-functions"

Config
analysis_options.yaml
dart_code_metrics:
rules:
- no-equal-arguments:
ignore-inline-functions: false

✅ Good:

void main() {
WithFunctions(
() => null,
() => null, // Correct, ignored
);
}

class WithFunctions {
final void Function() first;
final void Function() second;

const WithFunctions(this.first, this.second);
}

Additional Resources