Skip to content

[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

Merged
merged 7 commits into from
Jul 24, 2025
Merged

[Command] Audit #763

merged 7 commits into from
Jul 24, 2025

Conversation

JavedNicolas
Copy link
Contributor

@JavedNicolas JavedNicolas commented Jul 15, 2025

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

    • Introduced a command-line audit tool to identify translation keys used in the app but missing from translation files.
    • Added support for customizing the translations and source code directories when running the audit.
  • Documentation

    • Updated the README with instructions and details on using the new audit feature, including command-line options.

Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

A 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

File(s) Change Summary
README.md Added "✅ Audit missing keys" section with command usage and argument descriptions for the audit feature.
bin/audit.dart New executable script to parse CLI arguments, validate directories, and invoke the AuditCommand run method.
bin/audit/audit_command.dart Added AuditCommand class to scan source and translation files, detect used keys, and report missing keys per language.

Poem

In the warren of code, a bunny did peek,
Seeking lost keys that play hide-and-seek.
With a hop and a scan, the audit began,
"Where are your translations? Reveal if you can!"
Now every language is neat and complete—
No missing carrots, every string a treat!
🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0f2450 and f45b308.

📒 Files selected for processing (1)
  • bin/audit/audit_command.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bin/audit/audit_command.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
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between bed8c01 and 03f23c4.

📒 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

Copy link

@coderabbitai coderabbitai bot left a 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 to foo.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

📥 Commits

Reviewing files that changed from the base of the PR and between 03f23c4 and f0f2450.

📒 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.

@aissat aissat merged commit e64a7f8 into aissat:develop Jul 24, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants