-
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.
Merge branch 'master' into feature/rule-6.1.7-implicit-backing-property(
#443) # Conflicts: # diktat-analysis.yml # diktat-rules/src/main/kotlin/generated/WarningNames.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt # diktat-rules/src/main/resources/diktat-analysis-huawei.yml # diktat-rules/src/main/resources/diktat-analysis.yml
- Loading branch information
Showing
43 changed files
with
481 additions
and
29 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
diktat-gradle-plugin/src/test/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginTest.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,31 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class DiktatGradlePluginTest { | ||
private val projectBuilder = ProjectBuilder.builder() | ||
private lateinit var project: Project | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
project = projectBuilder.build() | ||
project.pluginManager.apply(DiktatGradlePlugin::class.java) | ||
} | ||
|
||
@Test | ||
fun `check that tasks are registered`() { | ||
Assertions.assertTrue(project.tasks.findByName("diktatCheck") != null) | ||
Assertions.assertTrue(project.tasks.findByName("diktatFix") != null) | ||
} | ||
|
||
@Test | ||
fun `check default extension properties`() { | ||
val diktatExtension = project.extensions.getByName("diktat") as DiktatExtension | ||
Assertions.assertFalse(diktatExtension.debug) | ||
Assertions.assertIterableEquals(project.fileTree("src").files, diktatExtension.inputs.files) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
diktat-gradle-plugin/src/test/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskTest.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,51 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
|
||
class DiktatJavaExecTaskTest { | ||
private val projectBuilder = ProjectBuilder.builder() | ||
private lateinit var project: Project | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
project = projectBuilder.build() | ||
} | ||
|
||
@Test | ||
fun `check command line for various inputs`() { | ||
val pwd = project.file(".") | ||
assertCommandLineEquals( | ||
listOf(null, "$pwd" + listOf("src", "**", "*.kt").joinToString(File.separator, prefix = File.separator)), | ||
DiktatExtension().apply { | ||
inputs = project.files("src/**/*.kt") | ||
} | ||
) | ||
} | ||
|
||
@Test | ||
fun `check command line in debug mode`() { | ||
val pwd = project.file(".") | ||
assertCommandLineEquals( | ||
listOf(null, "--debug", "$pwd${listOf("src", "**", "*.kt").joinToString(File.separator, prefix = File.separator)}"), | ||
DiktatExtension().apply { | ||
inputs = project.files("src/**/*.kt") | ||
debug = true | ||
} | ||
) | ||
} | ||
|
||
private fun registerDiktatTask(extension: DiktatExtension) = project.tasks.register( | ||
"test", DiktatJavaExecTaskBase::class.java, | ||
"6.7", extension, project.configurations.create("diktat") | ||
) | ||
|
||
private fun assertCommandLineEquals(expected: List<String?>, extension: DiktatExtension) { | ||
val task = registerDiktatTask(extension).get() | ||
Assertions.assertIterableEquals(expected, task.commandLine) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
diktat-gradle-plugin/src/test/kotlin/org/cqfn/diktat/plugin/gradle/UtilsTest.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,24 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class UtilsTest { | ||
@Test | ||
fun `test gradle version`() { | ||
Assertions.assertEquals( | ||
GradleVersion.fromString("6.6.1"), | ||
GradleVersion(6, 6, 1, null) | ||
) | ||
|
||
Assertions.assertEquals( | ||
GradleVersion.fromString("6.7"), | ||
GradleVersion(6, 7, 0, null) | ||
) | ||
|
||
Assertions.assertEquals( | ||
GradleVersion.fromString("6.7-rc-5"), | ||
GradleVersion(6, 7, 0, "rc-5") | ||
) | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AvoidEmptyPrimaryConstructor.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,35 @@ | ||
package org.cqfn.diktat.ruleset.rules | ||
|
||
import com.pinterest.ktlint.core.Rule | ||
import com.pinterest.ktlint.core.ast.ElementType.CLASS | ||
import org.cqfn.diktat.common.config.rules.RulesConfig | ||
import org.cqfn.diktat.ruleset.constants.Warnings.EMPTY_PRIMARY_CONSTRUCTOR | ||
import org.jetbrains.kotlin.com.intellij.lang.ASTNode | ||
import org.jetbrains.kotlin.psi.KtClass | ||
|
||
class AvoidEmptyPrimaryConstructor(private val configRules: List<RulesConfig>) : Rule("avoid-empty-primary-constructor") { | ||
|
||
|
||
private var isFixMode: Boolean = false | ||
private lateinit var emitWarn: ((offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) | ||
|
||
override fun visit(node: ASTNode, | ||
autoCorrect: Boolean, | ||
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) { | ||
emitWarn = emit | ||
isFixMode = autoCorrect | ||
|
||
if (node.elementType == CLASS) | ||
checkCLass(node.psi as KtClass) | ||
} | ||
|
||
@Suppress("UnsafeCallOnNullableType") | ||
private fun checkCLass(ktClass: KtClass) { | ||
if(ktClass.primaryConstructor?.valueParameters?.isNotEmpty() != false || ktClass.primaryConstructorModifierList != null) | ||
return | ||
EMPTY_PRIMARY_CONSTRUCTOR.warnAndFix(configRules, emitWarn, isFixMode, ktClass.nameIdentifier!!.text, | ||
ktClass.node.startOffset, ktClass.node) { | ||
ktClass.node.removeChild(ktClass.primaryConstructor!!.node) | ||
} | ||
} | ||
} |
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.