In our Android Studio project we are using Kotlin 1.5.21 and Jetpack Compose. While analyzing it in SonarCloud.io. We are using the SonarQube scanner 3.3 and have starting to see issues with unused imports false positives since the SonarCloud update on 9-16.
Products Used
- SonarCloud - Problem started to occur after the update on 9-16
- SonarScanner for Gradle 3.3
- SonarLint 5.3.0.36775 for Android Studio
Example False Positive Unused Imports
These are all related to Jetpack Compose.
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
If we remove the getValue import then the following lines of code will not compile.
var displayedMonth by remember { mutableStateOf(DateTimeUtil.dfMonthYear.format(LocalDate.now())) }
var daySelected by remember { mutableStateOf(scheduleViewModel.selectedDate) }
val calendarItemsUpdated by scheduleViewModel.calendarUpdatedLiveData.observeAsState()
If we remove the setValue import the following lines of code will not compile.
var displayedMonth by remember { mutableStateOf(DateTimeUtil.dfMonthYear.format(LocalDate.now())) }
var daySelected by remember { mutableStateOf(scheduleViewModel.selectedDate) }
if we remove the Alignment import the following lines of code will not compile.
.align(Alignment.CenterVertically),
Text(
modifier = Modifier
.wrapContentHeight()
.align(Alignment.CenterVertically),
text = stringResource(id = R.string.back),
fontWeight = FontWeight.Medium,
color = JobNimbusDarkGray)
If we remove the Color import the following lines will not compile.
ButtonDefaults.buttonColors(
backgroundColor = Color.Transparent,
disabledBackgroundColor = Color.Transparent
If we remove the FontWeight import the following lines will not compile.
fontWeight = FontWeight.Medium,
Text(
modifier = Modifier
.wrapContentHeight()
.align(Alignment.CenterVertically),
text = stringResource(id = R.string.back),
fontWeight = FontWeight.Medium,
color = JobNimbusDarkGray)