Skip to content

Commit

Permalink
Merge pull request #189 from Workiva/no_screaming
Browse files Browse the repository at this point in the history
Do not internationalize SCREAMING_CAPS constants
  • Loading branch information
rmconsole5-wk authored Oct 7, 2022
2 parents 618482d + 07d2441 commit 1520ddd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Improve reporting of parse errors in generated code for intl_message_migration
- Fix a regression where we were getting strings with surrounding quotes from the node,
and not stripping leading numbers as a result.
- Don't convert SCREAMING_CAPS_CONSTANTS in intl_message_migration

## [2.9.0](https://github.com/Workiva/over_react_codemod/compare/2.9.0....2.8.0)

Expand Down
2 changes: 2 additions & 0 deletions lib/src/intl_suggestors/intl_migrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ConstantStringMigrator extends GeneralizingAstVisitor
var end = node.parent!.end;
var firstLetter = string.substring(0, 1);
var secondLetter = string.substring(1, 2);
// If it looks like a CONSTANT_FROM_SOME_OTHER_LIBRARY don't convert it.
if (string.toUpperCase() == string) return;
// Is the first character uppercase, excluding strings that start with two of the same
// uppercase character, which has a good chance of being a date format (e.g. 'MM/dd/YYYY').
if (firstLetter != secondLetter &&
Expand Down
13 changes: 13 additions & 0 deletions test/intl_suggestors/constant_migrator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ void main() {
expect(messages.messageContents(), expectedFileContent);
});

test('SCREAMING_CAPS_ARE_IGNORED', () async {
await testSuggestor(
input: '''
const foo = 'DO_NOT_CONVERT_ME';
''',
expectedOutput: '''
const foo = 'DO_NOT_CONVERT_ME';
''',
);
final expectedFileContent = '';
expect(messages.messageContents(), expectedFileContent);
});

test('static constant', () async {
await testSuggestor(
input: '''
Expand Down

0 comments on commit 1520ddd

Please sign in to comment.