-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature. Ktlint rule wrapper #744
Conversation
### What's done: * Wrapper made * Class reworking hsa begun
### What's done: * Refactored more classes * Added error message
Codecov Report
@@ Coverage Diff @@
## master #744 +/- ##
============================================
- Coverage 80.05% 79.63% -0.43%
- Complexity 1997 2003 +6
============================================
Files 95 96 +1
Lines 5119 5032 -87
Branches 1644 1604 -40
============================================
- Hits 4098 4007 -91
- Misses 242 246 +4
Partials 779 779
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
import org.cqfn.diktat.ruleset.utils.log | ||
import org.jetbrains.kotlin.com.intellij.lang.ASTNode | ||
|
||
typealias DiktatConfigRule = org.cqfn.diktat.common.config.rules.Rule |
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.
typealias DiktatConfigRule = org.cqfn.diktat.common.config.rules.Rule | |
private typealias DiktatConfigRule = org.cqfn.diktat.common.config.rules.Rule |
Is it used only in this file?
else { | ||
try { | ||
logic(node) | ||
} catch (e: Exception) { |
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.
} catch (e: Exception) { | |
} catch (e: Throwable) { |
### What's done: * Fixed bugs
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.
Looks OK to me, @akuleshov7 please take a look. I remember you had some considerations whether to terminate application on internal errors.
351c9b0
to
019ea91
Compare
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
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/.\n Error: ${internalError.message}") |
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.
yes, exactly what @petertrr has mentioned. On the internal error we should stop diktat (exit 1) and SUGGEST to disable a rule where an issue happened
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.
Fixed
} else { | ||
try { | ||
logic(node) | ||
} catch (internalError: Throwable) { |
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.
damn, catching all exceptions? I do not know if it is a good idea, @petertrr think about this here
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 mean, isn't this what we were trying to achieve? Otherwise these exceptions are caught by ktlint and they just log a warning as well.
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 am saying that simply doing catch (Exception e) is a bad practice. May be there are different types of exceptions in ktlint to handle BEFORE we will catch all remaining exeptions
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.
Everything that is thrown from rule.visit
is catched in Ktlint.kt with catch (e: Exception)
. So their idea is that the visitor either handles all exceptions, or they are considered internal errors.
@@ -80,7 +79,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents | |||
* // FixMe: because it fixes only declaration without the usages | |||
*/ | |||
@Suppress("ForbiddenComment", "MISSING_KDOC_CLASS_ELEMENTS") | |||
class IdentifierNaming(private val configRules: List<RulesConfig>) : Rule("identifier-naming") { | |||
class IdentifierNaming(configRules: List<RulesConfig>) : DiktatRule("identifier-naming", configRules, | |||
listOf(BACKTICKS_PROHIBITED, VARIABLE_NAME_INCORRECT, VARIABLE_NAME_INCORRECT_FORMAT, CONSTANT_UPPERCASE, |
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.
will this pass diktat formatting rule?
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.
possible bug in diktat?
@Suppress("TooGenericExceptionCaught") | ||
abstract class DiktatRule(id: String, | ||
val configRules: List<RulesConfig>, | ||
val rules: List<DiktatConfigRule>) : Rule(id) { |
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.
please rename "rules" to "inspections". Who was writing a white paper? Me or you?
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.
Renamed
} | ||
|
||
private fun areRulesEnabled(): Boolean = | ||
rules.none { configRules.isRuleEnabled(it) } |
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.
Please correct me if I'm wrong: here you check that ALL rules are enabled. And if one of them is not enabled you simply do not run the whole rule (that can contain other inspections)?
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.
Please add a test (sorry if I have missed it)
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.
Added test and renamed a function
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
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.
lgtm
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.
lgtm
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.
lgtm
### What's done: * Fixed bugs
Introduced DiktatRule to wrap c.p.k.c.Rule
This pull request closes #606