Hello, is it possible to achieve this goal without...
# getting-started
o
Hello, is it possible to achieve this goal without external lint
Copy code
@Target(
    AnnotationTarget.PROPERTY,
    AnnotationTarget.TYPE,
    AnnotationTarget.VALUE_PARAMETER,
)
annotation class StringResource

// formatX only works with @StringResource annotated strings
fun @StringResource String.formatX(vararg arguments: Any): String = format(args = arguments)

fun main() {
    Strings().hello.formatX("xxx")

    // The below line should be shown as an error
    "Hello, %s".formatX("xxx")
}

data class Strings(
    @StringResource val hello: String = "Hello, %s",
)
y
Maybe what you want is a value class?
Copy code
@JvmInline value class StringResource(val underlying: String)
fun StringResource.formatX(vararg arguments: Any): String = underlying.format(args = arguments)
o
That's an ok workaround, but it may not be as inconvenient as before if we add new strings. We need to type an extra S for the StringResource code completion. That's also the reason why I asked such a thing at the beginning.