From cf5620859a0408a3bfb5dce868c5a5f774b875ba Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Thu, 29 Sep 2022 10:21:57 -0400 Subject: [PATCH 1/4] Report parse errors in generated code better --- lib/src/intl_suggestors/message_parser.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/src/intl_suggestors/message_parser.dart b/lib/src/intl_suggestors/message_parser.dart index 03a2ad73..586eb0af 100644 --- a/lib/src/intl_suggestors/message_parser.dart +++ b/lib/src/intl_suggestors/message_parser.dart @@ -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(); From cd4a75df49ad40522483c560e3f38368eef9a576 Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Thu, 29 Sep 2022 10:24:05 -0400 Subject: [PATCH 2/4] add changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45e96ec7..b886aaf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [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 + ## [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. From db91a4e5c1669acef32ac777eb1c6f68ab15850d Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Thu, 29 Sep 2022 11:53:47 -0400 Subject: [PATCH 3/4] Also fix an error with toVariableName when we get the name from the node --- lib/src/intl_suggestors/utils.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/intl_suggestors/utils.dart b/lib/src/intl_suggestors/utils.dart index 1f8f331e..b2b741df 100644 --- a/lib/src/intl_suggestors/utils.dart +++ b/lib/src/intl_suggestors/utils.dart @@ -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 = From ad690c4121c67ab59acda5bfe56913549aba31ec Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Thu, 29 Sep 2022 11:54:38 -0400 Subject: [PATCH 4/4] update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b886aaf8..d9fc7ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - 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)