diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 11f8480..1747fbd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -138,6 +138,9 @@ android { detekt { baseline = file("detekt-baseline.xml") + config.setFrom("$rootDir/detekt.yml") + buildUponDefaultConfig = true + allRules = false } dependencies { @@ -146,4 +149,5 @@ dependencies { implementation(libs.bundles.lifecycle) implementation(libs.bundles.compose) debugImplementation(libs.bundles.compose.preview) + detektPlugins(libs.compose.detekt) } diff --git a/app/detekt-baseline.xml b/app/detekt-baseline.xml index 6fef685..9c390c2 100644 --- a/app/detekt-baseline.xml +++ b/app/detekt-baseline.xml @@ -1,56 +1,21 @@ - + - FunctionNaming:Activity.kt$@Composable fun CheckFeatureLocked( skipCheck: Boolean ) - FunctionNaming:BrightDisplayActivity.kt$BrightDisplayActivity$@Composable private fun ScreenContent(onChangeColorButtonPress: () -> Unit) - FunctionNaming:BrightDisplayScreen.kt$@Composable @MyDevices private fun BrightDisplayScreenPreview() - FunctionNaming:BrightDisplayScreen.kt$@Composable internal fun BrightDisplayScreen( backgroundColor: Int, contrastColor: Int, onChangeColorPress: () -> Unit, sleepTimer: @Composable () -> Unit ) - FunctionNaming:MainActivity.kt$MainActivity$@Composable private fun AppLaunched( donateAlertDialogState: AlertDialogState = getDonateAlertDialogState(), rateStarsAlertDialogState: AlertDialogState = getRateStarsAlertDialogState(), ) - FunctionNaming:MainActivity.kt$MainActivity$@Composable private fun SleepTimerRadioDialog( alertDialogState: AlertDialogState, onCustomValueSelected: () -> Unit ) - FunctionNaming:MainScreen.kt$@Composable @MyDevices internal fun MainScreenPreview() - FunctionNaming:MainScreen.kt$@Composable internal fun BrightDisplayButton( onBrightDisplayPress: () -> Unit, ) - FunctionNaming:MainScreen.kt$@Composable internal fun FlashlightButton( flashlightActive: Boolean, onFlashlightPress: () -> Unit, ) - FunctionNaming:MainScreen.kt$@Composable internal fun MainScreen( flashlightButton: @Composable () -> Unit, brightDisplayButton: @Composable () -> Unit, sosButton: @Composable () -> Unit, stroboscopeButton: @Composable () -> Unit, slidersSection: @Composable () -> Unit, sleepTimer: @Composable () -> Unit, showMoreApps: Boolean, openSettings: () -> Unit, openAbout: () -> Unit, openSleepTimer: () -> Unit, moreAppsFromUs: () -> Unit, ) - FunctionNaming:MainScreen.kt$@Composable internal fun MainScreenSlidersSection( showBrightnessBar: Boolean, brightnessBarValue: Float, onBrightnessBarValueChange: (Float) -> Unit, showStroboscopeBar: Boolean, stroboscopeBarValue: Float, onStroboscopeBarValueChange: (Float) -> Unit, ) - FunctionNaming:MainScreen.kt$@Composable internal fun SosButton( sosActive: Boolean, onSosButtonPress: () -> Unit, ) - FunctionNaming:MainScreen.kt$@Composable internal fun StroboscopeButton( stroboscopeActive: Boolean, onStroboscopeButtonPress: () -> Unit, ) - FunctionNaming:MainScreen.kt$@Composable private fun SmallButton( painter: Painter, contentDescription: String, isActive: Boolean, onPress: () -> Unit ) - FunctionNaming:SettingsScreen.kt$@Composable @MyDevices private fun SettingsScreenPreview() - FunctionNaming:SettingsScreen.kt$@Composable internal fun ColorCustomizationSettingsSection( customizeColors: () -> Unit, customizeWidgetColors: () -> Unit, ) - FunctionNaming:SettingsScreen.kt$@Composable internal fun GeneralSettingsSection( showUseEnglish: Boolean, useEnglishChecked: Boolean, showDisplayLanguage: Boolean, displayLanguage: String, turnFlashlightOnStartupChecked: Boolean, forcePortraitModeChecked: Boolean, showBrightDisplayButtonChecked: Boolean, showSosButtonChecked: Boolean, showStroboscopeButtonChecked: Boolean, onUseEnglishPress: (Boolean) -> Unit, onSetupLanguagePress: () -> Unit, onTurnFlashlightOnStartupPress: (Boolean) -> Unit, onForcePortraitModePress: (Boolean) -> Unit, onShowBrightDisplayButtonPress: (Boolean) -> Unit, onShowSosButtonPress: (Boolean) -> Unit, onShowStroboscopeButtonPress: (Boolean) -> Unit, ) - FunctionNaming:SettingsScreen.kt$@Composable internal fun SettingsScreen( colorCustomizationSection: @Composable () -> Unit, generalSection: @Composable () -> Unit, goBack: () -> Unit, ) - FunctionNaming:SleepTimer.kt$@Composable @MyDevices internal fun SleepTimerPreview() - FunctionNaming:SleepTimer.kt$@Composable internal fun AnimatedSleepTimer( modifier: Modifier = Modifier, timerText: String, timerVisible: Boolean, onTimerClosePress: () -> Unit ) - FunctionNaming:SleepTimer.kt$@Composable internal fun SleepTimer( modifier: Modifier = Modifier, timerText: String, onCloseClick: () -> Unit ) - FunctionNaming:SleepTimerCustomAlertDialog.kt$@Composable @MyDevices private fun SleepTimerCustomAlertDialogPreview() - FunctionNaming:SleepTimerCustomAlertDialog.kt$@Composable fun SleepTimerCustomAlertDialog( alertDialogState: AlertDialogState, modifier: Modifier = Modifier, onConfirmClick: (seconds: Int) -> Unit, onCancelClick: (() -> Unit)? = null ) - FunctionNaming:WidgetConfigureScreen.kt$@Composable @MyDevices private fun WidgetBrightDisplayConfigureScreenPreview() - FunctionNaming:WidgetConfigureScreen.kt$@Composable internal fun WidgetConfigureScreen( @DrawableRes widgetDrawable: Int, @ColorInt widgetColor: Int, widgetAlpha: Float, onSliderChanged: (Float) -> Unit, onColorPressed: () -> Unit, onSavePressed: () -> Unit ) - LongMethod:MainActivity.kt$MainActivity$override fun onCreate(savedInstanceState: Bundle?) - LongMethod:SettingsActivity.kt$SettingsActivity$override fun onCreate(savedInstanceState: Bundle?) - LongMethod:SleepTimerCustomAlertDialog.kt$@Composable fun SleepTimerCustomAlertDialog( alertDialogState: AlertDialogState, modifier: Modifier = Modifier, onConfirmClick: (seconds: Int) -> Unit, onCancelClick: (() -> Unit)? = null ) - LongParameterList:Activity.kt$( appNameId: Int, licenseMask: Long, versionName: String, faqItems: ArrayList<FAQItem>, showFAQBeforeMail: Boolean, getAppIconIDs: ArrayList<Int> = getAppIconIDs(), getAppLauncherName: String = launcherName() ) - LongParameterList:MainScreen.kt$( flashlightButton: @Composable () -> Unit, brightDisplayButton: @Composable () -> Unit, sosButton: @Composable () -> Unit, stroboscopeButton: @Composable () -> Unit, slidersSection: @Composable () -> Unit, sleepTimer: @Composable () -> Unit, showMoreApps: Boolean, openSettings: () -> Unit, openAbout: () -> Unit, openSleepTimer: () -> Unit, moreAppsFromUs: () -> Unit, ) - LongParameterList:MainScreen.kt$( showBrightnessBar: Boolean, brightnessBarValue: Float, onBrightnessBarValueChange: (Float) -> Unit, showStroboscopeBar: Boolean, stroboscopeBarValue: Float, onStroboscopeBarValueChange: (Float) -> Unit, ) - LongParameterList:SettingsScreen.kt$( showUseEnglish: Boolean, useEnglishChecked: Boolean, showDisplayLanguage: Boolean, displayLanguage: String, turnFlashlightOnStartupChecked: Boolean, forcePortraitModeChecked: Boolean, showBrightDisplayButtonChecked: Boolean, showSosButtonChecked: Boolean, showStroboscopeButtonChecked: Boolean, onUseEnglishPress: (Boolean) -> Unit, onSetupLanguagePress: () -> Unit, onTurnFlashlightOnStartupPress: (Boolean) -> Unit, onForcePortraitModePress: (Boolean) -> Unit, onShowBrightDisplayButtonPress: (Boolean) -> Unit, onShowSosButtonPress: (Boolean) -> Unit, onShowStroboscopeButtonPress: (Boolean) -> Unit, ) - LongParameterList:WidgetConfigureScreen.kt$( @DrawableRes widgetDrawable: Int, @ColorInt widgetColor: Int, widgetAlpha: Float, onSliderChanged: (Float) -> Unit, onColorPressed: () -> Unit, onSavePressed: () -> Unit ) - MagicNumber:Config.kt$Config$1000 - MagicNumber:Config.kt$Config$1000L + ComposableParamOrder:SleepTimer.kt$AnimatedSleepTimer + ComposableParamOrder:SleepTimer.kt$SleepTimer + ComposableParamOrder:SleepTimerCustomAlertDialog.kt$SleepTimerCustomAlertDialog + LambdaParameterEventTrailing:SleepTimer.kt$onCloseClick + LambdaParameterEventTrailing:SleepTimer.kt$onTimerClosePress MagicNumber:Config.kt$Config$30 MagicNumber:Config.kt$Config$60 MagicNumber:Context.kt$60 MagicNumber:MainActivity.kt$MainActivity$10 - MagicNumber:MainActivity.kt$MainActivity$1000 MagicNumber:MainActivity.kt$MainActivity$30 MagicNumber:MainActivity.kt$MainActivity$3600 MagicNumber:MainActivity.kt$MainActivity$5 MagicNumber:MainActivity.kt$MainActivity$60 MagicNumber:MainActivity.kt$MainActivity.MainViewModel$0.5f - MagicNumber:MyCameraImpl.kt$MyCameraImpl$1000L - MagicNumber:SleepTimer.kt$SleepTimer$1000L - MagicNumber:SleepTimer.kt$SleepTimer.<no name provided>$1000 - MagicNumber:SleepTimerCustomAlertDialog.kt$60 MagicNumber:WidgetConfigureViewModel.kt$WidgetConfigureViewModel$255f MaxLineLength:BrightDisplayActivity.kt$BrightDisplayActivity$AnimatedSleepTimer(timerText = timerText, timerVisible = timerVisible, onTimerClosePress = ::stopSleepTimer) MaxLineLength:BrightDisplayActivity.kt$BrightDisplayActivity$requestedOrientation = if (config.forcePortraitMode) ActivityInfo.SCREEN_ORIENTATION_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_SENSOR @@ -96,6 +61,11 @@ MaxLineLength:WidgetConfigureViewModel.kt$WidgetConfigureViewModel$if MaxLineLength:WidgetTorchConfigureActivity.kt$WidgetTorchConfigureActivity$viewModel.setWidgetId(intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID) MemberNameEqualsClassName:SleepTimer.kt$SleepTimer$private var sleepTimer: CountDownTimer? = null + MultipleEmitters:MainScreen.kt$MainScreenSlidersSection + ParameterNaming:MainActivity.kt$MainActivity$onCustomValueSelected + ParameterNaming:WidgetConfigureScreen.kt$onColorPressed + ParameterNaming:WidgetConfigureScreen.kt$onSavePressed + ParameterNaming:WidgetConfigureScreen.kt$onSliderChanged ReturnCount:MyCameraImpl.kt$MyCameraImpl$fun toggleSOS(): Boolean ReturnCount:MyCameraImpl.kt$MyCameraImpl$fun toggleStroboscope(): Boolean SwallowedException:Activity.kt$e: Exception diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml index c07be50..083d8a5 100644 --- a/app/lint-baseline.xml +++ b/app/lint-baseline.xml @@ -37,7 +37,7 @@ errorLine2=" ~~~~"> @@ -85,6 +85,17 @@ column="17"/> + + + + @@ -103,7 +114,7 @@ errorLine2=" ~~~~~~~"> @@ -114,7 +125,7 @@ errorLine2=" ~~~~~~~"> @@ -125,7 +136,7 @@ errorLine2=" ~~~~~~~"> @@ -136,7 +147,7 @@ errorLine2=" ~~~~~~~"> @@ -147,7 +158,7 @@ errorLine2=" ~~~~~~~"> @@ -158,7 +169,7 @@ errorLine2=" ~~~~~~~"> @@ -169,7 +180,7 @@ errorLine2=" ~~~~~~~"> @@ -180,7 +191,7 @@ errorLine2=" ~~~~~~~"> @@ -191,7 +202,7 @@ errorLine2=" ~~~~~~~"> @@ -202,18 +213,18 @@ errorLine2=" ~~~~~~~"> diff --git a/detekt.yml b/detekt.yml new file mode 100644 index 0000000..6472c5a --- /dev/null +++ b/detekt.yml @@ -0,0 +1,58 @@ +build: + maxIssues: 0 + weights: + complexity: 2 + LongParameterList: 2 + style: 1 + +processors: + active: true + exclude: + - "FunctionCountProcessor" + - "PropertyCountProcessor" + +config: + validation: true + +complexity: + LongParameterList: + active: true + functionThreshold: 10 + constructorThreshold: 8 + ignoreDefaultParameters: true + ignoreAnnotated: + - "Composable" + LongMethod: + active: true + threshold: 120 + ignoreAnnotated: + - "Composable" + - "Preview" + +style: + MagicNumber: + active: true + ignoreAnnotated: ["Composable"] + ignoreEnums: true + ignoreNumbers: ["-1", "0", "1", "2", "42", "1000"] + MaxLineLength: + active: true + maxLineLength: 120 + excludePackageStatements: true + excludeImportStatements: true + +naming: + FunctionNaming: + active: true + ignoreAnnotated: ["Composable", "Preview"] + functionPattern: "[a-z][A-Za-z0-9]*" + +Compose: # io.nlopez.compose.rules + ComposableParametersOrdering: + active: true + ModifierDefaultValue: + active: true + MissingModifierDefaultValue: + active: true + PublicComposablePreview: + active: true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e73284c..86b2e66 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,6 +3,7 @@ kotlin = "2.2.0" #Detekt detekt = "1.23.8" +detektCompose = "0.4.22" #AndroidX androidx-customView = "1.2.0" androidx-customViewPooling = "1.1.0" @@ -43,6 +44,7 @@ compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" } compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" } compose-uiTooling-debug = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } compose-uiTooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } +compose-detekt = { module = "io.nlopez.compose.rules:detekt", version.ref = "detektCompose" } [bundles] compose = [ "compose-activity", diff --git a/lint.xml b/lint.xml index 05685cd..4b4a782 100644 --- a/lint.xml +++ b/lint.xml @@ -31,4 +31,5 @@ +