provide-correct-intl-args
Warns when the Intl.message()
invocation has incorrect args
list.
Example
❌ Bad:
import 'package:intl/intl.dart';
class SomeButtonClassI18n {
static const int value = 0;
static const String name = 'name';
static String simpleTitleNotExistArgsIssue(String name) {
// LINT: The 'args' parameter is missing. Try adding it.
return Intl.message(
'title',
name: 'SomeButtonClassI18n_simpleTitleNotExistArgsIssue',
);
}
static String simpleTitleArgsMustBeOmittedIssue1() {
return Intl.message(
'title $name',
name: 'SomeButtonClassI18n_simpleTitleArgsMustBeOmittedIssue1',
args: [name] // LINT: This parameter should be added to method parameter list.
);
}
static String simpleTitleArgsMustBeOmittedIssue2() {
return Intl.message(
'title',
name: 'SomeButtonClassI18n_simpleTitleArgsMustBeOmittedIssue2',
args: [name] // LINT: Unused 'args' parameter. Try removing it.
);
}
static String simpleArgsItemMustBeOmittedIssue(int value) {
return Intl.message(
'title $value',
name: 'SomeButtonClassI18n_simpleArgsItemMustBeOmittedIssue',
args: [value, name] // LINT: "Unused 'args' parameter. Try removing it.",
);
}
static String simpleMustBeSimpleIdentifierIssue1(int value) {
return Intl.message(
'title ${value + 1}', // LINT: Incorrect identifier. Try checking this expression for a potential mistake.
name: 'SomeButtonClassI18n_simpleMustBeSimpleIdentifierIssue1',
args: [value]
);
}
}
✅ Good:
import 'package:intl/intl.dart';
class SomeButtonClassI18n {
static String simpleTitle() {
return Intl.message(
'title',
name: 'SomeButtonClassI18n_simpleTitle',
);
}
static String titleWithParameter(String name) {
return Intl.message(
'title $name',
name: 'SomeButtonClassI18n_titleWithParameter',
args: [name],
);
}
static String titleWithManyParameter(String name, int value) {
return Intl.message(
'title $name, value: $value',
name: 'SomeButtonClassI18n_titleWithManyParameter',
args: [name, value],
);
}
static String titleWithOptionalParameter({String name}) {
return Intl.message(
'title $name',
name: 'SomeButtonClassI18n_titleWithOptionalParameter',
args: [name],
);
}
static String titleWithManyOptionalParameter({String name, int value}) {
return Intl.message(
'title $name, value: $value',
name: 'SomeButtonClassI18n_titleWithOptionalParameter',
args: [name, value],
);
}
static String titleWithPositionParameter([String name]) {
return Intl.message(
'title $name',
name: 'SomeButtonClassI18n_titleWithPositionParameter',
args: [name],
);
}
static String titleWithManyPositionParameter([String name, int value]) {
return Intl.message(
'title $name, value: $value',
name: 'SomeButtonClassI18n_titleWithManyPositionParameter',
args: [name, value],
);
}
}