-
-
Notifications
You must be signed in to change notification settings - Fork 363
[Command] Audit #763
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
[Command] Audit #763
Conversation
WalkthroughA new audit feature is introduced to identify translation keys used in Flutter app source code but missing from translation files. Documentation is updated to describe this feature and its command-line usage. New Dart scripts implement the audit logic, parsing source code and translation files, and reporting missing translation keys per language. Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (2)
README.md (1)
545-559
: Address formatting issues and improve wording.The documentation is helpful but has some formatting and style issues flagged by static analysis tools.
Apply these improvements:
-### ✅ Audit missing keys +### ✅ Audit missing keys -If you prefer to not generate keys you can see an audit of your translation keys to see the one present in your app code but not in your translations file by running the audit command. +If you prefer not to generate keys, you can audit your translation keys to see which ones are present in your app code but missing from your translation files by running the audit command. -``` +```bash flutter pub run easy_localization:audit-If you are not using the default translations folder path (assets/translations) or the lib folder for your code you can specify your custom paths :
+If you are not using the default translations folder path (assets/translations) or the lib folder for your code, you can specify your custom paths:The improvements address: 1. Better word ordering as suggested by LanguageTool 2. Language specification for the code block as required by markdownlint 3. Minor punctuation and spacing corrections </blockquote></details> <details> <summary>bin/audit/audit_command.dart (1)</summary><blockquote> `85-86`: **Improve variable detection logic for more accurate filtering.** The current variable detection only checks for `$` characters, but this may not accurately identify all variable patterns used in translation keys. This could lead to false positives or negatives. Consider a more robust approach: ```diff - final missingWithVariables = missing.where((key) => key.contains('\$')).toList(); - final missingWithoutVariables = missing.where((key) => !key.contains('\$')).toList(); + final missingWithVariables = missing.where((key) => + key.contains('\$') || // String interpolation + key.contains('{') || // Named arguments + key.contains('[') // Array-like patterns + ).toList(); + final missingWithoutVariables = missing.where((key) => + !key.contains('\$') && !key.contains('{') && !key.contains('[') + ).toList();
This provides more comprehensive detection of dynamic/variable keys that cannot be reliably verified.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md
(1 hunks)bin/audit.dart
(1 hunks)bin/audit/audit_command.dart
(1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md
[style] ~547-~547: Consider changing the order of words to improve your wording.
Context: ...### ✅ Audit missing keys If you prefer to not generate keys you can see an audit of y...
(TO_NOT_VB)
🪛 markdownlint-cli2 (0.17.2)
README.md
549-549: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
bin/audit/audit_command.dart (1)
85-86
: Missing LocaleKeys snake_case to dot notation conversion.The regex pattern captures LocaleKeys usage but doesn't convert snake_case keys to dot notation as mentioned in past review comments. Keys like
LocaleKeys.foo_bar
should be converted tofoo.bar
before adding to the used set.if (match.groupCount > 0) { - used.add(match.group(1)!); + String key = match.group(1)!; + // Convert LocaleKeys.foo_bar to foo.bar + if (pattern.pattern.contains('LocaleKeys')) { + key = key.replaceAll('_', '.'); + } + used.add(key); }Also applies to: 104-104
🧹 Nitpick comments (1)
bin/audit/audit_command.dart (1)
14-14
: Consider using return instead of exit() for better testability and library usage.Using
exit(1)
terminates the entire program, which may be too aggressive for a library command. Consider returning early or throwing an exception instead to allow calling code to handle the error appropriately.if (!translationDir.existsSync()) { stderr.writeln('Error: Translation directory "$transDir" does not exist.'); - exit(1); + return; } if (!sourceDir.existsSync()) { stderr.writeln('Error: Source directory "$srcDir" does not exist.'); - exit(1); + return; }Also applies to: 19-19
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
bin/audit.dart
(1 hunks)bin/audit/audit_command.dart
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- bin/audit.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (4)
bin/audit/audit_command.dart (4)
75-93
: Regex patterns are comprehensive and well-documented.The regex patterns effectively cover various translation key usage patterns including direct calls, context calls, string literals, generated keys, and pluralization. The comments clearly explain each pattern's purpose.
39-46
: Good error handling implementation for file operations.The try-catch block properly handles file reading and JSON parsing errors while allowing the process to continue with other files. The error message includes the file path for debugging.
67-69
: Excellent handling of different JSON value types.The method now properly handles arrays, numbers, and booleans as leaf values, ensuring all translation keys are captured regardless of their value type.
122-145
: Thoughtful separation of missing keys with and without variables.The reporting logic intelligently separates missing keys that contain variables (which may be false positives) from those without variables. This provides clearer actionable feedback to developers.
An alternative to key generation by comparing all the keys in code to the one in the localization files and return the one not present.
flutter pub run easy_localization:audit
Arguments :
--translations-dir | -t | assets/translations | Folder containing localization files
--source-dir | -s | lib | Folder containing the app code files
Summary by CodeRabbit
New Features
Documentation