Repository navigation
ArrayPrimitive rule: report variable/receiver types and factory methods - #3009
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3009 +/- ##
============================================
- Coverage 79.70% 79.67% -0.04%
- Complexity 2504 2509 +5
============================================
Files 427 427
Lines 7543 7541 -2
Branches 1424 1430 +6
============================================
- Hits 6012 6008 -4
Misses 773 773
- Partials 758 760 +2
Continue to review full report at Codecov.
|
| describe("variable type") { | ||
| it("is Array<Primitive>") { | ||
| val code = "val foo: Array<Int>? = null" | ||
| assertThat(subject.compileAndLint(code)).hasSize(1) |
There was a problem hiding this comment.
| assertThat(subject.compileAndLint(code)).hasSize(1) | |
| assertThat(subject.compileAndLintWithContext(env, code)).hasSize(1) |
| describe("receiver type") { | ||
| it("is Array<Primitive>") { | ||
| val code = "fun Array<Long>.foo() { println(this) }" | ||
| assertThat(subject.compileAndLint(code)).hasSize(1) |
There was a problem hiding this comment.
| assertThat(subject.compileAndLint(code)).hasSize(1) | |
| assertThat(subject.compileAndLintWithContext(env, code)).hasSize(1) |
|
|
||
| it("is intArrayOf()") { | ||
| val code = "fun test(x: Int) = intArrayOf(x)" | ||
| assertThat(subject.compileAndLint(code)).isEmpty() |
There was a problem hiding this comment.
| assertThat(subject.compileAndLint(code)).isEmpty() | |
| assertThat(subject.compileAndLintWithContext(env, code)).isEmpty() |
| class ArrayPrimitive(config: Config = Config.empty) : Rule(config) { | ||
| companion object { | ||
| private val primitiveTypes = PrimitiveType.NUMBER_TYPES.map { it.typeName.asString() } | ||
| private val arrayOfFunctionFqName = FqName("kotlin.arrayOf") |
There was a problem hiding this comment.
Follow-up for the future: the same behavior should probably be flagged also for emptyArray()
| @@ -35,44 +41,45 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType | |||
| * @active since v1.2.0 | |||
There was a problem hiding this comment.
| * @active since v1.2.0 | |
| * @active since v1.2.0 | |
| * @requiresTypeResolution | |
| */ |
|
Side note: this is a rule that transition from NOT requiring to requiring type resolution. This should probably be noted in the README @arturbosch ? |
| * fun returningFunction(): DoubleArray { } | ||
| * </compliant> | ||
| * | ||
| * @active since v1.2.0 |
There was a problem hiding this comment.
We should not disable this rule.
There was a problem hiding this comment.
Yup, I picked the wrong line for the suggestion. Updated
Fixes #1245