Update lint rules related to layout names prefixes#20317
Open
lukstbit wants to merge 2 commits intoankidroid:mainfrom
Open
Update lint rules related to layout names prefixes#20317lukstbit wants to merge 2 commits intoankidroid:mainfrom
lukstbit wants to merge 2 commits intoankidroid:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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