glide icon indicating copy to clipboard operation
glide copied to clipboard

Lint check for `Glide.with(view)`

Open nikclayton opened this issue 6 months ago • 0 comments

Hi,

Reading https://github.com/bumptech/glide/issues/898 it seems like (in many cases) Glide.with(view) is a potential foot-gun, and it would be better to use with passing an activity or fragment.

I've done this refactoring in my own project over in https://github.com/pachli/pachli-android/pull/1519, and as part of that I wrote a Lint detection rule to flag these.

I thought you might want to take this and bundle it as an (ignorable) lint check in Glide (details on publishing custom lint rules in a library project at https://github.com/googlesamples/android-custom-lint-rules).

The relevant parts of that PR are:

  • The lint detector, https://github.com/nikclayton/pachli-android/blob/glide-cleanup/checks/src/main/java/app/pachli/lint/checks/GlideWithViewDetector.kt
  • One test case, https://github.com/nikclayton/pachli-android/blob/glide-cleanup/checks/src/test/java/app/pachli/lint/checks/GlideWithViewDetectorTest.kt

You can also copy the entire lint machinery from https://github.com/nikclayton/pachli-android/tree/glide-cleanup/checks and delete the files not relevant to the project.

nikclayton avatar May 07 '25 12:05 nikclayton