Skip to content

Commit

Permalink
Fix more detekt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaygaba committed Dec 11, 2024
1 parent d13b00f commit 9db4375
Show file tree
Hide file tree
Showing 40 changed files with 104 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package com.airbnb.android.showkase.annotation
import kotlin.reflect.KClass

/**
* Used by the annotation processor internally to generate metadata files. This won't ever be
* needed by any users of Showkase.
*
* Used by the annotation processor internally to generate metadata files. This won't ever be
* needed by any users of Showkase.
*
* @param packageSimpleName Name of the module that the @Composable function belongs to
* @param packageName Name of the package that the @Composable function was declared in
* @param showkaseElementName Method name of the @Composable function
* @param showkaseName User defined name for the @Composable component to render inside
* the Showkase browser
* @param showkaseGroup User defined grouping key that will be used to group it with
* @param showkaseGroup User defined grouping key that will be used to group it with
* other @Composable functions.
* @param enclosingClass If the @Composable function is defined inside a class, the KClass of the
* wrapper class is stored in the array. Otherwise the array is empty.
* @param showkaseWidthDp The width that your component will be rendered in inside the
* @param showkaseWidthDp The width that your component will be rendered in inside the
* Showkase browser. Use this to restrict the size of your preview inside the Showkase browser.
* @param showkaseHeightDp The height that your component will be rendered in inside the
* Showkase browser. Use this to restrict the size of your preview inside the Showkase browser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package com.airbnb.android.showkase.annotation
*
* @ShowkaseColor(name = "Name", group = "Group")
* val redColor = Color.Red
*
*
* @ShowkaseColor("Primary", "Light Colors")
* val primaryColor = Color(0xFF6200EE)
*
* @param name The name that should be used to describe your `Color` fields. If you don't pass
* @param name The name that should be used to describe your `Color` fields. If you don't pass
* any value, the name of the color field is used as the name.
* @param group The grouping key that will be used to group it with other `Color` fields. This is
* useful for better organization and discoverability of your colors. If you don't pass any value
* for the group, the name of the class that wraps this field is used as the group name. If the
* for the group, the name of the class that wraps this field is used as the group name. If the
* field is a top level field, the color is added to a "Default Group".
*/
@MustBeDocumented
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package com.airbnb.android.showkase.annotation

/**
* Used to annotate @Composable functions that should be displayed inside the
* Used to annotate @Composable functions that should be displayed inside the
* Showkase browser. Here's how you would use it with your @Composable function:
*
*
* @ShowkaseComposable(name = "Name", group = "Group")
* @Composable
* fun MyComposable() {
* .......
* .......
* }
*
*
* <p>
* Note: Make sure that you add this annotation to only those functions that don't accept any
* parameters. If your function accepts a parameters, wrap it inside another function that doesn't
* accept any parameters.
*
* Note: Make sure that you add this annotation to only those functions that don't accept any
* parameters. If your function accepts a parameters, wrap it inside another function that doesn't
* accept any parameters.
*
* For example, here is a @Composable function that requires parameters -
*
* @Composable
* fun MyComposable(name: String) {
* .......
* .......
* }
*
* In order to make this function compatible with Showkase, you could further wrap this function
*
* In order to make this function compatible with Showkase, you could further wrap this function
* inside a method that doesn't accept a parameters in the following way:
*
*
* @ShowkaseComposable(name = "Name", group = "Group")
* @Composable
* fun MyComposablePreview() {
* MyComposable("Name")
* }
*
* This requirement is even needed by the @Preview functions of Jetpack Compose.
*
*
* This requirement is even needed by the @Preview functions of Jetpack Compose.
*
* @param name The name that should be used to describe your `@Composable` function. If you don't
* pass any value, the name of the composable function is used as the name.
* @param group The grouping key that will be used to group it with other `@Composable` functions
* . This is useful for better organization and discoverability of your components. If you don't
* pass any value for the group, the name of the class that wraps this function is used as the
* . This is useful for better organization and discoverability of your components. If you don't
* pass any value for the group, the name of the class that wraps this function is used as the
* group name. If the function is a top level function, the composable is added to a "Default Group".
* @param widthDp The width that your component will be rendered in inside the Showkase browser.
* @param widthDp The width that your component will be rendered in inside the Showkase browser.
* Use this to restrict the size of your preview inside the Showkase browser.
* @param heightDp The height that your component will be rendered in inside the Showkase browser.
* Use this to restrict the size of your preview inside the Showkase browser.
* @param skip Use this boolean when you want to skip this composable from the Showkase browser. A
* @param skip Use this boolean when you want to skip this composable from the Showkase browser. A
* use case of this might be when you want a composable that's annotated with @Preview to show previews
* in Android Studio but don't want to necessary show it in the component browser that's autogenerated
* by Showkase
* @param defaultStyle Used to represent a composable function is the default style variant of a given
* @param defaultStyle Used to represent a composable function is the default style variant of a given
* composable. More information on how Showkase allows you to represent component styles in this section -
* https://github.com/airbnb/Showkase#representing-component-styles-in-showkase
* @param tags Various string values that will be propagated to the Showkase browser to allow additional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package com.airbnb.android.showkase.annotation

/**
* Used to annotate the [ShowkaseRootModule] implementation class. This is needed to let Showkase
* know more about the module that is going to be the root module for aggregating all the Showkase
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* know more about the module that is going to be the root module for aggregating all the Showkase
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* are allowed to have only one @ShowkaseRoot per module.
*
*
* <p>
* Here's an example of how you would use it:
*
* @ShowkaseRoot
* fun MyRootModule: ShowkaseRootModule
*
*
* <p>
* The root module that you declare is also important to start the Showkase browser in order to
* The root module that you declare is also important to start the Showkase browser in order to
* view your composables. You will have to pass in the canonical name of this implementation when
* starting the [ShowkaseBrowserActiity]. Here's is how you would do it:
*
*
* startActivity(ShowkaseBrowserActivity.getIntent(this, MyRootModule::class.java.canonicalName!!))
*/
@MustBeDocumented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.airbnb.android.showkase.annotation
/**
* Interface used to declare the root class for a module. This is needed to let Showkase
* know more about the module that is going to be the root module for aggregating all the Showkase
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* are allowed to have only one @ShowkaseRoot per module.
*
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.airbnb.android.showkase.annotation

import kotlin.reflect.KClass


/**
* Used to annotate the [ShowkaseScreenshotTest] implementation class. This is needed to let
* Showkase know that it needs to generate screenshot tests for your UI elements that are integrated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package com.airbnb.android.showkase.annotation
* letterSpacing = (-1.5).sp
* )
*
* @param name The name that should be used to describe your `TextStyle` fields. If you don't
* @param name The name that should be used to describe your `TextStyle` fields. If you don't
* pass any value, the name of the textStyle field is used as the name.
* @param group The grouping key that will be used to group it with other `TextStyle` fields.
* This is useful for better organization and discoverability of your typography. If you don't
* @param group The grouping key that will be used to group it with other `TextStyle` fields.
* This is useful for better organization and discoverability of your typography. If you don't
* pass any value for the group, the name of the class that wraps this field is used as the group
* name. If the field is a top level field, the textStyle is added to a "Default Group".
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")

package com.vinaygaba.showkase_browser_testing_submodule.two

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")

package com.vinaygaba.showkase_browser_testing_submodule

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")

package com.vinaygaba.showkase_browser_testing_submodule

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")
package com.airbnb.android.showkase_browser_testing

import androidx.compose.ui.graphics.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")
package com.airbnb.android.showkase_browser_testing

import android.content.res.Configuration
Expand Down Expand Up @@ -69,7 +69,6 @@ fun TestComposable8() {
BasicText(text = "Test Composable9and10")
}


@Preview(
name = "Custom Text Light",
group = "Button",
Expand Down Expand Up @@ -107,7 +106,6 @@ fun PreviewText() {
BasicText(text = "Some text")
}


@EnglishLocalePreview
@Composable
fun PreviewEnglishText() {
Expand All @@ -121,4 +119,4 @@ private fun PrivateTextComposable() {
}

@ShowkaseRoot
class MyRootModule: ShowkaseRootModule
class MyRootModule : ShowkaseRootModule
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")
package com.airbnb.android.showkase_browser_testing

import androidx.compose.ui.text.TextStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("PackageName")
package com.airbnb.android.showkase_processor_testing

import com.airbnb.android.showkase.processor.ShowkaseProcessor
Expand Down Expand Up @@ -82,7 +83,7 @@ abstract class BaseProcessorTest {

@OptIn(ExperimentalCompilerApi::class)
protected fun compileInputsAndVerifyOutputs(
modes:List<Mode> = listOf(Mode.KSP, Mode.KAPT),
modes: List<Mode> = listOf(Mode.KSP, Mode.KAPT),
options: MutableMap<String, String> = mutableMapOf(),
) {
compileInputs(modes = modes, options = options) { mode, compilation, result ->
Expand Down Expand Up @@ -142,6 +143,6 @@ abstract class BaseProcessorTest {
.replace(" ", "_")

val className = testNameRule.className.substringAfterLast(".")
return File(rootResourcesDir, "$className/${methodName}")
return File(rootResourcesDir, "$className/$methodName")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("MaxLineLength", "PackageName")
package com.airbnb.android.showkase_processor_testing

import org.junit.Test
Expand Down Expand Up @@ -436,7 +437,6 @@ class ShowkaseProcessorTest : BaseProcessorTest() {
compileInputsAndVerifyOutputs()
}


@Test
fun `function inside object with preview annotation and no name or group`() {
compileInputsAndVerifyOutputs()
Expand Down Expand Up @@ -497,7 +497,6 @@ class ShowkaseProcessorTest : BaseProcessorTest() {
compileInputsAndVerifyOutputs()
}


@Test
fun `wrapped function with showkase composable and preview parameter and showkaseroot `() {
compileInputsAndVerifyOutputs()
Expand Down Expand Up @@ -580,12 +579,12 @@ class ShowkaseProcessorTest : BaseProcessorTest() {

@Test
fun `composable function with custom preview annotation generates output`() {
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP))
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP))
}

@Test
fun `composable function with custom preview annotation with preview param generates output`() {
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP))
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP))
}

@Test
Expand Down Expand Up @@ -621,4 +620,3 @@ class ShowkaseProcessorTest : BaseProcessorTest() {
compileInputsAndVerifyOutputs(options = options)
}
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("PackageName")
package com.airbnb.android.showkase_processor_testing

import org.junit.rules.TestWatcher
Expand All @@ -19,4 +20,4 @@ class TestNameRule : TestWatcher() {
methodName = d.methodName
className = d.className
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ShowkaseProcessor @JvmOverloads constructor(
private val logger = ShowkaseExceptionLogger()
private val showkaseValidator by lazy { ShowkaseValidator(environment) }

override fun getSupportedAnnotationTypes(): MutableSet<String> {
override fun getSupportedAnnotationTypes(): MutableSet<String> {
val supportedAnnotations = mutableSetOf(
ShowkaseComposable::class.java.name,
PREVIEW_CLASS_NAME,
Expand Down Expand Up @@ -126,7 +126,6 @@ class ShowkaseProcessor @JvmOverloads constructor(
}.flatten().mapNotNull { it }.toSet()
}


private fun processPreviewAnnotation(roundEnvironment: XRoundEnv): Set<ShowkaseMetadata.Component> {
val skipPrivatePreviews = environment.options["skipPrivatePreviews"] == "true"
val skipComposePreviews = environment.options["skipComposePreviews"] == "true"
Expand Down Expand Up @@ -157,7 +156,6 @@ class ShowkaseProcessor @JvmOverloads constructor(
element = element,
showkaseValidator = showkaseValidator
)

}.flatten().mapNotNull { it }.toSet()
}

Expand Down Expand Up @@ -252,7 +250,6 @@ class ShowkaseProcessor @JvmOverloads constructor(
)
)
}

}
}
return components
Expand Down Expand Up @@ -523,7 +520,7 @@ class ShowkaseProcessor @JvmOverloads constructor(
element = element,
propertyName = props.generatedPropertyName,
propertyPackage = props.packageName,
type = when(type) {
type = when (type) {
ShowkaseMetadataType.COLOR -> ShowkaseGeneratedMetadataType.COLOR
ShowkaseMetadataType.TYPOGRAPHY -> ShowkaseGeneratedMetadataType.TYPOGRAPHY
ShowkaseMetadataType.COMPONENT -> if (previewParameterClassType != null) {
Expand Down Expand Up @@ -584,7 +581,7 @@ class ShowkaseProcessor @JvmOverloads constructor(
rootModulePackageName: String,
testClassName: String,
) {
when(screenshotTestType) {
when (screenshotTestType) {
// We only handle composables without preview parameter for screenshots. This is because
// there's no way to get information about how many previews are dynamically generated using
// preview parameter as it happens on run time and our codegen doesn't get enough information
Expand Down Expand Up @@ -654,4 +651,3 @@ internal enum class ScreenshotTestType {
SHOWKASE,
PAPARAZZI_SHOWKASE
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.airbnb.android.showkase.processor.exceptions

import androidx.room.compiler.processing.XElement

internal class ShowkaseProcessorException(message: String, val element: XElement? = null): Exception(message)
internal class ShowkaseProcessorException(message: String, val element: XElement? = null) : Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal class ShowkaseValidator(private val environment: XProcessingEnv) {
element
)
}
// Validate that only a single parameter is passed to these functions. In addition,
// Validate that only a single parameter is passed to these functions. In addition,
// the parameter should be annotated with @PreviewParameter.
validateComposableParameter(element) -> {
throw ShowkaseProcessorException(
Expand Down Expand Up @@ -241,8 +241,8 @@ internal class ShowkaseValidator(private val environment: XProcessingEnv) {
)
}
// TODO(vinay.gaba) Also add the private modifier check. Unfortunately, the java code
// for this element adds a private modifier since it's a field. Potentially use
// kotlinMetadata to enforce this check.
// for this element adds a private modifier since it's a field. Potentially use
// kotlinMetadata to enforce this check.
else -> {
}
}
Expand Down
Loading

0 comments on commit 9db4375

Please sign in to comment.