https://kotlinlang.org logo
#getting-started
Title
# getting-started
t

Tech

11/24/2023, 10:50 AM
Hey, I'm writing a library and I was wondering if it was possible to have an annotation or something to define the max length a String should be and if it goes over that just give an IDE warning? I'll of course add built-in checks but I just thought this would be a little nice to have some warnings if developers go over how long the String should be.
v

Valtteri Puonti

11/24/2023, 10:57 AM
Have you tried make custom lint rules.? You can check for example Timber's lint module, in it there's a lint check that pops a warning if a tag-argument is longer than 23 chars https://github.com/JakeWharton/timber/blob/trunk/timber-lint/src/main/java/timber/lint/WrongTimberUsageDetector.kt#L142C30-L142C30 Hope this helps 🙂
t

Tech

11/24/2023, 11:21 AM
Thank you for the suggestion!
2 Views