-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature/ktlint-rule-wrapper(#606) ### What's done: * Wrapper made * All rules were refactored * Added error message
- Loading branch information
Showing
68 changed files
with
368 additions
and
817 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.cqfn.diktat.ruleset.rules | ||
|
||
import org.cqfn.diktat.common.config.rules.RulesConfig | ||
import org.cqfn.diktat.common.config.rules.isRuleEnabled | ||
import org.cqfn.diktat.ruleset.constants.EmitType | ||
import org.cqfn.diktat.ruleset.utils.log | ||
|
||
import com.pinterest.ktlint.core.Rule | ||
import org.jetbrains.kotlin.com.intellij.lang.ASTNode | ||
import kotlin.system.exitProcess | ||
|
||
private typealias DiktatConfigRule = org.cqfn.diktat.common.config.rules.Rule | ||
|
||
/** | ||
* This is a wrapper around Ktlint Rule | ||
* | ||
* @param id id of the rule | ||
* @property configRules all rules from configuration | ||
* @property inspections warnings that are used in the rule's code | ||
*/ | ||
@Suppress("TooGenericExceptionCaught") | ||
abstract class DiktatRule(id: String, | ||
val configRules: List<RulesConfig>, | ||
val inspections: List<DiktatConfigRule>) : Rule(id) { | ||
/** | ||
* Default value is false | ||
*/ | ||
var isFixMode: Boolean = false | ||
|
||
/** | ||
* Will be initialized in visit | ||
*/ | ||
lateinit var emitWarn: EmitType | ||
|
||
override fun visit(node: ASTNode, | ||
autoCorrect: Boolean, | ||
emit: EmitType) { | ||
emitWarn = emit | ||
isFixMode = autoCorrect | ||
|
||
if (areInspectionsDisabled()) { | ||
return | ||
} else { | ||
try { | ||
logic(node) | ||
} catch (internalError: Throwable) { | ||
log.error("Internal error has occurred in $id. Please make an issue on this bug at https://github.com/cqfn/diKTat/.", internalError) | ||
log.error("As a workaround you can disable these inspections in yml config: $inspections") | ||
exitProcess(1) | ||
} | ||
} | ||
} | ||
|
||
private fun areInspectionsDisabled(): Boolean = | ||
inspections.none { configRules.isRuleEnabled(it) } | ||
|
||
/** | ||
* Logic of the rule | ||
* | ||
* @param node node that are coming from visit | ||
*/ | ||
abstract fun logic(node: ASTNode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
e51031c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: