varabyte / kobweb-intellij-plugin

An official IntelliJ IDE plugin to include Kobweb-specific enhancements and understanding to your project
Apache License 2.0
10 stars 2 forks source link

Warn if user is using an attribute Modifier inside a ComponentStyle #7

Open bitspittle opened 5 months ago

bitspittle commented 5 months ago

Warn if a user is using an attribute modifer within a component style (and offer assistance to extract it to the extraModifiers parameter)

// Before
val SomeStyle by ComponentStyle.base {
   Modifier.id("id").size(...)
            ^^
            "id" is an attribute modifier and not valid inside a ComponentStyle, which can only reference style modifiers
}

// After refactoring
val SomeStyle by ComponentStyle.base(extraModifiers = { Modifier.id("id") }) {
   Modifier.size(...)
}

Also support alt base syntax:

// Before
val SomeStyle by ComponentStyle {
   base { Modifier.id("id") }
}

// After refactoring
val SomeStyle by ComponentStyle(extraModifiers = { Modifier.id("id") }) {
   base { Modifier.size(...) }
}

For attribute modifiers that AREN'T in the base block, do NOT offer to refactor. Just show the warning.

val SomeStyle by ComponentStyle {
   hover { Modifier.id("id").size(...) }
                    ^^
}