From ab9897ce15bdb98f7e6abd9a7ce577d1aed5c63d Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Wed, 5 Nov 2025 01:06:03 +0530 Subject: [PATCH] refactor(l10n): Improve key usage scanning by replacing external process with direct file reading --- tool/validate_arb_locales.dart | 39 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/tool/validate_arb_locales.dart b/tool/validate_arb_locales.dart index 3ad2f28..95771b0 100644 --- a/tool/validate_arb_locales.dart +++ b/tool/validate_arb_locales.dart @@ -124,23 +124,34 @@ Future> _scanUsedLocalizationKeys(Set baseKeys) async { final used = {}; Future keyIsUsed(String key) async { - final result = await Process.run('rg', [ - '--fixed-strings', - '--quiet', - '--glob=*.dart', - '--glob=!lib/l10n/app_localizations*.dart', - key, - 'lib', - ]); - if (result.exitCode == 0) { - return true; - } - if (result.exitCode > 1) { + try { + final libDir = Directory('lib'); + if (!await libDir.exists()) { + return false; + } + + await for (final entity in libDir.list(recursive: true)) { + if (entity is! File) continue; + if (!entity.path.endsWith('.dart')) continue; + if (entity.path.contains('lib/l10n/app_localizations')) continue; + + try { + final content = await entity.readAsString(); + if (content.contains(key)) { + return true; + } + } catch (e) { + // Skip files that can't be read + continue; + } + } + return false; + } catch (e) { stderr.writeln( - 'warning: failed to search for key "$key": ${result.stderr}'.trim(), + 'warning: failed to search for key "$key": $e', ); + return false; } - return false; } for (final key in baseKeys) {