Wrong Layout Name

ID

kotlin.android_wrong_layout_name

Severity

info

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Kotlin

Tags

android, naming

Description

Flags Android layout files whose file name does not follow the recommended <type>_<name> convention, where <type> is one of: activity, fragment, item, dialog, view or widget.

Rationale

A consistent layout naming convention makes it easy to scan res/layout/ and tell at a glance whether a file backs an activity, a fragment, a list item, a dialog, a reusable view or a widget. The Android team’s documentation and the community-standard ribot guidelines recommend the <type>_<name>.xml form.

# Bad: prefix "screen" is not a recognised type
res/layout/screen_main.xml

# Good: prefix "activity" is a recognised type
res/layout/activity_main.xml

To keep false positives low, the rule only flags files whose name contains at least one underscore (so the developer clearly intended a prefix). Files with no underscore are assumed to be project-specific and are skipped. Files starting with abc_ are skipped because they are generated by AppCompat.

Remediation

Rename the file so its prefix matches one of the recognised types.

git mv res/layout/screen_main.xml res/layout/activity_main.xml