An open API service indexing awesome lists of open source software.

https://github.com/rubixdev/ktlint-ruleset-mc-preprocessor

A custom ktlint rule set containing customized rules from the standard set tweaked for Minecraft mods using preprocessing
https://github.com/rubixdev/ktlint-ruleset-mc-preprocessor

Last synced: 10 months ago
JSON representation

A custom ktlint rule set containing customized rules from the standard set tweaked for Minecraft mods using preprocessing

Awesome Lists containing this project

README

          

# Custom ktlint Rule Set for Minecraft Preprocessor Mods

This is a custom rule set for [ktlint](https://ktlint.github.io/) which modifies
some standard rules to better work with Kotlin code that makes use of
[preprocessor](https://github.com/ReplayMod/preprocessor).

## Usage

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](https://github.com/diffplug/spotless/tree/main/plugin-gradle#applying-ktlint-to-kotlin-files)
in a `build.gradle.kts` file:

```kts
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](https://jitpack.io/#RubixDev/ktlint-ruleset-mc-preprocessor).

## Included Rules

- [`mc-preprocessor:chain-wrapping`](./src/main/kotlin/de/rubixdev/ktlint/mc/preprocessor/ChainWrappingRule.kt)
- based on
[`standard:chain-wrapping`](https://github.com/pinterest/ktlint/blob/c4788a5f581f0d9f85ca47296b6b576fd6b5d594/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt)
- 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](https://github.com/pinterest/ktlint/issues/163#issuecomment-369418775)
- this is just my preference and has nothing to do with the preprocessor

- [`mc-preprocessor:comment-spacing`](./src/main/kotlin/de/rubixdev/ktlint/mc/preprocessor/CommentSpacingRule.kt)
- based on
[`standard:comment-spacing`](https://github.com/pinterest/ktlint/blob/c4788a5f581f0d9f85ca47296b6b576fd6b5d594/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt)
- modified to allow comments starting with `//#`, `//$` or `///` to not have
spaces after them

- [`mc-preprocessor:import-ordering`](./src/main/kotlin/de/rubixdev/ktlint/mc/preprocessor/ImportOrderingRule.kt)
- based on
[`standard:import-ordering`](https://github.com/pinterest/ktlint/blob/c4788a5f581f0d9f85ca47296b6b576fd6b5d594/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt)
- 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](https://github.com/ReplayMod/preprocessor#the-preprocessor)
- 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