Skip to content

Commit

Permalink
Merge pull request #188 from Workiva/report_parse_errors_better
Browse files Browse the repository at this point in the history
Report parse errors better
  • Loading branch information
rmconsole6-wk authored Oct 5, 2022
2 parents a5c71e1 + 279299c commit 618482d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [2.10.0](https://github.com/Workiva/over_react_codemod/compare/2.10.0....2.9.0)

- Upgrade to analyzer 2.0
- 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.

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

- Improve the sorting to be by function/getter name rather than the whole function/getter string.
Expand Down
11 changes: 10 additions & 1 deletion lib/src/intl_suggestors/message_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ class MessageParser {
}

void _parse() {
ParseStringResult parsed = parseString(content: source, path: path);
ParseStringResult parsed;
try {
parsed = parseString(content: source, path: path);
} on ArgumentError {
print('Error in generated code!!');
print('--------------------------------------------------------');
print(source);
print('--------------------------------------------------------');
rethrow;
}
var intlClass = parsed.unit.declarations.first as ClassDeclaration;
var methodDeclarations =
intlClass.members.toList().cast<MethodDeclaration>();
Expand Down
4 changes: 4 additions & 0 deletions lib/src/intl_suggestors/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ String toClassName(String str) {
/// finally we check if it is a keyword and if so append "String" to it.
/// - "New" -> newString
String toVariableName(String str) {
// The name might have surrounding quotes, remove them.
if (str.startsWith("'") && str.endsWith("'")) {
str = str.substring(1, str.length - 1);
}
String strippedName =
str.replaceFirst(RegExp(r'^[0-9]*'), '').replaceAll("'", '').trim();
var fiveAtMost =
Expand Down

0 comments on commit 618482d

Please sign in to comment.