为项目配置硬编码文案检查
检查项目现有国际化与 lint 设置,添加面向用户界面的硬编码字符串规则,并接入持续集成验证。
完整提示词
<context>
After the first extraction pass, hard-coded strings creep back in within weeks unless something fails. Each ecosystem has a check: `eslint-plugin-i18next` (`no-literal-string`) or `eslint-plugin-formatjs` and `@intlify/eslint-plugin-vue-i18n` for JavaScript frameworks, Android lint `HardcodedText` and `SetTextI18n`, SwiftLint custom rules or Xcode's localization warnings, Flutter analyzer rules or custom lints, gettext extraction diffs for Python and PHP. Turned on naively they flag thousands of false positives (CSS classes, test ids, route paths, log lines, enum values), the team adds blanket disables, and the check becomes noise. The useful setup restricts the rule to JSX text and user-facing attributes, ignores known non-UI patterns, starts from a baseline of existing debt, and adds a cheap second check that every key used in code exists in the source catalog.
</context>
<task>
Add hard-coded string checks to {{repo_scope}}.
{{#ci}}CI: {{ci}}.{{/ci}}
Mode: {{mode}}.
1. Inspect the existing lint setup, config format (flat or legacy ESLint config, `lint.xml`, `.swiftlint.yml`, `analysis_options.yaml`), the i18n library and how strings are looked up.
2. Choose the rule or tool per ecosystem and explain why. Prefer maintained plugins tied to the i18n library in use; fall back to a narrowly scoped custom rule only when none fits.
3. Configure the rule to check user-facing text only: JSX or template text, and attributes such as `alt`, `title`, `placeholder`, `aria-label`, `label`. Ignore test files, stories, logging calls, `className`, `data-testid`, route definitions and constants files that hold non-UI values.
4. Add a check for string concatenation around translated values (`t("a") + name`) where the tool supports it, and a script or plugin check that every literal key used in code exists in the source catalog.
5. Write an allowlist for brand names, units and symbols, with a comment per entry, and document the inline-disable form with a required reason.
6. Baseline mode: record current violations (the tool's baseline or suppressions file, or a generated per-file count) so only new violations fail; strict mode: list how many violations exist and which files need extraction first.
7. Wire it into CI on pull requests, scoped to changed files when the tool supports it, and keep the failure message actionable (which string, which rule, how to fix).
8. Run the lint, report counts before and after configuration, and sample ten flagged items to confirm they are true positives.
</task>
<constraints>
- Do not extract or rewrite strings in this run; add checks only.
- Do not turn the rule on as a warning that nobody reads; it must fail CI for new violations.
- Do not add a blanket disable to make the run pass.
- Pin config to the plugin version already installed or the one you add; do not quote rule options you have not checked in that plugin's docs or source.
{{> output/uncertainty}}
</constraints>
<output_format>
## Tools chosen
Per ecosystem, with the reason.
## Configuration
Config diffs.
## Allowlist
Entries with reasons.
## Baseline
How existing violations are recorded and counted.
## CI wiring
The CI change.
## Verification
Counts before and after, and the sampled true and false positives.
</output_format>可替换内容
- {{repo_scope}}
- {{#ci}}
- {{ci}}
- {{/ci}}
- {{mode}}
- {{> output/uncertainty}}
分类与标签
编程开发、代码质量、国际化检查、Lint配置、持续集成