Skip to content

Qualify imports that hid their receiver - #3130

Merged
StylianosGakis merged 1 commit into
chore/delete-empty-lint-baselinesfrom
chore/qualify-namespace-imports
Sep 8, 2026
Merged

Qualify imports that hid their receiver#3130
StylianosGakis merged 1 commit into
chore/delete-empty-lint-baselinesfrom
chore/qualify-namespace-imports

Conversation

@StylianosGakis

@StylianosGakis StylianosGakis commented Sep 4, 2026

Copy link
Copy Markdown
Member

Fix all the wrongly imported places in the app manually, where we did string.foo rather than Res.string.foo as we've discussed in the past

🤖 AI description:

Fixes every existing violation of the import rule: 26 imports across 12 files. The rule itself and the ktlint check that enforces it are in the PR above, so this one is only hand-written source changes and can be read on its own.

The rule being applied. Import the type, never the namespace. An import may shorten a qualified reference only when the short name still says what it is to someone reading that line cold. HomeUiState.Success passes. Res.string and Clock.System do not: string.FOO names nothing, and System.now() reads as java.lang.System.

One was a latent bug rather than style. In TopAppBar.kt the identifier windowInsets meant two different things depending on where you read it. Three functions declare a windowInsets: WindowInsets = TopAppBarDefaults.windowInsets parameter and use it, so there the name is the parameter. TopAppBarLayoutForActions has no such parameter, so its bare windowInsets silently resolved to the file-level import ...TopAppBarDefaults.windowInsets instead, and only the compiler surfaced it once that import was gone.

No tooling catches this: the import is legitimately used at that one site, so no-unused-imports is right to stay quiet. It is exactly the readability failure the rule is about, since the same short name resolves to different things in one file.

For the 19 design system Defaults members the owning object lives in the same file, so they are now qualified as TooltipDefaults.defaultStyle, matching what TopAppBar.kt already did. References from inside an owning object's own body are untouched, since they resolve without an import.

ktlintCheck and ./gradlew lint both pass, and the touched modules compile.

Worth knowing for anyone repeating this kind of qualification: it has to cover lowercase resource names too, since string.general_close_button stops resolving once the Res.string import goes. ktlint cannot catch that, because it never compiles. Only a build does.

@StylianosGakis
StylianosGakis force-pushed the chore/qualify-namespace-imports branch from f27a011 to 5c2497e Compare September 4, 2026 13:48
@StylianosGakis StylianosGakis changed the title Import the type, never the namespace Qualify imports that hid their receiver Sep 4, 2026
@StylianosGakis
StylianosGakis force-pushed the chore/qualify-namespace-imports branch from 5c2497e to a452cac Compare September 4, 2026 14:26
@StylianosGakis
StylianosGakis changed the base branch from chore/lint-config-fixes to chore/delete-empty-lint-baselines September 4, 2026 14:27
@StylianosGakis
StylianosGakis force-pushed the chore/qualify-namespace-imports branch from a452cac to cd9a21c Compare September 4, 2026 16:52
@StylianosGakis
StylianosGakis marked this pull request as ready for review September 7, 2026 14:54
@StylianosGakis
StylianosGakis requested a review from a team as a code owner September 7, 2026 14:54
Fixes every existing violation of the import rule: 26 imports across 12
files.

Res.string.FOO and Clock.System.now() are restored at their use sites in
the feature files that had shortened them away. Nineteen of the rest are
design system Defaults members whose owning object lives in the same
file, so they are now qualified as TooltipDefaults.defaultStyle and the
like, matching what TopAppBar.kt already did. References from inside an
owning object's own body are untouched, since they resolve without an
import and gain nothing from the prefix.

TopAppBar.kt's import turned out to be unused except for one call in
TopAppBarLayoutForActions, which has no windowInsets parameter of its
own and was silently reading the import.
@StylianosGakis
StylianosGakis force-pushed the chore/qualify-namespace-imports branch from cd9a21c to 3ae370e Compare September 7, 2026 15:00
@StylianosGakis
StylianosGakis merged commit e57b29a into develop Sep 8, 2026
4 checks passed
@StylianosGakis
StylianosGakis deleted the chore/qualify-namespace-imports branch September 8, 2026 09:51
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.

2 participants