magic_value_extractor 0.1.0
magic_value_extractor: ^0.1.0 copied to clipboard
Extracts hard-coded magic strings and numbers from Dart and Flutter sources into AppStrings / AppNumbers constants and rewrites the call sites for you.
Changelog #
0.1.0 #
First release.
dart run magic_value_extractor --target=lib/ --output=lib/constants/finds magic strings and magic numbers and collects them intoAppStrings/AppNumbers.- Call sites are rewritten into commented constant references
(
--comment-style=line|block|none). - Exclusions for URLs, hex colours, file paths, asset paths, empty strings,
regular expressions, widget keys, logging calls,
assert()and annotations — each individually switchable. - The common numbers (
0,1,-1,0.0,1.0,-1.0) and hex literals are ignored by default (--ignore-numbers). - Naming from a built-in Japanese→English dictionary with a romaji fallback,
extra entries through
--dictionary, and DeepL / LLM integration through--name-hookwith an optional result cache (--name-cache). - Numbers are named after their value:
double_16_0/num_300(--number-name-style=snake|camel). - Existing constant files are merged into, matching values rather than names, so constants renamed by hand are reused and manual edits survive.
- Imports are inserted in
dart:→package:→ relative order. --dry-run,--verbose,--json-report,--min-occurrences,--japanese-only,--exclude,--verify=none|parse|analyze.// magic:ignoreand// magic:ignore-filefor pinpoint exclusions.- Rewritten files are re-parsed before being written; a file that would break is left unchanged and reported.
- Supports a wide
analyzerrange (>=7.4.0 <15.0.0) so that, as adev_dependency, it never holds back the host project's toolchain: Dart 3.5 through the current SDK, alongside the latestbuild_runner/json_serializable.