Skip to content

Commit 3d2d93b

Browse files
committed
feat: hidding warning by default and added flag to display them
1 parent 73a945e commit 3d2d93b

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ If you are not using the default translations folder path (assets/translations)
588588
| ---------------------------- | ----- | --------------------- | --------------------------------------------------------------------------- |
589589
| --translations-dir | -t | assets/translations | Folder containing localization files |
590590
| --source-dir | -s | lib | Folder containing the app code files |
591+
| --show-warnings | -w | false | show the warning (keys that contains variables and thus cannot be verified) |
591592
592593
### Errors :
593594

bin/audit.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ void main(List<String> args) {
99

1010
parser.addOption('translations-dir', abbr: 't', defaultsTo: 'assets/translations');
1111
parser.addOption('source-dir', abbr: 's', defaultsTo: 'lib');
12+
parser.addFlag('show-warnings', abbr: 'w', defaultsTo: false);
1213

1314
try {
1415
var argResults = parser.parse(actual);
1516
final transDir = argResults['translations-dir'] as String;
1617
final srcDir = argResults['source-dir'] as String;
18+
final showWarnings = argResults['show-warnings'] as bool;
1719

1820
if (!Directory(transDir).existsSync()) {
1921
stderr.writeln('Error: Translation directory "$transDir" does not exist.');
@@ -25,7 +27,7 @@ void main(List<String> args) {
2527
exit(1);
2628
}
2729

28-
AuditCommand().run(transDir: transDir, srcDir: srcDir);
30+
AuditCommand().run(transDir: transDir, srcDir: srcDir, showWarnings: showWarnings);
2931
} catch (e) {
3032
stderr.writeln('Error: $e');
3133
exit(1);

bin/audit/audit_command.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:io';
22
import 'key_parser.dart';
33

44
class AuditCommand {
5-
Future<void> run({required String transDir, required String srcDir}) async {
5+
Future<void> run({required String transDir, required String srcDir, required bool showWarnings}) async {
66
try {
77
final translationDir = Directory(transDir);
88
final sourceDir = Directory(srcDir);
@@ -21,13 +21,13 @@ class AuditCommand {
2121
final allTranslations = await keyParser.parseKeysInTranslationsDir(translationDir);
2222
final usedKeys = keyParser.parseKeysInSourceDir(sourceDir);
2323

24-
_report(allTranslations, usedKeys);
24+
_report(allTranslations, usedKeys, showWarnings: showWarnings);
2525
} catch (e) {
2626
stderr.writeln('Error during audit: $e');
2727
}
2828
}
2929

30-
void _report(Map<String, Set<String>> allTranslations, Set<String> usedKeys) {
30+
void _report(Map<String, Set<String>> allTranslations, Set<String> usedKeys, {required bool showWarnings}) {
3131
stderr.writeln('=== Keys Audit ===');
3232

3333
for (var lang in allTranslations.keys) {
@@ -37,7 +37,7 @@ class AuditCommand {
3737
final missingWithoutVariables = missing.where((key) => !key.contains('\$')).toList();
3838

3939
stderr.writeln('\nLanguage: $lang');
40-
if (missingWithVariables.isEmpty && missingWithoutVariables.isEmpty) {
40+
if ((missingWithVariables.isEmpty || !showWarnings) && missingWithoutVariables.isEmpty) {
4141
stderr.writeln(' ✅ all good!');
4242
}
4343

@@ -51,7 +51,7 @@ class AuditCommand {
5151
exit(1);
5252
}
5353

54-
if (missingWithVariables.isNotEmpty) {
54+
if (missingWithVariables.isNotEmpty && showWarnings) {
5555
stderr.writeln(' 🟡 Missing with variables (${missingWithVariables.length}):');
5656
stderr.writeln(' These keys may not be missing as they contain variables that cannot be verified.');
5757
for (var key in missingWithVariables) {

0 commit comments

Comments
 (0)