bbaldino
01/07/2020, 10:04 PMArtur Bosch
01/08/2020, 7:05 AMbbaldino
01/08/2020, 5:49 PMfun Byte.putBit(bitPos: Int, isSet: Boolean): Byte {
return if (isSet) {
(this.toInt() or (0b10000000 ushr bitPos)).toByte()
} else {
(this.toInt() and (0b10000000 ushr bitPos).inv()).toByte()
}
}
myByte.putBit(1, true)
and think it would be modified in place, but actually it returns the new value. i'm looking for a way similar to 'nodiscard' in c++ where i can generate a warning of some kind in this scenariodiego-gomez-olvera
01/09/2020, 11:37 AMbbaldino
01/09/2020, 5:24 PMschalkms
01/09/2020, 9:00 PMdiego-gomez-olvera
01/10/2020, 8:58 AMbbaldino
01/10/2020, 5:53 PMschalkms
01/10/2020, 8:52 PMwould it be possible to add one?Yes, you could add such a rule to detekt. You would need to use type and symbol solving, which is shown in the following example. https://github.com/arturbosch/detekt/blob/master/detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UselessCallOnNotNull.kt If you have a strong need for this rule, you can certainly re-implement this in detekt and contribute back to the project.
bbaldino
01/10/2020, 9:05 PMCheckResult
(or whatever) annotation and not using its return would almost definitely indicate a bug.schalkms
01/10/2020, 9:11 PMDo you think it would be something that would belong in detekt?Yeah, it would be a nice add-on with a very low priority, since there are existing solutions. There are many other features, which have way higher priority. We rely on contributions from our awesome community for such rules. Of course we try to assist as much as possible.
bbaldino
01/10/2020, 9:13 PMschalkms
01/10/2020, 9:15 PMOne decision would be whether or not to warn on ALL functions who return a value which isn't saved vs. just those with an annotationWe handle this with configuration options. For example:
LongParameterList:
active: true
threshold: 6
ignoreDefaultParameters: false
bbaldino
01/10/2020, 9:16 PMschalkms
01/10/2020, 9:17 PMAnd the rule could be disabled by users for those cases where it shouldn't warn.Yes. Detekt supports the
@Suppress
annotation.But, basically, just always warn and let users use detekt's existing mechanism to disable it (entirely, case-by-case, etc.) if they wantYes, considering the user defined config options like
threshold
for instance.bbaldino
01/10/2020, 9:18 PMschalkms
01/10/2020, 9:24 PMbbaldino
01/10/2020, 9:24 PMUselessCallOnNotNull
test, to see how it's parsing the expression. But it looks like the KtQualifiedExpression
passed to visitQualifiedExpression
does not include the assignment (i.e. for val testList = listOf("string").orEmpty
, it just has listOf("string").orEmpty
). Do you happen to know if there's an expression type which includes any assignment (if it exists) as well as the expression?visitDeclaration
Artur Bosch
01/12/2020, 5:59 PM