diktat
diktat copied to clipboard
False positive finding for rule [FILE_UNORDERED_IMPORTS]
[FILE_UNORDERED_IMPORTS] imports should be ordered alphabetically and shouldn't be separated by newlines: import android.bluetooth.BluetoothAdapter...
This is what Android Studio expects (right click on file --> Optimize Imports) and diktatCheck complains:
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Context.BLUETOOTH_SERVICE
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.util.Log
import de.example.common.jvm.util.whenNotNull
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn
import java.lang.Short.MIN_VALUE
This is what diktatFix is doing:
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Context.BLUETOOTH_SERVICE
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.util.Log
import de.example.common.jvm.util.whenNotNull
import java.lang.Short.MIN_VALUE
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn
ok sorry, after checking the convention guide I noticed this is the correct behavior of diktat.
I have these grouping never seen before. No android source code out there does this grouping with separated lines. I'm just wondering.
BUT... This is not the format Android Studio expects when it optimizes the imports (right click on file --> Optimize Imports). Any thoughts about that?
AND... Why does diktatCheck not find and fix those imports?:
...
import androidx.compose.ui.unit.sp
import de.example.common.android.compose.theme.MyTheme
It does not find it but according to coding guide it should find it and suggest a new line.
ok sorry, after checking the convention guide I noticed this is the correct behavior of diktat.
yeah, android development guides sometimes differ from backend/kotlinJS development.
This inspection was suggested to us by two very big international companies (one from Asia and the other from Europe). They are using such convention
Any ideas why it does not warn about the last example?
Any ideas why it does not warn about the last example?
Looks like we haven’t added androidx to the inspection and the code style. It goes to other and is grouped with remaining imports
@petertrr could please also check why we ignore org.cqfn.diktat in AstNodeUtils.kt and group them together?
We also have a flag to disable this grouping, since it's indeed sometimes a controversial style:
https://github.com/saveourtool/diktat/blob/9e3b5cb7d1a84e103ad5020bed096279ad373eb1/diktat-rules/src/main/resources/diktat-analysis.yml#L160-L162
Setting useRecommendedImportsOrder to false will only keep alphabetical ordering without grouping
Good to know. Thanks @petertrr :)
@akuleshov7 I guess it can be closed