pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.06k stars 504 forks source link

Can't Suppress individual wildcard import #2681

Closed Lucky38i closed 3 weeks ago

Lucky38i commented 3 weeks ago

Expected Behavior

I expect to be able to suppress an individual wildcard import in accordance with the FAQ section. however, I'm getting compilation issues.

Observed Behavior

I'm attempting to suppress an individual wildcard import I have in a project. However, I'm getting an error imports are only allowed at the beginning of the file. Thus forcing me to do a file-wide suppression which is exactly what I don't want to do. Maybe I'm missing something silly but I'm not getting expected behaviour as shown in the FAQ page Screenshot 2024-06-04 at 11 11 00

Your Environment

paul-dingemans commented 3 weeks ago

That is an error in the documentation. Import statements can not be annotated in Kotlin. You need to use a file annotation like below:

@file:Suppress("ktlint:standard:no-wildcard-imports)

If you want to disable the rule for all files, it is better to disable it in the .editorconfig file (docs)