Skip to content

Update lint rules related to layout names prefixes#20317

Open
lukstbit wants to merge 2 commits intoankidroid:mainfrom
lukstbit:fix_updateLintRuleForLayoutNames
Open

Update lint rules related to layout names prefixes#20317
lukstbit wants to merge 2 commits intoankidroid:mainfrom
lukstbit:fix_updateLintRuleForLayoutNames

Conversation

@lukstbit
Copy link
Member

Purpose / Description

This is a proposal to simplify the previous layout prefixes lint rules. Feel free to reject.

The initial implementation for these rules is complex and a bit inefficient(we check all classes to see if it's one that we are interested in), but most important, it doesn't quite work when used with by viewBinding(ex: CheckPronunciationFragment).

To fix the above I created a new rule which uses a specific detector from lint to look only at layout names. It's much simpler and also gets applied for all layouts. The only downside is that we lose specificity: if we encounter a layout named fragment_random.xml it would be marked as correct but we can't see if it's actually used in a RandomFragment class.

Note: I didn't fix any of the raised issues(mostly to not introduce conflicts to existing PRs). Some need further discussions and I think we could also use them as a
Good First Issue

How Has This Been Tested?

Added a layout that would trigger the new rule.

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

The new lint rule checks the layout names directly.

Advantage of new rule vs. initial rules:
- simpler, only one class vs multiple classes in the initial implementation
- faster, new rule runs only against the layouts files not for every class
  in the project
- correct, all layouts with issues are marked

The disadvantage of new rule vs initial rules is that we lose the specificity
info about the prefix because we don't see where it's used. So a file named
"fragment_panel.xml" could be used as the layout for an activity while still
passing this check.

Note: this PR doesn't fix any of the current naming errors.
@lukstbit lukstbit changed the title Fix update lint rule for layout names Update lint rules related to layout names prefixes Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant