This is a custom rule set for ktlint which modifies some standard rules to better work with Kotlin code that makes use of preprocessor.
The exact usage is dependent on your ktlint setup and you should refer to your
integration's documentation, but here is how you would do it for
Spotless
in a build.gradle.kts file:
repositories {
maven("https://jitpack.io")
}
spotless {
kotlin {
ktlint().customRuleSets(listOf("com.github.RubixDev:ktlint-ruleset-mc-preprocessor:01fbcf09be"))
}
}Replace the commit hash with the latest hash on JitPack.
-
mc-preprocessor:chain-wrapping- based on
standard:chain-wrapping - modified to move the operators
*,/,%,&&, and||on the start of the next line instead of at the end of the current line +and-operators are kept at the end of lines because Kotlin's parsing is a bit annoying there- this is just my preference and has nothing to do with the preprocessor
- based on
-
mc-preprocessor:comment-spacing- based on
standard:comment-spacing - modified to allow comments starting with
//#,//$or///to not have spaces after them
- based on
-
mc-preprocessor:import-ordering- based on
standard:import-ordering - modified to sort imports alphabetically, but respects preprocessor comments for version-specific imports and puts those separately at the end as specified in their docs
- sorts the preprocessor import blocks based on their Minecraft version and the comparison operator they use
- custom import ordering patterns cannot be specified with this version of the rule
- based on