Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTL-188: Fix incrementing the usage number of duplicate getters #186

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/intl_suggestors/intl_message_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MessageSyntax {
/// A template to build property access for intl string
/// ex: ExampleIntl.exampleString
String getterCall(StringLiteral node, String namespace, {String? name}) =>
'${namespace}.${name ?? nameForNode(node, initialName: name)}';
'${namespace}.${nameForNode(node, initialName: name)}';

/// Returns Intl.message for string literal.
///
Expand Down
23 changes: 23 additions & 0 deletions test/intl_suggestors/constant_migrator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ void main() {
final expectedFileContent = '''
static String get anotherStatic => Intl.message(\'Another static\', name: \'TestClassIntl_anotherStatic\');
static String get foo => Intl.message(\'I am a user-visible constant\', name: \'TestClassIntl_foo\');
''';
expect(messages.messageContents().trim(),
expectedFileContent.trim()); // Avoid the leading return.
});

test('duplicate getter names increment', () async {
await testSuggestor(
input: '''
const String dueDate = 'Due Date';
class Dupe {
static const dueDate = 'Due date';
}
''',
expectedOutput: '''
final String dueDate = TestClassIntl.dueDate;
class Dupe {
static final String dueDate = TestClassIntl.dueDate1;
}
''',
);
final expectedFileContent = '''
static String get dueDate => Intl.message(\'Due Date\', name: \'TestClassIntl_dueDate\');
static String get dueDate1 => Intl.message(\'Due date\', name: \'TestClassIntl_dueDate1\');
''';
expect(messages.messageContents().trim(),
expectedFileContent.trim()); // Avoid the leading return.
Expand Down