Skip to content

Add a lint rule to detect unused formatted resources - #716

Merged
theisenp merged 1 commit into
mainfrom
unused-formatted-resource-lint
Jul 31, 2026
Merged

Add a lint rule to detect unused formatted resources#716
theisenp merged 1 commit into
mainfrom
unused-formatted-resource-lint

Conversation

@theisenp

@theisenp theisenp commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

In #649 we changed the way Paraphrase generates FormattedResources, so that instead of generating a reference to all strings with ICU arguments, it generates a reference to all strings full stop. That helps catch some correctness issues, but it also exacerbated a quirk in the way that Paraphrase interacts with lint.

Paraphrase breaks the standard Android UnusedResources lint in a couple ways:

  • When checkGeneratedSources is disabled, lint reports false positives because it doesn't see resource references in the generated FormattedResources object.
  • When checkGeneratedSources is enabled, lint reports false negatives because every resource is technically referenced in the generated FormattedResources object.

I'm proposing a new UnusedFormattedResources lint rule to address the problem. Basically it's a version of UnusedResources that's Paraphrase-aware:

  • It records string declarations
  • It counts a reference via FormattedResources as a usage of the underlying string
  • If doesn't consider references in FormattedResources itself as sufficient to mark a string as used

I'm sure this implementation is missing some nuances, but it at least seems work when I locally apply it to Cash App, so I think it's a reasonable starting point, and we can iterate as issues arise.

@theisenp
theisenp force-pushed the unused-formatted-resource-lint branch from e13ed1b to 5e69760 Compare July 2, 2026 19:06
Comment thread lint/src/main/java/app/cash/paraphrase/lint/UnusedFormattedResourcesDetector.kt Outdated
@theisenp
theisenp force-pushed the unused-formatted-resource-lint branch 2 times, most recently from ef8ba1f to 08fdaa5 Compare July 2, 2026 19:38
@theisenp
theisenp marked this pull request as ready for review July 2, 2026 19:38
Comment thread lint/src/main/java/app/cash/paraphrase/lint/UnusedFormattedResourcesDetector.kt Outdated
@theisenp
theisenp force-pushed the unused-formatted-resource-lint branch from 08fdaa5 to 2845493 Compare July 6, 2026 18:11
@theisenp
theisenp force-pushed the unused-formatted-resource-lint branch from 2845493 to c2a52eb Compare July 31, 2026 21:09
@theisenp
theisenp force-pushed the unused-formatted-resource-lint branch from c2a52eb to fe4a53e Compare July 31, 2026 23:27
@theisenp
theisenp enabled auto-merge July 31, 2026 23:28
@theisenp
theisenp merged commit 860535c into main Jul 31, 2026
5 checks passed
@theisenp
theisenp deleted the unused-formatted-resource-lint branch July 31, 2026 23:32
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