From 7fee58a3568a495bcd4c0b46a00735ca36c9c8c9 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 15 Nov 2022 18:28:03 +0300 Subject: [PATCH 01/30] Add main for diktat.jar ### What's done: * renamed diktat-ruleset to diktat * added DiktatMain * updated gradle plugin to use only diktat as dependency It closes #1557 --- {diktat-ruleset => diktat}/pom.xml | 2 +- .../org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt | 0 .../kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt | 0 .../org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt | 0 .../src/test/kotlin/org/cqfn/diktat/util/SmokeTestUtils.kt | 0 .../src/test/resources/test/smoke/.gitignore | 0 .../src/test/resources/test/smoke/build.gradle_.kts | 0 .../src/test/resources/test/smoke/save.toml | 0 .../jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt | 0 .../src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt | 0 .../src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt | 0 .../test/smoke/src/main/kotlin/DefaultPackageExpected.kt | 0 .../test/smoke/src/main/kotlin/DefaultPackageTest.kt | 0 .../test/smoke/src/main/kotlin/Example1-2Expected.kt | 0 .../resources/test/smoke/src/main/kotlin/Example1Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example1Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example2Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example2Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example3Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example3Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example4Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example4Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example5Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example5Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example6Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example6Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example7Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example7Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example8Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example8Test.kt | 0 .../src/main/kotlin/KdocFormattingMultilineTagsExpected.kt | 0 .../smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt | 0 .../smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt | 0 .../test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt | 0 .../src/main/kotlin/ManyLineTransformInLongLineExpected.kt | 0 .../smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt | 0 .../smoke/src/main/kotlin/kotlin-library-expected.gradle.kts | 0 .../test/smoke/src/main/kotlin/kotlin-library.gradle.kts | 0 .../src/test/resources/test/smoke/src/main/kotlin/save.toml | 0 .../smoke/src/main/kotlin/script/PackageInScriptExpected.kts | 0 .../test/smoke/src/main/kotlin/script/PackageInScriptTest.kts | 0 .../src/main/kotlin/script/SimpleRunInScriptExpected.kts | 0 .../smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts | 0 pom.xml | 4 ++-- 45 files changed, 3 insertions(+), 3 deletions(-) rename {diktat-ruleset => diktat}/pom.xml (99%) rename {diktat-ruleset => diktat}/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt (100%) rename {diktat-ruleset => diktat}/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt (100%) rename {diktat-ruleset => diktat}/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt (100%) rename {diktat-ruleset => diktat}/src/test/kotlin/org/cqfn/diktat/util/SmokeTestUtils.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/.gitignore (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/build.gradle_.kts (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/save.toml (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/save.toml (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts (100%) rename {diktat-ruleset => diktat}/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts (100%) diff --git a/diktat-ruleset/pom.xml b/diktat/pom.xml similarity index 99% rename from diktat-ruleset/pom.xml rename to diktat/pom.xml index 9024648b37..12eb7082de 100644 --- a/diktat-ruleset/pom.xml +++ b/diktat/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 diktat - This module builds jar that can be used to run diktat using ktlint -R via command line + This module builds jar that can be used to run diktat using java -jar via command line org.cqfn.diktat diff --git a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt b/diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt similarity index 100% rename from diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt rename to diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt diff --git a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt b/diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt similarity index 100% rename from diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt rename to diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt diff --git a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt b/diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt similarity index 100% rename from diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt rename to diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt diff --git a/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/util/SmokeTestUtils.kt b/diktat/src/test/kotlin/org/cqfn/diktat/util/SmokeTestUtils.kt similarity index 100% rename from diktat-ruleset/src/test/kotlin/org/cqfn/diktat/util/SmokeTestUtils.kt rename to diktat/src/test/kotlin/org/cqfn/diktat/util/SmokeTestUtils.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/.gitignore b/diktat/src/test/resources/test/smoke/.gitignore similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/.gitignore rename to diktat/src/test/resources/test/smoke/.gitignore diff --git a/diktat-ruleset/src/test/resources/test/smoke/build.gradle_.kts b/diktat/src/test/resources/test/smoke/build.gradle_.kts similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/build.gradle_.kts rename to diktat/src/test/resources/test/smoke/build.gradle_.kts diff --git a/diktat-ruleset/src/test/resources/test/smoke/save.toml b/diktat/src/test/resources/test/smoke/save.toml similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/save.toml rename to diktat/src/test/resources/test/smoke/save.toml diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt b/diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt rename to diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt b/diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt rename to diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt b/diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt rename to diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts b/diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts rename to diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts b/diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts rename to diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/save.toml b/diktat/src/test/resources/test/smoke/src/main/kotlin/save.toml similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/save.toml rename to diktat/src/test/resources/test/smoke/src/main/kotlin/save.toml diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts b/diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts rename to diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts b/diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts rename to diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts b/diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts rename to diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts diff --git a/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts b/diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts similarity index 100% rename from diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts rename to diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts diff --git a/pom.xml b/pom.xml index e3d68692e1..29b9b2d1d4 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 1.2.5-SNAPSHOT pom - diktat + diktat-parent diKTat kotlin formatter and fixer https://www.cqfn.org/diKTat/ @@ -67,7 +67,7 @@ diktat-common diktat-rules diktat-test-framework - diktat-ruleset + diktat diktat-maven-plugin diktat-gradle-plugin From 67932defb6588a8404ce4fe31b85ed157c75e18a Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 15 Nov 2022 18:52:01 +0300 Subject: [PATCH 02/30] [skip-ci] WIP --- diktat/pom.xml | 77 +------------------ .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 5 ++ .../org/cqfn/diktat/cli/DiktatProperties.kt | 7 ++ pom.xml | 43 ++++++++++- 4 files changed, 52 insertions(+), 80 deletions(-) create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt diff --git a/diktat/pom.xml b/diktat/pom.xml index 12eb7082de..66af555f35 100644 --- a/diktat/pom.xml +++ b/diktat/pom.xml @@ -17,25 +17,6 @@ org.cqfn.diktat diktat-rules ${project.version} - - - - org.jetbrains.kotlin - kotlin-stdlib-common - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - - - org.jetbrains.kotlin - kotlin-stdlib - - - org.jetbrains.kotlin - kotlin-compiler-embeddable - - @@ -44,31 +25,6 @@ ${project.version} test - - org.jetbrains.kotlin - kotlin-stdlib-common - test - - - org.jetbrains.kotlin - kotlin-stdlib-jdk7 - test - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - test - - - org.jetbrains.kotlin - kotlin-stdlib - test - - - org.jetbrains.kotlin - kotlin-compiler-embeddable - test - org.junit.jupiter junit-jupiter @@ -92,40 +48,9 @@ + ${project.basedir}/src/main/kotlin ${project.basedir}/src/test/kotlin - - org.jetbrains.kotlin - kotlin-maven-plugin - - - test-compile - process-test-sources - - test-compile - - - - - src/main/kotlin - src/test/kotlin - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - - - - - - maven-jar-plugin - - - default-jar - none - - - org.apache.maven.plugins diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt new file mode 100644 index 0000000000..c53fdd5111 --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -0,0 +1,5 @@ +package org.cqfn.diktat + +fun main(args: Array) { + +} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt new file mode 100644 index 0000000000..11341cccf9 --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -0,0 +1,7 @@ +package org.cqfn.diktat.cli + +data class DiktatProperties( + val config: String, + val reporter: String, + val output: String, +) diff --git a/pom.xml b/pom.xml index 29b9b2d1d4..1d24f62f83 100644 --- a/pom.xml +++ b/pom.xml @@ -369,16 +369,51 @@ ${kotlin.version} 1.8 - - src/main/kotlin - src/main/resources - -Werror -opt-in=kotlin.RequiresOptIn true + + + compile + process-sources + + compile + + + + src/main/kotlin + src/main/resources + src/main/resources + + + kotlinx-serialization + + + + + test-compile + process-test-sources + + test-compile + + + + src/test/java + src/test/kotlin + + + + + + + org.jetbrains.kotlin + kotlin-maven-serialization + ${kotlin.version} + + org.codehaus.mojo From e2dd4b22d1c74f946573a5e030b477e3bfe38048 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 16 Nov 2022 13:14:32 +0300 Subject: [PATCH 03/30] [skip-ci] WIP #2 --- diktat/pom.xml | 4 ++ .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 53 +++++++++++++++++++ .../org/cqfn/diktat/api/DiktatLogLevel.kt | 7 +++ .../org/cqfn/diktat/api/DiktatReporterType.kt | 23 ++++++++ .../org/cqfn/diktat/cli/DiktatProperties.kt | 3 ++ pom.xml | 11 ++++ 6 files changed, 101 insertions(+) create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt diff --git a/diktat/pom.xml b/diktat/pom.xml index 66af555f35..1893b9cdec 100644 --- a/diktat/pom.xml +++ b/diktat/pom.xml @@ -18,6 +18,10 @@ diktat-rules ${project.version} + + org.jetbrains.kotlinx + kotlinx-cli-jvm + org.cqfn.diktat diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index c53fdd5111..305caa4eb5 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -1,5 +1,58 @@ package org.cqfn.diktat +import org.cqfn.diktat.api.DiktatLogLevel +import org.cqfn.diktat.api.DiktatReporterType +import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF +import kotlinx.cli.ArgParser +import kotlinx.cli.ArgType +import kotlinx.cli.default + fun main(args: Array) { + val parser = ArgParser("diktat") + val configOption = parser.option( + type = ArgType.String, + fullName = "config", + shortName = "c", + description = """ + Specify the location of the YAML configuration file. + By default, $DIKTAT_ANALYSIS_CONF in the current + directory is used. + """.trimIndent(), + ).default(DIKTAT_ANALYSIS_CONF) + val config: String by configOption + + val formatOption = parser.option( + type = ArgType.Boolean, + fullName = "format", + shortName = "F", + description = "Fix any deviations from the code style." + ).default(false) + val format: Boolean by formatOption + + val reporterOption = parser.option( + type = ArgType.Choice(), + fullName = "reporter", + shortName = "r", + description = "The reporter to use", + ).default(DiktatReporterType.PLAIN) + val reporter: DiktatReporterType by reporterOption + + val outputOption = parser.option( + type = ArgType.String, + fullName = "output", + shortName = "o", + description = "Redirect the reporter output to a file.", + ) + val output: String? by outputOption + + val logLevelOption = parser.option( + type = ArgType.Choice(), + fullName = "log-level", + shortName = "l", + description = "Enable the output of specified level", + ).default(DiktatLogLevel.INFO) + val logLevel: DiktatLogLevel by logLevelOption + + parser.parse(args) } diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt new file mode 100644 index 0000000000..a383b93201 --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt @@ -0,0 +1,7 @@ +package org.cqfn.diktat.api + +enum class DiktatLogLevel { + DEBUG, + INFO, + TRACE, +} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt new file mode 100644 index 0000000000..a39516b0a8 --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt @@ -0,0 +1,23 @@ +package org.cqfn.diktat.api + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Type of reporting in `diktat` + */ +@Serializable +enum class DiktatReporterType { + @SerialName("plain") + PLAIN, + @SerialName("plain_group_by_file") + PLAIN_GROUP_BY_FILE, + @SerialName("json") + JSON, + @SerialName("sarif") + SARIF, + @SerialName("checkstyle") + CHECKSTYLE, + @SerialName("html") + HTML, +} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 11341cccf9..74d74f08ad 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -1,7 +1,10 @@ package org.cqfn.diktat.cli +import org.cqfn.diktat.api.DiktatLogLevel + data class DiktatProperties( val config: String, val reporter: String, val output: String, + val logLevel: DiktatLogLevel, ) diff --git a/pom.xml b/pom.xml index 1d24f62f83..1613a411e4 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ true official 1.4.1 + 0.3.5 0.47.1 5.9.1 1.9.1 @@ -132,6 +133,16 @@ kotlinx-serialization-json-jvm ${kotlinx.serialization.version} + + org.jetbrains.kotlinx + kotlinx-cli + ${kotlinx-cli.version} + + + org.jetbrains.kotlinx + kotlinx-cli-jvm + ${kotlinx-cli.version} + com.pinterest.ktlint ktlint-core From 887edc556c49d3f5e63425412d806ee13f2aabbb Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 16 Nov 2022 14:06:54 +0300 Subject: [PATCH 04/30] [skip-ci] WIP #3 --- .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 305caa4eb5..dd73796a85 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -2,14 +2,17 @@ package org.cqfn.diktat import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.api.DiktatReporterType +import org.cqfn.diktat.common.config.rules.DIKTAT import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF +import org.cqfn.diktat.common.config.rules.DIKTAT_RULE_SET_ID +import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default fun main(args: Array) { - val parser = ArgParser("diktat") - val configOption = parser.option( + val parser = ArgParser(DIKTAT) + val config: String by parser.option( type = ArgType.String, fullName = "config", shortName = "c", @@ -19,40 +22,32 @@ fun main(args: Array) { directory is used. """.trimIndent(), ).default(DIKTAT_ANALYSIS_CONF) - val config: String by configOption - - val formatOption = parser.option( + val format: Boolean by parser.option( type = ArgType.Boolean, fullName = "format", shortName = "F", description = "Fix any deviations from the code style." ).default(false) - val format: Boolean by formatOption - - val reporterOption = parser.option( + val reporter: DiktatReporterType by parser.option( type = ArgType.Choice(), fullName = "reporter", shortName = "r", description = "The reporter to use", ).default(DiktatReporterType.PLAIN) - val reporter: DiktatReporterType by reporterOption - - val outputOption = parser.option( + val output: String? by parser.option( type = ArgType.String, fullName = "output", shortName = "o", description = "Redirect the reporter output to a file.", ) - val output: String? by outputOption - - val logLevelOption = parser.option( + val logLevel: DiktatLogLevel by parser.option( type = ArgType.Choice(), fullName = "log-level", shortName = "l", - description = "Enable the output of specified level", + description = "Enable the output with specific level", ).default(DiktatLogLevel.INFO) - val logLevel: DiktatLogLevel by logLevelOption parser.parse(args) + val diktatRuleSetProvider = DiktatRuleSetProvider(config) } From 710cc31c082f9d951f1ef73c22c2b76e7a7ab88c Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 16 Nov 2022 15:44:24 +0300 Subject: [PATCH 05/30] fixed merge --- .../cqfn/diktat/plugin/maven/DiktatBaseMojo.kt | 1 - .../org/cqfn/diktat/api/DiktatLogLevel.kt | 10 ---------- diktat/pom.xml | 3 +++ .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 17 ++++++++++++----- .../org/cqfn/diktat/DiktatProcessCommand.kt | 1 - .../org/cqfn/diktat/api/DiktatCallback.kt | 0 .../kotlin/org/cqfn/diktat/api/DiktatError.kt | 0 .../org/cqfn/diktat/api/DiktatLogLevel.kt | 5 ++++- .../org/cqfn/diktat/cli/DiktatProperties.kt | 2 -- .../diktat/ktlint/LintErrorCallbackWrapper.kt | 0 .../org/cqfn/diktat/ktlint/LintErrorWrapper.kt | 0 11 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt rename {diktat-ruleset => diktat}/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt (98%) rename {diktat-ruleset => diktat}/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt (100%) rename {diktat-ruleset => diktat}/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt (100%) rename {diktat-ruleset => diktat}/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt (100%) rename {diktat-ruleset => diktat}/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt (100%) diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt index 878b822ea6..5454f1da27 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt @@ -5,7 +5,6 @@ package org.cqfn.diktat.plugin.maven import org.cqfn.diktat.DiktatProcessCommand -import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.ktlint.unwrap import com.pinterest.ktlint.core.LintError diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt deleted file mode 100644 index 6e6e18641d..0000000000 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.cqfn.diktat.api - -/** - * Log level of `diktat processing` - */ -enum class DiktatLogLevel { - DEBUG, - INFO, - ; -} diff --git a/diktat/pom.xml b/diktat/pom.xml index 1893b9cdec..1426fe2de2 100644 --- a/diktat/pom.xml +++ b/diktat/pom.xml @@ -66,6 +66,9 @@ diktat-${project.version} false + + org.cqfn.diktat.DiktatMainKt + true diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index dd73796a85..3721c9b8a2 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -1,14 +1,14 @@ package org.cqfn.diktat -import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.api.DiktatReporterType import org.cqfn.diktat.common.config.rules.DIKTAT import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF -import org.cqfn.diktat.common.config.rules.DIKTAT_RULE_SET_ID import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider +import com.pinterest.ktlint.core.Reporter import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default +import kotlinx.cli.multiple fun main(args: Array) { val parser = ArgParser(DIKTAT) @@ -22,18 +22,20 @@ fun main(args: Array) { directory is used. """.trimIndent(), ).default(DIKTAT_ANALYSIS_CONF) - val format: Boolean by parser.option( + val doFormat: Boolean by parser.option( type = ArgType.Boolean, fullName = "format", shortName = "F", description = "Fix any deviations from the code style." ).default(false) - val reporter: DiktatReporterType by parser.option( + val reporters: List by parser.option( type = ArgType.Choice(), fullName = "reporter", shortName = "r", description = "The reporter to use", - ).default(DiktatReporterType.PLAIN) + ) + .default(DiktatReporterType.PLAIN) + .multiple() val output: String? by parser.option( type = ArgType.String, fullName = "output", @@ -50,4 +52,9 @@ fun main(args: Array) { parser.parse(args) val diktatRuleSetProvider = DiktatRuleSetProvider(config) + +} + +private fun loadReporter(): Reporter { + } diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt similarity index 98% rename from diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt rename to diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index c2667014ab..de37a7ad75 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -1,7 +1,6 @@ package org.cqfn.diktat import org.cqfn.diktat.api.DiktatCallback -import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.ktlint.unwrap import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider import com.pinterest.ktlint.core.KtLint diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt similarity index 100% rename from diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt rename to diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt similarity index 100% rename from diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt rename to diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt index a383b93201..6e6e18641d 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt @@ -1,7 +1,10 @@ package org.cqfn.diktat.api +/** + * Log level of `diktat processing` + */ enum class DiktatLogLevel { DEBUG, INFO, - TRACE, + ; } diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 74d74f08ad..5748f06a71 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -1,7 +1,5 @@ package org.cqfn.diktat.cli -import org.cqfn.diktat.api.DiktatLogLevel - data class DiktatProperties( val config: String, val reporter: String, diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt similarity index 100% rename from diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt rename to diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt similarity index 100% rename from diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt rename to diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt From 89871f587a31f1f1ad80fe8e0f4bc10ba74e0ef8 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 16 Nov 2022 19:03:25 +0300 Subject: [PATCH 06/30] WIP #2 --- .../diktat/plugin/maven/DiktatBaseMojo.kt | 1 + diktat-rules/pom.xml | 29 ++++++++--- .../src/main/kotlin/generated/WarningNames.kt | 4 +- .../diktat/ruleset/generation/Generation.kt | 13 +++-- .../ruleset/generation/GenerationConstants.kt | 51 +++++++++++++++++++ .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 15 ++++-- .../org/cqfn/diktat/DiktatProcessCommand.kt | 1 + .../org/cqfn/diktat/api/DiktatReporterType.kt | 2 - .../org/cqfn/diktat/cli/DiktatProperties.kt | 2 + .../org/cqfn/diktat/ktlint/ReporterUtil.kt | 2 + pom.xml | 1 + 11 files changed, 99 insertions(+), 22 deletions(-) create mode 100644 diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt index 5454f1da27..878b822ea6 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt @@ -5,6 +5,7 @@ package org.cqfn.diktat.plugin.maven import org.cqfn.diktat.DiktatProcessCommand +import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.ktlint.unwrap import com.pinterest.ktlint.core.LintError diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index f7b4cf55b7..f486df2276 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -126,21 +126,36 @@ org.codehaus.mojo exec-maven-plugin + + generate-constants + generate-sources + + java + + + org.cqfn.diktat.ruleset.generation.GenerationConstantsKt + + ${project.build.outputDirectory} + ${project.version} + ${project.basedir}/../LICENSE + + + generate-warnings generate-test-sources java + + org.cqfn.diktat.ruleset.generation.GenerationKt + + ${project.build.sourceDirectory} + ${project.basedir}/src/test/resources + + - - org.cqfn.diktat.ruleset.generation.GenerationKt - - ${project.build.sourceDirectory} - ${project.basedir}/src/test/resources - - diff --git a/diktat-rules/src/main/kotlin/generated/WarningNames.kt b/diktat-rules/src/main/kotlin/generated/WarningNames.kt index 8ef79dfbe5..8f38eb426f 100644 --- a/diktat-rules/src/main/kotlin/generated/WarningNames.kt +++ b/diktat-rules/src/main/kotlin/generated/WarningNames.kt @@ -1,5 +1,5 @@ -// This document was auto generated, please don't modify it. -// This document contains all enum properties from Warnings.kt as Strings. +// | This document was auto generated, please don't modify it. +// | This document contains all enum properties from Warnings.kt as Strings. package generated import kotlin.String diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt index 975a7361e1..637a2d56ab 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt @@ -25,15 +25,11 @@ import kotlin.io.path.writeLines /** * The comment that will be added to the generated sources file. */ -private val autoGenerationComment = - """ - | This document was auto generated, please don't modify it. - | This document contains all enum properties from Warnings.kt as Strings. - """.trimMargin() +internal const val autoGenerationComment = "This document was auto generated, please don't modify it." fun main(args: Array) { require(args.size == 2) { - "Only two arguments are expected: " + "Only four arguments are expected: " } generateWarningNames(args[0]) validateYear(args[1]) @@ -59,7 +55,10 @@ private fun generateWarningNames(sourceDirectory: String) { .builder("generated", "WarningNames") .addType(fileBody) .indent(" ") - .addFileComment(autoGenerationComment) + .addFileComment(""" + | $autoGenerationComment + | This document contains all enum properties from Warnings.kt as Strings. + """.trimIndent()) .build() kotlinFile.writeTo(Paths.get(sourceDirectory)) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt new file mode 100644 index 0000000000..3c0be8ebdb --- /dev/null +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt @@ -0,0 +1,51 @@ +/** + * This file contains code for codegen: generating a file with diktat constants + */ + +package org.cqfn.diktat.ruleset.generation + +import com.squareup.kotlinpoet.FileSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.PropertySpec + +import java.nio.file.Paths + +import kotlin.io.path.readText + + +fun main(args: Array) { + require(args.size == 3) { + "Only four arguments are expected: " + } + generateDiktatConstants(args[0], args[1], args[2]) +} + +private fun generateDiktatConstants( + sourceDirectory: String, + version: String, + licenseFile: String, +) { + FileSpec + .builder("generated", "DiktatConstants") + .addProperty( + PropertySpec.builder("DIKTAT_VERSION", String::class) + .addModifiers(KModifier.CONST) + .addModifiers(KModifier.INTERNAL) + .initializer("%S", version) + .build() + ) + .addProperty( + PropertySpec.builder("LICENSE", String::class) + .addModifiers(KModifier.CONST) + .addModifiers(KModifier.INTERNAL) + .initializer("%S", Paths.get(licenseFile).readText()) + .build() + ) + .indent(" ") + .addFileComment(""" + | $autoGenerationComment. + | This document contains diktat constants. + """.trimMargin()) + .build() + .writeTo(Paths.get(sourceDirectory)) +} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 3721c9b8a2..4d7983ff07 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -1,5 +1,6 @@ package org.cqfn.diktat +import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.api.DiktatReporterType import org.cqfn.diktat.common.config.rules.DIKTAT import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF @@ -9,6 +10,7 @@ import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default import kotlinx.cli.multiple +import kotlinx.cli.vararg fun main(args: Array) { val parser = ArgParser(DIKTAT) @@ -48,13 +50,18 @@ fun main(args: Array) { shortName = "l", description = "Enable the output with specific level", ).default(DiktatLogLevel.INFO) + val patterns: List by parser.argument( + type = ArgType.String, + description = "" + ) + .vararg() parser.parse(args) val diktatRuleSetProvider = DiktatRuleSetProvider(config) } - -private fun loadReporter(): Reporter { - -} +// +//private fun loadReporter(): Reporter { +// +//} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index de37a7ad75..c2667014ab 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -1,6 +1,7 @@ package org.cqfn.diktat import org.cqfn.diktat.api.DiktatCallback +import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.ktlint.unwrap import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider import com.pinterest.ktlint.core.KtLint diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt index a39516b0a8..a5dc52225d 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt @@ -10,8 +10,6 @@ import kotlinx.serialization.Serializable enum class DiktatReporterType { @SerialName("plain") PLAIN, - @SerialName("plain_group_by_file") - PLAIN_GROUP_BY_FILE, @SerialName("json") JSON, @SerialName("sarif") diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 5748f06a71..74d74f08ad 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -1,5 +1,7 @@ package org.cqfn.diktat.cli +import org.cqfn.diktat.api.DiktatLogLevel + data class DiktatProperties( val config: String, val reporter: String, diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt new file mode 100644 index 0000000000..cdbdbce2f1 --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt @@ -0,0 +1,2 @@ +package org.cqfn.diktat.ktlint + diff --git a/pom.xml b/pom.xml index 1613a411e4..ce77ad95bd 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,7 @@ official 1.4.1 0.3.5 + ${kotlin.version}-1.0.8 0.47.1 5.9.1 1.9.1 From 391f663a8930a0f8d4a224154d585ae74ec76955 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 17 Nov 2022 13:06:02 +0300 Subject: [PATCH 07/30] WIP #3 --- diktat/pom.xml | 22 +++++ .../kotlin/org/cqfn/diktat/api/DiktatMode.kt | 15 ++++ .../org/cqfn/diktat/cli/DiktatProperties.kt | 81 ++++++++++++++++++- .../org/cqfn/diktat/ktlint/ReporterUtil.kt | 25 ++++++ pom.xml | 7 +- 5 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt diff --git a/diktat/pom.xml b/diktat/pom.xml index 1426fe2de2..4d3d2ad6e5 100644 --- a/diktat/pom.xml +++ b/diktat/pom.xml @@ -18,6 +18,28 @@ diktat-rules ${project.version} + + + com.pinterest.ktlint + ktlint-reporter-plain + + + com.pinterest.ktlint + ktlint-reporter-json + + + com.pinterest.ktlint + ktlint-reporter-sarif + + + com.pinterest.ktlint + ktlint-reporter-checkstyle + + + com.pinterest.ktlint + ktlint-reporter-html + + org.jetbrains.kotlinx kotlinx-cli-jvm diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt new file mode 100644 index 0000000000..4f3499660b --- /dev/null +++ b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt @@ -0,0 +1,15 @@ +package org.cqfn.diktat.api + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Mode of `diktat` + */ +@Serializable +enum class DiktatMode { + @SerialName("check") + CHECK, + @SerialName("fix") + FIX, +} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 74d74f08ad..352293acb3 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -1,10 +1,89 @@ package org.cqfn.diktat.cli import org.cqfn.diktat.api.DiktatLogLevel +import org.cqfn.diktat.api.DiktatMode +import org.cqfn.diktat.api.DiktatReporterType +import org.cqfn.diktat.common.config.rules.DIKTAT +import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF +import kotlinx.cli.ArgParser +import kotlinx.cli.ArgType +import kotlinx.cli.default +import kotlinx.cli.multiple +import kotlinx.cli.vararg +/** + * @property config path to `diktat-analysis.yml` + * @property mode mode of `diktat` + * @property reporter + * @property output + * @property logLevel + */ data class DiktatProperties( val config: String, + val mode: DiktatMode, val reporter: String, val output: String, val logLevel: DiktatLogLevel, -) +) { + companion object { + /** + * @param args cli arguments + * @return parsed [DiktatProperties] + */ + fun parse(args: Array): DiktatProperties { + val parser = ArgParser(DIKTAT) + val config: String by parser.option( + type = ArgType.String, + fullName = "config", + shortName = "c", + description = """ + Specify the location of the YAML configuration file. + By default, $DIKTAT_ANALYSIS_CONF in the current + directory is used. + """.trimIndent(), + ).default(DIKTAT_ANALYSIS_CONF) + val mode: DiktatMode by parser.option( + type = ArgType.Choice(), + fullName = "mode", + shortName = "m", + description = "Mode of `diktat` controls that `diktat` fixes or only finds any deviations from the code style." + ).default(DiktatMode.CHECK) + val reporters: List by parser.option( + type = ArgType.Choice(), + fullName = "reporter", + shortName = "r", + description = "The reporter to use", + ) + .default(DiktatReporterType.PLAIN) + .multiple() + val output: String? by parser.option( + type = ArgType.String, + fullName = "output", + shortName = "o", + description = "Redirect the reporter output to a file.", + ) + val logLevel: DiktatLogLevel by parser.option( + type = ArgType.Choice(), + fullName = "log-level", + shortName = "l", + description = "Enable the output with specific level", + ).default(DiktatLogLevel.INFO) + val patterns: List by parser.argument( + type = ArgType.String, + description = "" + ) + .vararg() + + parser.parse(args) + + return DiktatProperties( + config = config, + mode = mode, + reporter = "N/A", + output = "N/A", + logLevel = logLevel, + ) + } + } +} + diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt index cdbdbce2f1..f9a5351927 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt @@ -1,2 +1,27 @@ package org.cqfn.diktat.ktlint +import com.pinterest.ktlint.reporter.checkstyle.CheckStyleReporterProvider +import com.pinterest.ktlint.reporter.html.HtmlReporterProvider +import com.pinterest.ktlint.reporter.json.JsonReporterProvider +import com.pinterest.ktlint.reporter.plain.PlainReporterProvider +import com.pinterest.ktlint.reporter.sarif.SarifReporterProvider +import kotlinx.cli.ArgParser +import kotlinx.cli.ArgType + +private val reporters = setOf( + PlainReporterProvider(), + JsonReporterProvider(), + SarifReporterProvider(), + CheckStyleReporterProvider(), + HtmlReporterProvider(), +) + .associateBy { it.id } + +internal fun ArgParser.createReporterOption() { + return option( + ArgType.Choice { + + } + ArgType.Choice { } + ) +} diff --git a/pom.xml b/pom.xml index ce77ad95bd..ce41015e2b 100644 --- a/pom.xml +++ b/pom.xml @@ -160,6 +160,11 @@ ktlint-reporter-plain ${ktlint.version} + + com.pinterest.ktlint + ktlint-reporter-json + ${ktlint.version} + com.pinterest.ktlint ktlint-reporter-sarif @@ -167,7 +172,7 @@ com.pinterest.ktlint - ktlint-reporter-json + ktlint-reporter-checkstyle ${ktlint.version} From b85651d2fef8bda522ffa9cba1154cf3da1390f3 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 21 Nov 2022 20:07:01 +0300 Subject: [PATCH 08/30] WIP #4 --- .../diktat/plugin/maven/DiktatBaseMojo.kt | 4 +- diktat/pom.xml | 26 +++++ .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 105 ++++++++---------- .../org/cqfn/diktat/DiktatProcessCommand.kt | 23 +++- .../org/cqfn/diktat/api/DiktatLogLevel.kt | 10 -- .../org/cqfn/diktat/api/DiktatReporterType.kt | 21 ---- .../org/cqfn/diktat/cli/DiktatProperties.kt | 101 +++++++++++++---- .../org/cqfn/diktat/ktlint/ReporterUtil.kt | 36 ++++-- diktat/src/main/resources/META-INF/version | 1 + 9 files changed, 200 insertions(+), 127 deletions(-) delete mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt delete mode 100644 diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt create mode 100644 diktat/src/main/resources/META-INF/version diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt index 878b822ea6..7bb9dbe875 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt @@ -5,7 +5,6 @@ package org.cqfn.diktat.plugin.maven import org.cqfn.diktat.DiktatProcessCommand -import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.ktlint.unwrap import com.pinterest.ktlint.core.LintError @@ -27,6 +26,7 @@ import org.apache.maven.plugin.MojoExecutionException import org.apache.maven.plugin.MojoFailureException import org.apache.maven.plugins.annotations.Parameter import org.apache.maven.project.MavenProject +import org.slf4j.event.Level import java.io.File import java.io.FileOutputStream @@ -245,7 +245,7 @@ abstract class DiktatBaseMojo : AbstractMojo() { } } .logLevel( - if (debug) DiktatLogLevel.DEBUG else DiktatLogLevel.INFO + if (debug) Level.DEBUG else Level.INFO ) .build() runAction(command) diff --git a/diktat/pom.xml b/diktat/pom.xml index 4d3d2ad6e5..b5dc23b6fd 100644 --- a/diktat/pom.xml +++ b/diktat/pom.xml @@ -18,6 +18,15 @@ diktat-rules ${project.version} + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.apache.logging.log4j + log4j-core + 2.19.0 + com.pinterest.ktlint @@ -76,6 +85,23 @@ ${project.basedir}/src/main/kotlin ${project.basedir}/src/test/kotlin + + + src/main/resources/META-INF + + version + + /META-INF/diktat + true + + + ${project.basedir}/.. + + LICENSE + + /META-INF/diktat + + diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 4d7983ff07..2e11b5bb57 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -1,67 +1,52 @@ package org.cqfn.diktat -import org.cqfn.diktat.api.DiktatLogLevel -import org.cqfn.diktat.api.DiktatReporterType -import org.cqfn.diktat.common.config.rules.DIKTAT -import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF -import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider -import com.pinterest.ktlint.core.Reporter -import kotlinx.cli.ArgParser -import kotlinx.cli.ArgType -import kotlinx.cli.default -import kotlinx.cli.multiple -import kotlinx.cli.vararg +import org.cqfn.diktat.api.DiktatError +import org.cqfn.diktat.api.DiktatMode +import org.cqfn.diktat.cli.DiktatProperties +import org.cqfn.diktat.ktlint.unwrap +import java.nio.file.Files +import java.nio.file.Paths +import kotlin.io.path.absolutePathString +import kotlin.io.path.extension fun main(args: Array) { - val parser = ArgParser(DIKTAT) - val config: String by parser.option( - type = ArgType.String, - fullName = "config", - shortName = "c", - description = """ - Specify the location of the YAML configuration file. - By default, $DIKTAT_ANALYSIS_CONF in the current - directory is used. - """.trimIndent(), - ).default(DIKTAT_ANALYSIS_CONF) - val doFormat: Boolean by parser.option( - type = ArgType.Boolean, - fullName = "format", - shortName = "F", - description = "Fix any deviations from the code style." - ).default(false) - val reporters: List by parser.option( - type = ArgType.Choice(), - fullName = "reporter", - shortName = "r", - description = "The reporter to use", - ) - .default(DiktatReporterType.PLAIN) - .multiple() - val output: String? by parser.option( - type = ArgType.String, - fullName = "output", - shortName = "o", - description = "Redirect the reporter output to a file.", - ) - val logLevel: DiktatLogLevel by parser.option( - type = ArgType.Choice(), - fullName = "log-level", - shortName = "l", - description = "Enable the output with specific level", - ).default(DiktatLogLevel.INFO) - val patterns: List by parser.argument( - type = ArgType.String, - description = "" - ) - .vararg() + val properties = DiktatProperties.parse(args) + properties.configureLogger() - parser.parse(args) - - val diktatRuleSetProvider = DiktatRuleSetProvider(config) + val reporter = properties.reporter() + reporter.beforeAll() + val currentFolder = Paths.get(".") + properties.patterns + .asSequence() + .flatMap { pattern -> + Files.newDirectoryStream(currentFolder, pattern).asSequence() + } + .map { file -> + val result = mutableListOf>() + DiktatProcessCommand.Builder() + .file(file) + .config(properties.config) + .callback { error, isCorrected -> + result.add(error to isCorrected) + } + .isScript(!file.extension.endsWith(".kt", ignoreCase = true)) + .logLevel(properties.logLevel) + .build() + .let { command -> + when (properties.mode) { + DiktatMode.CHECK -> command.check() + DiktatMode.FIX -> command.check() + } + } + file to result + } + .forEach { (file, result) -> + reporter.before(file.absolutePathString()) + result.forEach { (error, isCorrected) -> + reporter.onLintError(file.absolutePathString(), error.unwrap(), isCorrected) + } + reporter.after(file.absolutePathString()) + } + reporter.afterAll() } -// -//private fun loadReporter(): Reporter { -// -//} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index c2667014ab..7cb8d8284f 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -1,12 +1,13 @@ package org.cqfn.diktat import org.cqfn.diktat.api.DiktatCallback -import org.cqfn.diktat.api.DiktatLogLevel +import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF import org.cqfn.diktat.ktlint.unwrap import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider import com.pinterest.ktlint.core.KtLint import com.pinterest.ktlint.core.api.EditorConfigDefaults import com.pinterest.ktlint.core.api.EditorConfigOverride +import org.slf4j.event.Level import java.nio.file.Path import kotlin.io.path.absolutePathString @@ -19,9 +20,10 @@ import kotlin.io.path.absolutePathString class DiktatProcessCommand private constructor( val file: Path, val fileContent: String, + private val config: String, private val callback: DiktatCallback, private val isScript: Boolean, - private val logLevel: DiktatLogLevel, + private val logLevel: Level, ) { /** * Run `diktat fix` using parameters from current command @@ -41,13 +43,13 @@ class DiktatProcessCommand private constructor( private fun ktLintParams(): KtLint.ExperimentalParams = KtLint.ExperimentalParams( fileName = file.absolutePathString(), text = fileContent, - ruleSets = setOf(DiktatRuleSetProvider().get()), + ruleSets = setOf(DiktatRuleSetProvider(config).get()), ruleProviders = emptySet(), userData = emptyMap(), cb = callback.unwrap(), script = isScript, editorConfigPath = null, - debug = logLevel == DiktatLogLevel.DEBUG, + debug = logLevel == Level.DEBUG, editorConfigDefaults = EditorConfigDefaults.emptyEditorConfigDefaults, editorConfigOverride = EditorConfigOverride.emptyEditorConfigOverride, isInvokedFromCli = false @@ -58,6 +60,7 @@ class DiktatProcessCommand private constructor( * * @property file * @property fileContent + * @property config * @property callback * @property isScript * @property logLevel @@ -65,9 +68,10 @@ class DiktatProcessCommand private constructor( data class Builder( var file: Path? = null, var fileContent: String? = null, + var config: String = DIKTAT_ANALYSIS_CONF, var callback: DiktatCallback? = null, var isScript: Boolean? = null, - var logLevel: DiktatLogLevel = DiktatLogLevel.INFO, + var logLevel: Level = Level.INFO, ) { /** * @param file @@ -81,6 +85,12 @@ class DiktatProcessCommand private constructor( */ fun fileContent(fileContent: String) = apply { this.fileContent = fileContent } + /** + * @param config + * @return updated builder + */ + fun config(config: String) = apply { this.config = config } + /** * @param callback * @return updated builder @@ -97,7 +107,7 @@ class DiktatProcessCommand private constructor( * @param logLevel * @return updated builder */ - fun logLevel(logLevel: DiktatLogLevel) = apply { this.logLevel = logLevel } + fun logLevel(logLevel: Level) = apply { this.logLevel = logLevel } /** * @return built [DiktatProcessCommand] @@ -109,6 +119,7 @@ class DiktatProcessCommand private constructor( requireNotNull(fileContent) { "fileContent is required" }, + config, requireNotNull(callback) { "callback is required" }, diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt deleted file mode 100644 index 6e6e18641d..0000000000 --- a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.cqfn.diktat.api - -/** - * Log level of `diktat processing` - */ -enum class DiktatLogLevel { - DEBUG, - INFO, - ; -} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt b/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt deleted file mode 100644 index a5dc52225d..0000000000 --- a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.cqfn.diktat.api - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -/** - * Type of reporting in `diktat` - */ -@Serializable -enum class DiktatReporterType { - @SerialName("plain") - PLAIN, - @SerialName("json") - JSON, - @SerialName("sarif") - SARIF, - @SerialName("checkstyle") - CHECKSTYLE, - @SerialName("html") - HTML, -} diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 352293acb3..62fd3f733e 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -1,14 +1,22 @@ package org.cqfn.diktat.cli -import org.cqfn.diktat.api.DiktatLogLevel import org.cqfn.diktat.api.DiktatMode -import org.cqfn.diktat.api.DiktatReporterType import org.cqfn.diktat.common.config.rules.DIKTAT import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF +import org.cqfn.diktat.ktlint.reporterProvider +import com.pinterest.ktlint.core.Reporter +import com.pinterest.ktlint.core.ReporterProvider +import com.pinterest.ktlint.reporter.plain.internal.Color +import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.core.LoggerContext +import org.slf4j.event.Level +import java.io.PrintStream +import java.nio.file.Paths +import kotlin.io.path.createDirectories +import kotlin.io.path.outputStream import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default -import kotlinx.cli.multiple import kotlinx.cli.vararg /** @@ -21,10 +29,56 @@ import kotlinx.cli.vararg data class DiktatProperties( val config: String, val mode: DiktatMode, - val reporter: String, - val output: String, - val logLevel: DiktatLogLevel, + val reporterProvider: ReporterProvider<*>, + val output: String?, + val groupByFileInPlain: Boolean, + val colorInPlain: Color?, + val logLevel: Level, + val patterns: List, ) { + /** + * @return a configured [Reporter] + */ + fun reporter(): Reporter { + return reporterProvider.get( + out = output + ?.let { Paths.get(it) } + ?.also { it.parent.createDirectories() } + ?.outputStream() + ?.let { PrintStream(it) } + ?: System.out, + opt = buildMap { + colorInPlain?.let { + put("color", true) + put("color_name", it) + } ?: run { + put("color", false) + } + put("format", (mode == DiktatMode.FIX)) + put("group_by_file", groupByFileInPlain) + }.mapValues { it.toString() }, + ) + } + + /** + * Configure logger level using [logLevel] + */ + fun configureLogger() { + // set log level + LogManager.getContext(false) + .let { it as LoggerContext } + .also { ctx -> + ctx.configuration.rootLogger.level = when (logLevel) { + Level.ERROR -> org.apache.logging.log4j.Level.ERROR + Level.WARN -> org.apache.logging.log4j.Level.WARN + Level.INFO -> org.apache.logging.log4j.Level.INFO + Level.DEBUG -> org.apache.logging.log4j.Level.DEBUG + Level.TRACE -> org.apache.logging.log4j.Level.TRACE + } + } + .updateLoggers() + } + companion object { /** * @param args cli arguments @@ -48,26 +102,31 @@ data class DiktatProperties( shortName = "m", description = "Mode of `diktat` controls that `diktat` fixes or only finds any deviations from the code style." ).default(DiktatMode.CHECK) - val reporters: List by parser.option( - type = ArgType.Choice(), - fullName = "reporter", - shortName = "r", - description = "The reporter to use", - ) - .default(DiktatReporterType.PLAIN) - .multiple() + val reporterProvider: ReporterProvider<*> = parser.reporterProvider() val output: String? by parser.option( type = ArgType.String, fullName = "output", shortName = "o", description = "Redirect the reporter output to a file.", ) - val logLevel: DiktatLogLevel by parser.option( - type = ArgType.Choice(), + val groupByFileInPlain: Boolean by parser.option( + type = ArgType.Boolean, + fullName = "plain-group-by-file", + shortName = null, + description = "A flag for plain reporter" + ).default(false) + val color: Color? by parser.option( + type = ArgType.Choice(), + fullName = "plain-color", + shortName = null, + description = "Colorize the output." + ) + val logLevel: Level by parser.option( + type = ArgType.Choice(), fullName = "log-level", shortName = "l", description = "Enable the output with specific level", - ).default(DiktatLogLevel.INFO) + ).default(Level.INFO) val patterns: List by parser.argument( type = ArgType.String, description = "" @@ -75,13 +134,15 @@ data class DiktatProperties( .vararg() parser.parse(args) - return DiktatProperties( config = config, mode = mode, - reporter = "N/A", - output = "N/A", + reporterProvider = reporterProvider, + output = output, + groupByFileInPlain = groupByFileInPlain, + colorInPlain = color, logLevel = logLevel, + patterns = patterns, ) } } diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt index f9a5351927..28ae8e55bb 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt @@ -1,5 +1,6 @@ package org.cqfn.diktat.ktlint +import com.pinterest.ktlint.core.ReporterProvider import com.pinterest.ktlint.reporter.checkstyle.CheckStyleReporterProvider import com.pinterest.ktlint.reporter.html.HtmlReporterProvider import com.pinterest.ktlint.reporter.json.JsonReporterProvider @@ -7,9 +8,12 @@ import com.pinterest.ktlint.reporter.plain.PlainReporterProvider import com.pinterest.ktlint.reporter.sarif.SarifReporterProvider import kotlinx.cli.ArgParser import kotlinx.cli.ArgType +import kotlinx.cli.default -private val reporters = setOf( - PlainReporterProvider(), +private val plainReporterProvider = PlainReporterProvider() + +private val reporterProviders = setOf( + plainReporterProvider, JsonReporterProvider(), SarifReporterProvider(), CheckStyleReporterProvider(), @@ -17,11 +21,27 @@ private val reporters = setOf( ) .associateBy { it.id } -internal fun ArgParser.createReporterOption() { - return option( - ArgType.Choice { - - } - ArgType.Choice { } +/** + * @return a single [ReporterProvider] as parsed cli arg + */ +internal fun ArgParser.reporterProvider(): ReporterProvider<*> { + val reporterProviders: ReporterProvider<*> by this.option( + type = ArgType.Choice( + choices = reporterProviders.values.toList(), + toVariant = reporterProviders::getValue, + variantToString = ReporterProvider<*>::id, + ), + fullName = "reporter", + shortName = "r", + description = "The reporter to use" ) + .default(plainReporterProvider) + return reporterProviders +} + +/** + * @return true if receiver is [PlainReporterProvider] + */ +internal fun ReporterProvider<*>.isPlain(): Boolean { + return id == plainReporterProvider.id } diff --git a/diktat/src/main/resources/META-INF/version b/diktat/src/main/resources/META-INF/version new file mode 100644 index 0000000000..ad96e7cf93 --- /dev/null +++ b/diktat/src/main/resources/META-INF/version @@ -0,0 +1 @@ +${project.version} From 461a6f8320f7e9a15d6fa7cf4b179baeacfca7f5 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 21 Nov 2022 20:22:16 +0300 Subject: [PATCH 09/30] review notes --- diktat-rules/pom.xml | 29 +++-------- .../src/main/kotlin/generated/WarningNames.kt | 4 +- .../diktat/ruleset/generation/Generation.kt | 13 ++--- .../ruleset/generation/GenerationConstants.kt | 51 ------------------- diktat/pom.xml | 1 - .../org/cqfn/diktat/cli/DiktatProperties.kt | 12 ++++- pom.xml | 5 ++ 7 files changed, 32 insertions(+), 83 deletions(-) delete mode 100644 diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index f486df2276..f7b4cf55b7 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -126,36 +126,21 @@ org.codehaus.mojo exec-maven-plugin - - generate-constants - generate-sources - - java - - - org.cqfn.diktat.ruleset.generation.GenerationConstantsKt - - ${project.build.outputDirectory} - ${project.version} - ${project.basedir}/../LICENSE - - - generate-warnings generate-test-sources java - - org.cqfn.diktat.ruleset.generation.GenerationKt - - ${project.build.sourceDirectory} - ${project.basedir}/src/test/resources - - + + org.cqfn.diktat.ruleset.generation.GenerationKt + + ${project.build.sourceDirectory} + ${project.basedir}/src/test/resources + + diff --git a/diktat-rules/src/main/kotlin/generated/WarningNames.kt b/diktat-rules/src/main/kotlin/generated/WarningNames.kt index 8f38eb426f..a9d8781e0f 100644 --- a/diktat-rules/src/main/kotlin/generated/WarningNames.kt +++ b/diktat-rules/src/main/kotlin/generated/WarningNames.kt @@ -1,5 +1,5 @@ -// | This document was auto generated, please don't modify it. -// | This document contains all enum properties from Warnings.kt as Strings. +// This document was auto generated, please don't modify it. +// This document contains all enum properties from Warnings.kt as Strings. package generated import kotlin.String diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt index 637a2d56ab..975a7361e1 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt @@ -25,11 +25,15 @@ import kotlin.io.path.writeLines /** * The comment that will be added to the generated sources file. */ -internal const val autoGenerationComment = "This document was auto generated, please don't modify it." +private val autoGenerationComment = + """ + | This document was auto generated, please don't modify it. + | This document contains all enum properties from Warnings.kt as Strings. + """.trimMargin() fun main(args: Array) { require(args.size == 2) { - "Only four arguments are expected: " + "Only two arguments are expected: " } generateWarningNames(args[0]) validateYear(args[1]) @@ -55,10 +59,7 @@ private fun generateWarningNames(sourceDirectory: String) { .builder("generated", "WarningNames") .addType(fileBody) .indent(" ") - .addFileComment(""" - | $autoGenerationComment - | This document contains all enum properties from Warnings.kt as Strings. - """.trimIndent()) + .addFileComment(autoGenerationComment) .build() kotlinFile.writeTo(Paths.get(sourceDirectory)) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt deleted file mode 100644 index 3c0be8ebdb..0000000000 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/GenerationConstants.kt +++ /dev/null @@ -1,51 +0,0 @@ -/** - * This file contains code for codegen: generating a file with diktat constants - */ - -package org.cqfn.diktat.ruleset.generation - -import com.squareup.kotlinpoet.FileSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.PropertySpec - -import java.nio.file.Paths - -import kotlin.io.path.readText - - -fun main(args: Array) { - require(args.size == 3) { - "Only four arguments are expected: " - } - generateDiktatConstants(args[0], args[1], args[2]) -} - -private fun generateDiktatConstants( - sourceDirectory: String, - version: String, - licenseFile: String, -) { - FileSpec - .builder("generated", "DiktatConstants") - .addProperty( - PropertySpec.builder("DIKTAT_VERSION", String::class) - .addModifiers(KModifier.CONST) - .addModifiers(KModifier.INTERNAL) - .initializer("%S", version) - .build() - ) - .addProperty( - PropertySpec.builder("LICENSE", String::class) - .addModifiers(KModifier.CONST) - .addModifiers(KModifier.INTERNAL) - .initializer("%S", Paths.get(licenseFile).readText()) - .build() - ) - .indent(" ") - .addFileComment(""" - | $autoGenerationComment. - | This document contains diktat constants. - """.trimMargin()) - .build() - .writeTo(Paths.get(sourceDirectory)) -} diff --git a/diktat/pom.xml b/diktat/pom.xml index b5dc23b6fd..c3f19b9fa6 100644 --- a/diktat/pom.xml +++ b/diktat/pom.xml @@ -25,7 +25,6 @@ org.apache.logging.log4j log4j-core - 2.19.0 diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 62fd3f733e..6742261c55 100644 --- a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -3,6 +3,7 @@ package org.cqfn.diktat.cli import org.cqfn.diktat.api.DiktatMode import org.cqfn.diktat.common.config.rules.DIKTAT import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF +import org.cqfn.diktat.ktlint.isPlain import org.cqfn.diktat.ktlint.reporterProvider import com.pinterest.ktlint.core.Reporter import com.pinterest.ktlint.core.ReporterProvider @@ -26,6 +27,7 @@ import kotlinx.cli.vararg * @property output * @property logLevel */ +@Suppress("DEPRECATION") data class DiktatProperties( val config: String, val mode: DiktatMode, @@ -49,13 +51,21 @@ data class DiktatProperties( ?: System.out, opt = buildMap { colorInPlain?.let { + require(reporterProvider.isPlain()) { + "colorization is applicable only for plain reporter" + } put("color", true) put("color_name", it) } ?: run { put("color", false) } put("format", (mode == DiktatMode.FIX)) - put("group_by_file", groupByFileInPlain) + if (groupByFileInPlain) { + require(reporterProvider.isPlain()) { + "groupByFile is applicable only for plain reporter" + } + put("group_by_file", true) + } }.mapValues { it.toString() }, ) } diff --git a/pom.xml b/pom.xml index ce41015e2b..d9881da538 100644 --- a/pom.xml +++ b/pom.xml @@ -220,6 +220,11 @@ log4j-slf4j-impl ${log4j.version} + + org.apache.logging.log4j + log4j-core + ${log4j.version} + io.github.petertrr kotlin-multiplatform-diff-jvm From 530ef7991cfaa0d6f6e3bbe07390bfc1b8079f01 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 21 Nov 2022 20:23:40 +0300 Subject: [PATCH 10/30] review notes #2 --- diktat-rules/src/main/kotlin/generated/WarningNames.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diktat-rules/src/main/kotlin/generated/WarningNames.kt b/diktat-rules/src/main/kotlin/generated/WarningNames.kt index a9d8781e0f..8ef79dfbe5 100644 --- a/diktat-rules/src/main/kotlin/generated/WarningNames.kt +++ b/diktat-rules/src/main/kotlin/generated/WarningNames.kt @@ -1,5 +1,5 @@ -// This document was auto generated, please don't modify it. -// This document contains all enum properties from Warnings.kt as Strings. +// This document was auto generated, please don't modify it. +// This document contains all enum properties from Warnings.kt as Strings. package generated import kotlin.String From 72588b6b81d0cec2db8c0d3549982a78cf3dd0e1 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 22 Nov 2022 13:41:38 +0300 Subject: [PATCH 11/30] moved ruleset back --- {diktat => diktat-ruleset}/pom.xml | 0 .../src/main/kotlin/org/cqfn/diktat/DiktatMain.kt | 0 .../src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt | 0 .../src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt | 0 .../src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt | 0 .../src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt | 0 .../src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt | 0 .../kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt | 0 .../src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt | 0 .../src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt | 0 {diktat => diktat-ruleset}/src/main/resources/META-INF/version | 0 .../kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt | 0 .../kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt | 0 .../kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt | 0 .../src/test/resources/test/smoke/.gitignore | 0 .../src/test/resources/test/smoke/build.gradle_.kts | 0 .../src/test/resources/test/smoke/save.toml | 0 .../src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt | 0 .../src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt | 0 .../src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt | 0 .../test/smoke/src/main/kotlin/DefaultPackageExpected.kt | 0 .../resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt | 0 .../resources/test/smoke/src/main/kotlin/Example1-2Expected.kt | 0 .../resources/test/smoke/src/main/kotlin/Example1Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example1Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example2Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example2Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example3Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example3Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example4Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example4Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example5Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example5Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example6Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example6Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example7Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example7Test.kt | 0 .../resources/test/smoke/src/main/kotlin/Example8Expected.kt | 0 .../test/resources/test/smoke/src/main/kotlin/Example8Test.kt | 0 .../src/main/kotlin/KdocFormattingMultilineTagsExpected.kt | 0 .../smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt | 0 .../smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt | 0 .../test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt | 0 .../src/main/kotlin/ManyLineTransformInLongLineExpected.kt | 0 .../smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt | 0 .../smoke/src/main/kotlin/kotlin-library-expected.gradle.kts | 0 .../test/smoke/src/main/kotlin/kotlin-library.gradle.kts | 0 .../src/test/resources/test/smoke/src/main/kotlin/save.toml | 0 .../smoke/src/main/kotlin/script/PackageInScriptExpected.kts | 0 .../test/smoke/src/main/kotlin/script/PackageInScriptTest.kts | 0 .../smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts | 0 .../test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts | 0 pom.xml | 2 +- 54 files changed, 1 insertion(+), 1 deletion(-) rename {diktat => diktat-ruleset}/pom.xml (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt (100%) rename {diktat => diktat-ruleset}/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt (100%) rename {diktat => diktat-ruleset}/src/main/resources/META-INF/version (100%) rename {diktat => diktat-ruleset}/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt (100%) rename {diktat => diktat-ruleset}/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt (100%) rename {diktat => diktat-ruleset}/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/.gitignore (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/build.gradle_.kts (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/save.toml (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/save.toml (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts (100%) rename {diktat => diktat-ruleset}/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts (100%) diff --git a/diktat/pom.xml b/diktat-ruleset/pom.xml similarity index 100% rename from diktat/pom.xml rename to diktat-ruleset/pom.xml diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatCallback.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatError.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorCallbackWrapper.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/LintErrorWrapper.kt diff --git a/diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt similarity index 100% rename from diktat/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt rename to diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt diff --git a/diktat/src/main/resources/META-INF/version b/diktat-ruleset/src/main/resources/META-INF/version similarity index 100% rename from diktat/src/main/resources/META-INF/version rename to diktat-ruleset/src/main/resources/META-INF/version diff --git a/diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt b/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt similarity index 100% rename from diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt rename to diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSaveSmokeTest.kt diff --git a/diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt b/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt similarity index 100% rename from diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt rename to diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt diff --git a/diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt b/diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt similarity index 100% rename from diktat/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt rename to diktat-ruleset/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTestBase.kt diff --git a/diktat/src/test/resources/test/smoke/.gitignore b/diktat-ruleset/src/test/resources/test/smoke/.gitignore similarity index 100% rename from diktat/src/test/resources/test/smoke/.gitignore rename to diktat-ruleset/src/test/resources/test/smoke/.gitignore diff --git a/diktat/src/test/resources/test/smoke/build.gradle_.kts b/diktat-ruleset/src/test/resources/test/smoke/build.gradle_.kts similarity index 100% rename from diktat/src/test/resources/test/smoke/build.gradle_.kts rename to diktat-ruleset/src/test/resources/test/smoke/build.gradle_.kts diff --git a/diktat/src/test/resources/test/smoke/save.toml b/diktat-ruleset/src/test/resources/test/smoke/save.toml similarity index 100% rename from diktat/src/test/resources/test/smoke/save.toml rename to diktat-ruleset/src/test/resources/test/smoke/save.toml diff --git a/diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptExpected.kt diff --git a/diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt b/diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/jsMain/kotlin/org/cqfn/diktat/scripts/ScriptTest.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Bug1Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageExpected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/DefaultPackageTest.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1-2Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example1Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example2Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example5Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example6Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example7Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Expected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/Example8Test.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsExpected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/KdocFormattingMultilineTagsTest.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetExpected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/LocalVariableWithOffsetTest.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineExpected.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/ManyLineTransformInLongLineTest.kt diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library-expected.gradle.kts diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/kotlin-library.gradle.kts diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/save.toml b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/save.toml similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/save.toml rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/save.toml diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptExpected.kts diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/PackageInScriptTest.kts diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptExpected.kts diff --git a/diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts b/diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts similarity index 100% rename from diktat/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts rename to diktat-ruleset/src/test/resources/test/smoke/src/main/kotlin/script/SimpleRunInScriptTest.kts diff --git a/pom.xml b/pom.xml index d9881da538..1db2be8ee3 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ diktat-common diktat-rules diktat-test-framework - diktat + diktat-ruleset diktat-maven-plugin diktat-gradle-plugin From 53ca8cfa58e479ddba8ea92be123a171d66cc945 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 22 Nov 2022 13:46:21 +0300 Subject: [PATCH 12/30] review notes --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1db2be8ee3..ee64a4ae5f 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,6 @@ official 1.4.1 0.3.5 - ${kotlin.version}-1.0.8 0.47.1 5.9.1 1.9.1 @@ -408,7 +407,6 @@ src/main/kotlin src/main/resources - src/main/resources kotlinx-serialization From 3ecd3f002e4ec137789cbc1f5d6e9d83cb9a77aa Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 22 Nov 2022 15:30:07 +0300 Subject: [PATCH 13/30] fixed main --- diktat-maven-plugin/pom.xml | 1 - diktat-ruleset/pom.xml | 4 + .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 6 +- .../org/cqfn/diktat/DiktatProcessCommand.kt | 14 ++- .../org/cqfn/diktat/cli/DiktatProperties.kt | 70 +++--------- .../org/cqfn/diktat/ktlint/ReporterUtil.kt | 107 +++++++++++++++--- pom.xml | 5 + 7 files changed, 133 insertions(+), 74 deletions(-) diff --git a/diktat-maven-plugin/pom.xml b/diktat-maven-plugin/pom.xml index e1244be738..1d03c64fc0 100644 --- a/diktat-maven-plugin/pom.xml +++ b/diktat-maven-plugin/pom.xml @@ -49,7 +49,6 @@ org.cqfn.diktat diktat - ${project.version} com.pinterest.ktlint diff --git a/diktat-ruleset/pom.xml b/diktat-ruleset/pom.xml index c3f19b9fa6..806517bb5f 100644 --- a/diktat-ruleset/pom.xml +++ b/diktat-ruleset/pom.xml @@ -102,6 +102,10 @@ + + org.jetbrains.kotlin + kotlin-maven-plugin + org.apache.maven.plugins diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 2e11b5bb57..b86ca07979 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -8,6 +8,7 @@ import java.nio.file.Files import java.nio.file.Paths import kotlin.io.path.absolutePathString import kotlin.io.path.extension +import kotlin.io.path.writeText fun main(args: Array) { val properties = DiktatProperties.parse(args) @@ -36,7 +37,10 @@ fun main(args: Array) { .let { command -> when (properties.mode) { DiktatMode.CHECK -> command.check() - DiktatMode.FIX -> command.check() + DiktatMode.FIX -> { + val formattedFileContent = command.fix() + file.writeText(formattedFileContent, Charsets.UTF_8) + } } } file to result diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index df3dfee6e6..87ac5059a3 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -8,9 +8,13 @@ import com.pinterest.ktlint.core.KtLint import com.pinterest.ktlint.core.api.EditorConfigDefaults import com.pinterest.ktlint.core.api.EditorConfigOverride import org.intellij.lang.annotations.Language +import org.slf4j.Logger +import org.slf4j.LoggerFactory import org.slf4j.event.Level import java.nio.file.Path import kotlin.io.path.absolutePathString +import kotlin.io.path.extension +import kotlin.io.path.readText /** * Command to run `diktat` @@ -42,19 +46,23 @@ class DiktatProcessCommand private constructor( private fun ktLintParams(): KtLint.ExperimentalParams = KtLint.ExperimentalParams( fileName = file.absolutePathString(), - text = fileContent, + text = file.readText(Charsets.UTF_8), ruleSets = emptySet(), ruleProviders = DiktatRuleSetProviderV2(config).getRuleProviders(), userData = emptyMap(), cb = callback.unwrap(), - script = isScript, + script = file.extension.endsWith("kts"), editorConfigPath = null, - debug = logLevel == Level.DEBUG, + debug = isDebug, editorConfigDefaults = EditorConfigDefaults.emptyEditorConfigDefaults, editorConfigOverride = EditorConfigOverride.emptyEditorConfigOverride, isInvokedFromCli = false ) + private val isDebug: Boolean by lazy { + LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isDebugEnabled + } + /** * Builder for [DiktatProcessCommand] * diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 6742261c55..fff6e1386b 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -3,18 +3,13 @@ package org.cqfn.diktat.cli import org.cqfn.diktat.api.DiktatMode import org.cqfn.diktat.common.config.rules.DIKTAT import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF -import org.cqfn.diktat.ktlint.isPlain -import org.cqfn.diktat.ktlint.reporterProvider +import org.cqfn.diktat.ktlint.buildReporter +import org.cqfn.diktat.ktlint.colorName +import org.cqfn.diktat.ktlint.reporterProviderId import com.pinterest.ktlint.core.Reporter -import com.pinterest.ktlint.core.ReporterProvider -import com.pinterest.ktlint.reporter.plain.internal.Color import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.core.LoggerContext import org.slf4j.event.Level -import java.io.PrintStream -import java.nio.file.Paths -import kotlin.io.path.createDirectories -import kotlin.io.path.outputStream import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default @@ -27,48 +22,22 @@ import kotlinx.cli.vararg * @property output * @property logLevel */ -@Suppress("DEPRECATION") data class DiktatProperties( val config: String, val mode: DiktatMode, - val reporterProvider: ReporterProvider<*>, + val reporterProviderId: String, val output: String?, - val groupByFileInPlain: Boolean, - val colorInPlain: Color?, + private val groupByFileInPlain: Boolean, + private val colorNameInPlain: String?, val logLevel: Level, val patterns: List, ) { /** * @return a configured [Reporter] */ - fun reporter(): Reporter { - return reporterProvider.get( - out = output - ?.let { Paths.get(it) } - ?.also { it.parent.createDirectories() } - ?.outputStream() - ?.let { PrintStream(it) } - ?: System.out, - opt = buildMap { - colorInPlain?.let { - require(reporterProvider.isPlain()) { - "colorization is applicable only for plain reporter" - } - put("color", true) - put("color_name", it) - } ?: run { - put("color", false) - } - put("format", (mode == DiktatMode.FIX)) - if (groupByFileInPlain) { - require(reporterProvider.isPlain()) { - "groupByFile is applicable only for plain reporter" - } - put("group_by_file", true) - } - }.mapValues { it.toString() }, - ) - } + fun reporter(): Reporter = buildReporter( + reporterProviderId, output, colorNameInPlain, groupByFileInPlain, mode + ) /** * Configure logger level using [logLevel] @@ -100,11 +69,7 @@ data class DiktatProperties( type = ArgType.String, fullName = "config", shortName = "c", - description = """ - Specify the location of the YAML configuration file. - By default, $DIKTAT_ANALYSIS_CONF in the current - directory is used. - """.trimIndent(), + description = "Specify the location of the YAML configuration file. By default, $DIKTAT_ANALYSIS_CONF in the current directory is used.", ).default(DIKTAT_ANALYSIS_CONF) val mode: DiktatMode by parser.option( type = ArgType.Choice(), @@ -112,7 +77,7 @@ data class DiktatProperties( shortName = "m", description = "Mode of `diktat` controls that `diktat` fixes or only finds any deviations from the code style." ).default(DiktatMode.CHECK) - val reporterProvider: ReporterProvider<*> = parser.reporterProvider() + val reporterProviderId: String by parser.reporterProviderId() val output: String? by parser.option( type = ArgType.String, fullName = "output", @@ -125,12 +90,7 @@ data class DiktatProperties( shortName = null, description = "A flag for plain reporter" ).default(false) - val color: Color? by parser.option( - type = ArgType.Choice(), - fullName = "plain-color", - shortName = null, - description = "Colorize the output." - ) + val colorName: String? by parser.colorName() val logLevel: Level by parser.option( type = ArgType.Choice(), fullName = "log-level", @@ -139,7 +99,7 @@ data class DiktatProperties( ).default(Level.INFO) val patterns: List by parser.argument( type = ArgType.String, - description = "" + description = "A list of files to process by diktat" ) .vararg() @@ -147,10 +107,10 @@ data class DiktatProperties( return DiktatProperties( config = config, mode = mode, - reporterProvider = reporterProvider, + reporterProviderId = reporterProviderId, output = output, groupByFileInPlain = groupByFileInPlain, - colorInPlain = color, + colorNameInPlain = colorName, logLevel = logLevel, patterns = patterns, ) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt index 28ae8e55bb..70c2159492 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt @@ -1,11 +1,17 @@ package org.cqfn.diktat.ktlint +import org.cqfn.diktat.api.DiktatMode +import com.pinterest.ktlint.core.Reporter import com.pinterest.ktlint.core.ReporterProvider import com.pinterest.ktlint.reporter.checkstyle.CheckStyleReporterProvider import com.pinterest.ktlint.reporter.html.HtmlReporterProvider import com.pinterest.ktlint.reporter.json.JsonReporterProvider import com.pinterest.ktlint.reporter.plain.PlainReporterProvider import com.pinterest.ktlint.reporter.sarif.SarifReporterProvider +import java.io.PrintStream +import java.nio.file.Paths +import kotlin.io.path.createDirectories +import kotlin.io.path.outputStream import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default @@ -21,23 +27,56 @@ private val reporterProviders = setOf( ) .associateBy { it.id } +private const val defaultColorName = "DARK_GRAY" + +// supported color names in KtLint +private val colorNames = listOf( + "BLACK", + "RED", + "GREEN", + "YELLOW", + "BLUE", + "MAGENTA", + "CYAN", + "LIGHT_GRAY", + defaultColorName, + "LIGHT_RED", + "LIGHT_GREEN", + "LIGHT_YELLOW", + "LIGHT_BLUE", + "LIGHT_MAGENTA", + "LIGHT_CYAN", + "WHITE", +) + /** * @return a single [ReporterProvider] as parsed cli arg */ -internal fun ArgParser.reporterProvider(): ReporterProvider<*> { - val reporterProviders: ReporterProvider<*> by this.option( - type = ArgType.Choice( - choices = reporterProviders.values.toList(), - toVariant = reporterProviders::getValue, - variantToString = ReporterProvider<*>::id, - ), - fullName = "reporter", - shortName = "r", - description = "The reporter to use" - ) - .default(plainReporterProvider) - return reporterProviders -} +internal fun ArgParser.reporterProviderId() = option( + type = ArgType.Choice( + choices = reporterProviders.keys.toList(), + toVariant = { it }, + variantToString = { it }, + ), + fullName = "reporter", + shortName = "r", + description = "The reporter to use" +) + .default(plainReporterProvider.id) + +/** + * @return a single and optional color name as parsed cli args + */ +internal fun ArgParser.colorName() = this.option( + type = ArgType.Choice( + choices = colorNames, + toVariant = { it }, + variantToString = { it }, + ), + fullName = "plain-color", + shortName = null, + description = "Colorize the output.", +) /** * @return true if receiver is [PlainReporterProvider] @@ -45,3 +84,43 @@ internal fun ArgParser.reporterProvider(): ReporterProvider<*> { internal fun ReporterProvider<*>.isPlain(): Boolean { return id == plainReporterProvider.id } + +/** + * @return a configured [Reporter] + */ +internal fun buildReporter( + reporterProviderId: String, + output: String?, + colorNameInPlain: String?, + groupByFileInPlain: Boolean, + mode: DiktatMode, +): Reporter { + val reporterProvider = reporterProviders.getValue(reporterProviderId) + return reporterProvider.get( + out = output + ?.let { Paths.get(it) } + ?.also { it.parent.createDirectories() } + ?.outputStream() + ?.let { PrintStream(it) } + ?: System.out, + opt = buildMap { + colorNameInPlain?.let { + require(reporterProvider.isPlain()) { + "colorization is applicable only for plain reporter" + } + put("color", true) + put("color_name", it) + } ?: run { + put("color", false) + put("color_name", defaultColorName) + } + put("format", (mode == DiktatMode.FIX)) + if (groupByFileInPlain) { + require(reporterProvider.isPlain()) { + "groupByFile is applicable only for plain reporter" + } + put("group_by_file", true) + } + }.mapValues { it.toString() }, + ) +} diff --git a/pom.xml b/pom.xml index ee64a4ae5f..4708139310 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,11 @@ + + org.cqfn.diktat + diktat + ${project.version} + com.squareup kotlinpoet From 9f0b3799d6f2f61e0595dcacca4680afc3318828 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 14:48:01 +0300 Subject: [PATCH 14/30] fixed Glob search --- .../diktat/plugin/maven/DiktatBaseMojo.kt | 7 +--- .../cqfn/diktat/plugin/maven/DiktatMojo.kt | 3 +- .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 18 +++++++--- .../org/cqfn/diktat/DiktatProcessCommand.kt | 33 +------------------ .../org/cqfn/diktat/ktlint/ReporterUtil.kt | 2 +- 5 files changed, 19 insertions(+), 44 deletions(-) diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt index a6534fc2fc..cf39d3a315 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt @@ -26,7 +26,6 @@ import org.apache.maven.plugin.MojoExecutionException import org.apache.maven.plugin.MojoFailureException import org.apache.maven.plugins.annotations.Parameter import org.apache.maven.project.MavenProject -import org.slf4j.event.Level import java.io.File import java.io.FileOutputStream @@ -40,6 +39,7 @@ abstract class DiktatBaseMojo : AbstractMojo() { * Flag that indicates whether to turn debug logging on */ @Parameter(property = "diktat.debug") + // TODO: need to check that debug is enabled in log is detected by SLF4J in diktat var debug = false /** @@ -240,8 +240,6 @@ abstract class DiktatBaseMojo : AbstractMojo() { ) { val command = DiktatProcessCommand.Builder() .file(file.toPath()) - .fileContent(file.readText(Charsets.UTF_8)) - .isScript(file.extension.equals("kts", ignoreCase = true)) .callback { error, isCorrected -> val ktLintError = error.unwrap() if (!baselineErrors.containsLintError(ktLintError)) { @@ -249,9 +247,6 @@ abstract class DiktatBaseMojo : AbstractMojo() { lintErrors.add(ktLintError) } } - .logLevel( - if (debug) Level.DEBUG else Level.INFO - ) .build() runAction(command) } diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatMojo.kt index bc230de2b6..2f716a322f 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatMojo.kt @@ -9,6 +9,7 @@ import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProviderV2 import org.apache.maven.plugins.annotations.Mojo import kotlin.io.path.absolutePathString +import kotlin.io.path.readText import kotlin.io.path.writeText /** @@ -37,7 +38,7 @@ class DiktatFixMojo : DiktatBaseMojo() { */ override fun runAction(command: DiktatProcessCommand) { val fileName = command.file.absolutePathString() - val fileContent = command.fileContent + val fileContent = command.file.readText(Charsets.UTF_8) val formattedText = command.fix() if (fileContent != formattedText) { log.info("Original and formatted content differ, writing to $fileName...") diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index b86ca07979..1f746f4da8 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -4,10 +4,13 @@ import org.cqfn.diktat.api.DiktatError import org.cqfn.diktat.api.DiktatMode import org.cqfn.diktat.cli.DiktatProperties import org.cqfn.diktat.ktlint.unwrap -import java.nio.file.Files +import java.nio.file.InvalidPathException +import java.nio.file.Path import java.nio.file.Paths import kotlin.io.path.absolutePathString +import kotlin.io.path.exists import kotlin.io.path.extension +import kotlin.io.path.listDirectoryEntries import kotlin.io.path.writeText fun main(args: Array) { @@ -21,8 +24,11 @@ fun main(args: Array) { properties.patterns .asSequence() .flatMap { pattern -> - Files.newDirectoryStream(currentFolder, pattern).asSequence() + pattern.tryToPath()?.let { sequenceOf(it) } + ?: currentFolder.listDirectoryEntries(pattern).asSequence() } + .filter { file -> file.extension in setOf("kt", "kts") } + .distinct() .map { file -> val result = mutableListOf>() DiktatProcessCommand.Builder() @@ -31,8 +37,6 @@ fun main(args: Array) { .callback { error, isCorrected -> result.add(error to isCorrected) } - .isScript(!file.extension.endsWith(".kt", ignoreCase = true)) - .logLevel(properties.logLevel) .build() .let { command -> when (properties.mode) { @@ -54,3 +58,9 @@ fun main(args: Array) { } reporter.afterAll() } + +private fun String.tryToPath(): Path? = try { + Paths.get(this).takeIf { it.exists() } +} catch (e: InvalidPathException) { + null +} diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index 87ac5059a3..faa9000961 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -24,11 +24,8 @@ import kotlin.io.path.readText */ class DiktatProcessCommand private constructor( val file: Path, - @Language("kotlin") val fileContent: String, private val config: String, private val callback: DiktatCallback, - private val isScript: Boolean, - private val logLevel: Level, ) { /** * Run `diktat fix` using parameters from current command @@ -51,7 +48,7 @@ class DiktatProcessCommand private constructor( ruleProviders = DiktatRuleSetProviderV2(config).getRuleProviders(), userData = emptyMap(), cb = callback.unwrap(), - script = file.extension.endsWith("kts"), + script = file.extension.endsWith("kts", ignoreCase = true), editorConfigPath = null, debug = isDebug, editorConfigDefaults = EditorConfigDefaults.emptyEditorConfigDefaults, @@ -67,11 +64,8 @@ class DiktatProcessCommand private constructor( * Builder for [DiktatProcessCommand] * * @property file - * @property fileContent * @property config * @property callback - * @property isScript - * @property logLevel */ data class Builder( var file: Path? = null, @@ -87,12 +81,6 @@ class DiktatProcessCommand private constructor( */ fun file(file: Path) = apply { this.file = file } - /** - * @param fileContent - * @return updated builder - */ - fun fileContent(@Language("kotlin") fileContent: String) = apply { this.fileContent = fileContent } - /** * @param config * @return updated builder @@ -105,18 +93,6 @@ class DiktatProcessCommand private constructor( */ fun callback(callback: DiktatCallback) = apply { this.callback = callback } - /** - * @param isScript - * @return updated builder - */ - fun isScript(isScript: Boolean) = apply { this.isScript = isScript } - - /** - * @param logLevel - * @return updated builder - */ - fun logLevel(logLevel: Level) = apply { this.logLevel = logLevel } - /** * @return built [DiktatProcessCommand] */ @@ -124,17 +100,10 @@ class DiktatProcessCommand private constructor( requireNotNull(file) { "file is required" }, - requireNotNull(fileContent) { - "fileContent is required" - }, config, requireNotNull(callback) { "callback is required" }, - requireNotNull(isScript) { - "isScript is required" - }, - logLevel, ) } } diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt index 70c2159492..098a9ec5bc 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt @@ -121,6 +121,6 @@ internal fun buildReporter( } put("group_by_file", true) } - }.mapValues { it.toString() }, + }.mapValues { it.value.toString() }, ) } From a60c2d6391ca45781f8608cb879d830f9458f110 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 15:14:38 +0300 Subject: [PATCH 15/30] removed TODO --- .../kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt index cf39d3a315..0b049f9e27 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt @@ -35,13 +35,6 @@ import java.io.PrintStream * Base [Mojo] for checking and fixing code using diktat */ abstract class DiktatBaseMojo : AbstractMojo() { - /** - * Flag that indicates whether to turn debug logging on - */ - @Parameter(property = "diktat.debug") - // TODO: need to check that debug is enabled in log is detected by SLF4J in diktat - var debug = false - /** * Property that will be used if you need to publish the report to GitHub */ From 3413b69e3e80a8e6654826a206edaf7a227da61a Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 15:18:06 +0300 Subject: [PATCH 16/30] fixed path --- diktat-ruleset/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diktat-ruleset/pom.xml b/diktat-ruleset/pom.xml index 806517bb5f..6b169771fb 100644 --- a/diktat-ruleset/pom.xml +++ b/diktat-ruleset/pom.xml @@ -90,7 +90,7 @@ version - /META-INF/diktat + META-INF/diktat true @@ -98,7 +98,7 @@ LICENSE - /META-INF/diktat + META-INF/diktat From ed3bf1a1213c17e0263a57391972afa25907bad3 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 15:35:08 +0300 Subject: [PATCH 17/30] diktat:fix --- .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 24 +++++++++++++------ .../org/cqfn/diktat/DiktatProcessCommand.kt | 12 ++++++---- .../kotlin/org/cqfn/diktat/api/DiktatMode.kt | 1 + .../org/cqfn/diktat/cli/DiktatProperties.kt | 11 +++++---- .../org/cqfn/diktat/ktlint/ReporterUtil.kt | 21 ++++++++++------ 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 1f746f4da8..34ea92651f 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -1,3 +1,7 @@ +/** + * The file contains main method + */ + package org.cqfn.diktat import org.cqfn.diktat.api.DiktatError @@ -13,6 +17,18 @@ import kotlin.io.path.extension import kotlin.io.path.listDirectoryEntries import kotlin.io.path.writeText +typealias DiktatErrorWithCorrectionInfo = Pair + +private fun String.tryToPath(): Path? = try { + Paths.get(this).takeIf { it.exists() } +} catch (e: InvalidPathException) { + null +} + +@Suppress( + "LongMethod", + "TOO_LONG_FUNCTION" +) fun main(args: Array) { val properties = DiktatProperties.parse(args) properties.configureLogger() @@ -30,7 +46,7 @@ fun main(args: Array) { .filter { file -> file.extension in setOf("kt", "kts") } .distinct() .map { file -> - val result = mutableListOf>() + val result: MutableList = mutableListOf() DiktatProcessCommand.Builder() .file(file) .config(properties.config) @@ -58,9 +74,3 @@ fun main(args: Array) { } reporter.afterAll() } - -private fun String.tryToPath(): Path? = try { - Paths.get(this).takeIf { it.exists() } -} catch (e: InvalidPathException) { - null -} diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index faa9000961..cbf0da96de 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -20,13 +20,16 @@ import kotlin.io.path.readText * Command to run `diktat` * * @property file - * @property fileContent */ class DiktatProcessCommand private constructor( val file: Path, private val config: String, private val callback: DiktatCallback, ) { + private val isDebug: Boolean by lazy { + LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isDebugEnabled + } + /** * Run `diktat fix` using parameters from current command * @@ -56,16 +59,15 @@ class DiktatProcessCommand private constructor( isInvokedFromCli = false ) - private val isDebug: Boolean by lazy { - LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isDebugEnabled - } - /** * Builder for [DiktatProcessCommand] * * @property file * @property config * @property callback + * @property fileContent + * @property isScript + * @property logLevel */ data class Builder( var file: Path? = null, diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt index 4f3499660b..aabe4ea9c5 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/api/DiktatMode.kt @@ -12,4 +12,5 @@ enum class DiktatMode { CHECK, @SerialName("fix") FIX, + ; } diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index fff6e1386b..37399b9d4d 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -18,9 +18,9 @@ import kotlinx.cli.vararg /** * @property config path to `diktat-analysis.yml` * @property mode mode of `diktat` - * @property reporter + * @property reporterProviderId * @property output - * @property logLevel + * @property patterns */ data class DiktatProperties( val config: String, @@ -29,7 +29,7 @@ data class DiktatProperties( val output: String?, private val groupByFileInPlain: Boolean, private val colorNameInPlain: String?, - val logLevel: Level, + private val logLevel: Level, val patterns: List, ) { /** @@ -63,6 +63,10 @@ data class DiktatProperties( * @param args cli arguments * @return parsed [DiktatProperties] */ + @Suppress( + "LongMethod", + "TOO_LONG_FUNCTION" + ) fun parse(args: Array): DiktatProperties { val parser = ArgParser(DIKTAT) val config: String by parser.option( @@ -117,4 +121,3 @@ data class DiktatProperties( } } } - diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt index 098a9ec5bc..6cc546638b 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/ktlint/ReporterUtil.kt @@ -1,3 +1,7 @@ +/** + * File contains util methods to create ktlint's [Reporter] + */ + package org.cqfn.diktat.ktlint import org.cqfn.diktat.api.DiktatMode @@ -16,6 +20,8 @@ import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default +private const val DEFAULT_COLOR_NAME = "DARK_GRAY" + private val plainReporterProvider = PlainReporterProvider() private val reporterProviders = setOf( @@ -27,8 +33,6 @@ private val reporterProviders = setOf( ) .associateBy { it.id } -private const val defaultColorName = "DARK_GRAY" - // supported color names in KtLint private val colorNames = listOf( "BLACK", @@ -39,7 +43,7 @@ private val colorNames = listOf( "MAGENTA", "CYAN", "LIGHT_GRAY", - defaultColorName, + DEFAULT_COLOR_NAME, "LIGHT_RED", "LIGHT_GREEN", "LIGHT_YELLOW", @@ -81,11 +85,14 @@ internal fun ArgParser.colorName() = this.option( /** * @return true if receiver is [PlainReporterProvider] */ -internal fun ReporterProvider<*>.isPlain(): Boolean { - return id == plainReporterProvider.id -} +internal fun ReporterProvider<*>.isPlain(): Boolean = id == plainReporterProvider.id /** + * @param reporterProviderId + * @param output + * @param colorNameInPlain + * @param groupByFileInPlain + * @param mode * @return a configured [Reporter] */ internal fun buildReporter( @@ -112,7 +119,7 @@ internal fun buildReporter( put("color_name", it) } ?: run { put("color", false) - put("color_name", defaultColorName) + put("color_name", DEFAULT_COLOR_NAME) } put("format", (mode == DiktatMode.FIX)) if (groupByFileInPlain) { From fb434147ca732948b3f970a40a85d903e97d1860 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 15:45:11 +0300 Subject: [PATCH 18/30] removed debug from tests --- .../cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt index 5f76547344..0d2ef274ab 100644 --- a/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt +++ b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt @@ -44,11 +44,11 @@ class DiktatBaseMojoTest { xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + org.cqfn.diktat diktat-test 1.0.0-SNAPSHOT - + @@ -70,7 +70,6 @@ class DiktatBaseMojoTest { val mavenProject = projectBuilder.build(pom, buildingRequest).project val diktatCheckMojo = mojoRule.lookupConfiguredMojo(mavenProject, "check") as DiktatCheckMojo - Assertions.assertFalse(diktatCheckMojo.debug) Assertions.assertEquals("diktat-analysis.yml", diktatCheckMojo.diktatConfigFile) Assertions.assertIterableEquals(listOf(pom.parentFile.toPath() / "src"), diktatCheckMojo.inputs.map { Path(it) }) Assertions.assertTrue(diktatCheckMojo.excludes.isEmpty()) @@ -85,18 +84,17 @@ class DiktatBaseMojoTest { xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + org.cqfn.diktat diktat-test 1.0.0-SNAPSHOT - + org.cqfn.diktat diktat-maven-plugin - true my-diktat-config.yml ${'$'}{project.basedir}/src/main/kotlin @@ -122,7 +120,6 @@ class DiktatBaseMojoTest { val mavenProject = projectBuilder.build(pom, buildingRequest).project val diktatCheckMojo = mojoRule.lookupConfiguredMojo(mavenProject, "check") as DiktatCheckMojo - Assertions.assertTrue(diktatCheckMojo.debug) Assertions.assertEquals("my-diktat-config.yml", diktatCheckMojo.diktatConfigFile) Assertions.assertIterableEquals( listOf(pom.parentFile.toPath() / "src/main/kotlin", pom.parentFile.toPath() / "src/test/kotlin"), From 1161f4dae414ed98859c13c0a9bca4b11d696e10 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 15:47:37 +0300 Subject: [PATCH 19/30] extra changes --- .../kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt index 0d2ef274ab..68aecd31bb 100644 --- a/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt +++ b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt @@ -84,7 +84,7 @@ class DiktatBaseMojoTest { xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + org.cqfn.diktat diktat-test 1.0.0-SNAPSHOT From fffff4dbb89f21da76b05884859fc50197072a13 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 15:51:32 +0300 Subject: [PATCH 20/30] extra changes --- .../kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt index 68aecd31bb..0d2ef274ab 100644 --- a/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt +++ b/diktat-maven-plugin/src/test/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojoTest.kt @@ -84,7 +84,7 @@ class DiktatBaseMojoTest { xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + org.cqfn.diktat diktat-test 1.0.0-SNAPSHOT From ad567c5f01c910e0d251775499b430d1d2c6c8cc Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 18:33:57 +0300 Subject: [PATCH 21/30] load rules once --- .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 17 ++++++++- .../org/cqfn/diktat/DiktatProcessCommand.kt | 35 ++++++++++++------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 34ea92651f..7c05ea6861 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -7,7 +7,10 @@ package org.cqfn.diktat import org.cqfn.diktat.api.DiktatError import org.cqfn.diktat.api.DiktatMode import org.cqfn.diktat.cli.DiktatProperties +import org.cqfn.diktat.common.utils.loggerWithKtlintConfig import org.cqfn.diktat.ktlint.unwrap +import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactory +import mu.KotlinLogging import java.nio.file.InvalidPathException import java.nio.file.Path import java.nio.file.Paths @@ -17,6 +20,8 @@ import kotlin.io.path.extension import kotlin.io.path.listDirectoryEntries import kotlin.io.path.writeText +private val log = KotlinLogging.loggerWithKtlintConfig {} + typealias DiktatErrorWithCorrectionInfo = Pair private fun String.tryToPath(): Path? = try { @@ -33,9 +38,16 @@ fun main(args: Array) { val properties = DiktatProperties.parse(args) properties.configureLogger() + log.debug { + "Load diktatRuleSet using config ${properties.config}" + } + val diktatRuleSetFactory = DiktatRuleSetFactory(properties.config) val reporter = properties.reporter() reporter.beforeAll() + log.debug { + "Resole files by patterns: ${properties.patterns}" + } val currentFolder = Paths.get(".") properties.patterns .asSequence() @@ -46,10 +58,13 @@ fun main(args: Array) { .filter { file -> file.extension in setOf("kt", "kts") } .distinct() .map { file -> + log.debug { + "Start processing the file: $file" + } val result: MutableList = mutableListOf() DiktatProcessCommand.Builder() .file(file) - .config(properties.config) + .diktatRuleSetFactory(diktatRuleSetFactory) .callback { error, isCorrected -> result.add(error to isCorrected) } diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index cbf0da96de..5f50d760b3 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -3,14 +3,13 @@ package org.cqfn.diktat import org.cqfn.diktat.api.DiktatCallback import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF import org.cqfn.diktat.ktlint.unwrap +import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactory import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProviderV2 import com.pinterest.ktlint.core.KtLint import com.pinterest.ktlint.core.api.EditorConfigDefaults import com.pinterest.ktlint.core.api.EditorConfigOverride -import org.intellij.lang.annotations.Language import org.slf4j.Logger import org.slf4j.LoggerFactory -import org.slf4j.event.Level import java.nio.file.Path import kotlin.io.path.absolutePathString import kotlin.io.path.extension @@ -23,7 +22,7 @@ import kotlin.io.path.readText */ class DiktatProcessCommand private constructor( val file: Path, - private val config: String, + private val diktatRuleSetFactory: DiktatRuleSetFactory, private val callback: DiktatCallback, ) { private val isDebug: Boolean by lazy { @@ -48,7 +47,7 @@ class DiktatProcessCommand private constructor( fileName = file.absolutePathString(), text = file.readText(Charsets.UTF_8), ruleSets = emptySet(), - ruleProviders = DiktatRuleSetProviderV2(config).getRuleProviders(), + ruleProviders = DiktatRuleSetProviderV2(diktatRuleSetFactory).getRuleProviders(), userData = emptyMap(), cb = callback.unwrap(), script = file.extension.endsWith("kts", ignoreCase = true), @@ -63,19 +62,15 @@ class DiktatProcessCommand private constructor( * Builder for [DiktatProcessCommand] * * @property file + * @property diktatRuleSetFactory * @property config * @property callback - * @property fileContent - * @property isScript - * @property logLevel */ data class Builder( var file: Path? = null, - @Language("kotlin") var fileContent: String? = null, - var config: String = DIKTAT_ANALYSIS_CONF, + var diktatRuleSetFactory: DiktatRuleSetFactory? = null, + var config: String? = null, var callback: DiktatCallback? = null, - var isScript: Boolean? = null, - var logLevel: Level = Level.INFO, ) { /** * @param file @@ -83,11 +78,25 @@ class DiktatProcessCommand private constructor( */ fun file(file: Path) = apply { this.file = file } + /** + * @param diktatRuleSetFactory + * @return updated builder + */ + fun diktatRuleSetFactory(diktatRuleSetFactory: DiktatRuleSetFactory) = require(config == null) { + "diktatRuleSetFactory is set already via config" + }.let { + apply { this.diktatRuleSetFactory = diktatRuleSetFactory } + } + /** * @param config * @return updated builder */ - fun config(config: String) = apply { this.config = config } + fun config(config: String) = require(diktatRuleSetFactory == null) { + "diktatRuleSetFactory is already provided directly" + }.let { + apply { this.config = config } + } /** * @param callback @@ -102,7 +111,7 @@ class DiktatProcessCommand private constructor( requireNotNull(file) { "file is required" }, - config, + diktatRuleSetFactory ?: DiktatRuleSetFactory(config ?: DIKTAT_ANALYSIS_CONF), requireNotNull(callback) { "callback is required" }, From 0213beba2d2fa14a46c7670e5a9378e233d13533 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 18:43:08 +0300 Subject: [PATCH 22/30] load rules once --- diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 7c05ea6861..9bf377c7f1 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -20,6 +20,7 @@ import kotlin.io.path.extension import kotlin.io.path.listDirectoryEntries import kotlin.io.path.writeText +@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR") private val log = KotlinLogging.loggerWithKtlintConfig {} typealias DiktatErrorWithCorrectionInfo = Pair @@ -39,14 +40,14 @@ fun main(args: Array) { properties.configureLogger() log.debug { - "Load diktatRuleSet using config ${properties.config}" + "Loading diktatRuleSet using config ${properties.config}" } val diktatRuleSetFactory = DiktatRuleSetFactory(properties.config) val reporter = properties.reporter() reporter.beforeAll() log.debug { - "Resole files by patterns: ${properties.patterns}" + "Resolving files by patterns: ${properties.patterns}" } val currentFolder = Paths.get(".") properties.patterns From f5dd64f15e82061eed0d4167b14b588cfce0d9c8 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 19:08:00 +0300 Subject: [PATCH 23/30] fixed search by glob --- .../src/main/kotlin/org/cqfn/diktat/DiktatMain.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 9bf377c7f1..990ba0ca1d 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -14,10 +14,12 @@ import mu.KotlinLogging import java.nio.file.InvalidPathException import java.nio.file.Path import java.nio.file.Paths +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.PathWalkOption import kotlin.io.path.absolutePathString import kotlin.io.path.exists import kotlin.io.path.extension -import kotlin.io.path.listDirectoryEntries +import kotlin.io.path.walk import kotlin.io.path.writeText @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR") @@ -31,6 +33,7 @@ private fun String.tryToPath(): Path? = try { null } +@OptIn(ExperimentalPathApi::class) @Suppress( "LongMethod", "TOO_LONG_FUNCTION" @@ -54,10 +57,16 @@ fun main(args: Array) { .asSequence() .flatMap { pattern -> pattern.tryToPath()?.let { sequenceOf(it) } - ?: currentFolder.listDirectoryEntries(pattern).asSequence() + ?: run { + // create a matcher and return a filter that uses it. + val matcher = currentFolder.fileSystem.getPathMatcher("glob:$pattern") + currentFolder.walk(PathWalkOption.INCLUDE_DIRECTORIES) + .filter { matcher.matches(it) } + } } .filter { file -> file.extension in setOf("kt", "kts") } .distinct() + .map { it.normalize() } .map { file -> log.debug { "Start processing the file: $file" From 52945cfcd0e9bc44c694f1dd05e3e97c8173c939 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 23 Nov 2022 19:47:10 +0300 Subject: [PATCH 24/30] version and license --- .../org/cqfn/diktat/cli/DiktatProperties.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 37399b9d4d..675aa445d3 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -10,9 +10,13 @@ import com.pinterest.ktlint.core.Reporter import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.core.LoggerContext import org.slf4j.event.Level +import kotlin.system.exitProcess import kotlinx.cli.ArgParser import kotlinx.cli.ArgType +import kotlinx.cli.ExperimentalCli +import kotlinx.cli.Subcommand import kotlinx.cli.default +import kotlinx.cli.optional import kotlinx.cli.vararg /** @@ -63,6 +67,7 @@ data class DiktatProperties( * @param args cli arguments * @return parsed [DiktatProperties] */ + @OptIn(ExperimentalCli::class) @Suppress( "LongMethod", "TOO_LONG_FUNCTION" @@ -107,6 +112,33 @@ data class DiktatProperties( ) .vararg() + parser.subcommands( + object : Subcommand("version", "Output version information and exit.") { + override fun execute() { + println(readFromResource("META-INF/diktat/version")) + exitProcess(0) + } + }, + object : Subcommand("license", "Display the license and exit.") { + override fun execute() { + println(readFromResource("META-INF/diktat/LICENSE")) + exitProcess(0) + } + }, + ) +// val showVersion: Boolean? by parser.option( +// type = ArgType.Boolean, +// fullName = "version", +// shortName = "V", +// description = "Output version information and exit." +// ) +// val showLicense: Boolean? by parser.option( +// type = ArgType.Boolean, +// fullName = "license", +// shortName = null, +// description = "Display the license and exit." +// ) + parser.parse(args) return DiktatProperties( config = config, @@ -119,5 +151,11 @@ data class DiktatProperties( patterns = patterns, ) } + + private fun readFromResource(resourceName: String): String = DiktatProperties::class.java + .classLoader + .getResource(resourceName) + ?.readText() + ?: error("Resource $resourceName not found") } } From 3f7a177086cdd8b813339d10054878f802a9ac2a Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 24 Nov 2022 12:01:55 +0300 Subject: [PATCH 25/30] version and license --- .../org/cqfn/diktat/cli/DiktatProperties.kt | 65 ++++++++++--------- .../src/main/resources/META-INF/version | 3 +- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 675aa445d3..7d9a6180ae 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -13,10 +13,7 @@ import org.slf4j.event.Level import kotlin.system.exitProcess import kotlinx.cli.ArgParser import kotlinx.cli.ArgType -import kotlinx.cli.ExperimentalCli -import kotlinx.cli.Subcommand import kotlinx.cli.default -import kotlinx.cli.optional import kotlinx.cli.vararg /** @@ -67,7 +64,6 @@ data class DiktatProperties( * @param args cli arguments * @return parsed [DiktatProperties] */ - @OptIn(ExperimentalCli::class) @Suppress( "LongMethod", "TOO_LONG_FUNCTION" @@ -109,35 +105,22 @@ data class DiktatProperties( val patterns: List by parser.argument( type = ArgType.String, description = "A list of files to process by diktat" - ) - .vararg() + ).vararg() - parser.subcommands( - object : Subcommand("version", "Output version information and exit.") { - override fun execute() { - println(readFromResource("META-INF/diktat/version")) - exitProcess(0) - } - }, - object : Subcommand("license", "Display the license and exit.") { - override fun execute() { - println(readFromResource("META-INF/diktat/LICENSE")) - exitProcess(0) - } - }, + parser.addOptionAndShowResourceWithExit( + fullName = "version", + shortName = "V", + description = "Output version information and exit.", + args = args, + resourceName = "META-INF/diktat/version" + ) + parser.addOptionAndShowResourceWithExit( + fullName = "license", + shortName = null, + description = "Display the license and exit.", + args = args, + resourceName = "META-INF/diktat/LICENSE", ) -// val showVersion: Boolean? by parser.option( -// type = ArgType.Boolean, -// fullName = "version", -// shortName = "V", -// description = "Output version information and exit." -// ) -// val showLicense: Boolean? by parser.option( -// type = ArgType.Boolean, -// fullName = "license", -// shortName = null, -// description = "Display the license and exit." -// ) parser.parse(args) return DiktatProperties( @@ -152,6 +135,26 @@ data class DiktatProperties( ) } + private fun ArgParser.addOptionAndShowResourceWithExit( + fullName: String, + shortName: String?, + description: String, + args: Array, + resourceName: String, + ) { + // add here to print in help + option( + type = ArgType.Boolean, + fullName = fullName, + shortName = shortName, + description = description + ) + if (args.contains("--$fullName") || shortName?.let { args.contains("-$it") } == true) { + println(readFromResource(resourceName)) + exitProcess(0) + } + } + private fun readFromResource(resourceName: String): String = DiktatProperties::class.java .classLoader .getResource(resourceName) diff --git a/diktat-ruleset/src/main/resources/META-INF/version b/diktat-ruleset/src/main/resources/META-INF/version index ad96e7cf93..abae2e47cf 100644 --- a/diktat-ruleset/src/main/resources/META-INF/version +++ b/diktat-ruleset/src/main/resources/META-INF/version @@ -1 +1,2 @@ -${project.version} +diktat: ${project.version} +ktlint: ${ktlint.version} From 6683f91b29dfb37822396a0f6222f23ff74e0e3c Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 24 Nov 2022 12:17:13 +0300 Subject: [PATCH 26/30] review notes --- diktat-common/pom.xml | 34 ---------------- diktat-maven-plugin/pom.xml | 22 ----------- diktat-rules/pom.xml | 23 ----------- .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 14 ++----- .../org/cqfn/diktat/cli/DiktatProperties.kt | 3 +- .../kotlin/org/cqfn/diktat/util/FileUtils.kt | 34 ++++++++++++++++ diktat-test-framework/pom.xml | 39 ------------------- 7 files changed, 39 insertions(+), 130 deletions(-) create mode 100644 diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt diff --git a/diktat-common/pom.xml b/diktat-common/pom.xml index fdf999e628..686ac1d5d9 100644 --- a/diktat-common/pom.xml +++ b/diktat-common/pom.xml @@ -57,40 +57,6 @@ org.jetbrains.kotlin kotlin-maven-plugin - - - compile - process-sources - - compile - - - - test-compile - process-test-sources - - test-compile - - - - src/test/kotlin - src/test/resources - - - - - - - kotlinx-serialization - - - - - org.jetbrains.kotlin - kotlin-maven-serialization - ${kotlin.version} - - diff --git a/diktat-maven-plugin/pom.xml b/diktat-maven-plugin/pom.xml index 1d03c64fc0..1a9231b0b5 100644 --- a/diktat-maven-plugin/pom.xml +++ b/diktat-maven-plugin/pom.xml @@ -115,28 +115,6 @@ org.jetbrains.kotlin kotlin-maven-plugin - - - compile - process-sources - - compile - - - - test-compile - process-test-sources - - test-compile - - - - - src/test/kotlin - - - - org.apache.maven.plugins diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index f7b4cf55b7..37e3b944d2 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -96,29 +96,6 @@ - - compile - compile - - compile - - - - test-compile - process-test-sources - - test-compile - - - - - src/main/kotlin - src/test/kotlin - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index 990ba0ca1d..c59cf7ebc8 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -10,6 +10,8 @@ import org.cqfn.diktat.cli.DiktatProperties import org.cqfn.diktat.common.utils.loggerWithKtlintConfig import org.cqfn.diktat.ktlint.unwrap import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactory +import org.cqfn.diktat.util.tryToPath +import org.cqfn.diktat.util.walkByGlob import mu.KotlinLogging import java.nio.file.InvalidPathException import java.nio.file.Path @@ -27,13 +29,6 @@ private val log = KotlinLogging.loggerWithKtlintConfig {} typealias DiktatErrorWithCorrectionInfo = Pair -private fun String.tryToPath(): Path? = try { - Paths.get(this).takeIf { it.exists() } -} catch (e: InvalidPathException) { - null -} - -@OptIn(ExperimentalPathApi::class) @Suppress( "LongMethod", "TOO_LONG_FUNCTION" @@ -58,10 +53,7 @@ fun main(args: Array) { .flatMap { pattern -> pattern.tryToPath()?.let { sequenceOf(it) } ?: run { - // create a matcher and return a filter that uses it. - val matcher = currentFolder.fileSystem.getPathMatcher("glob:$pattern") - currentFolder.walk(PathWalkOption.INCLUDE_DIRECTORIES) - .filter { matcher.matches(it) } + currentFolder.walkByGlob(pattern) } } .filter { file -> file.extension in setOf("kt", "kts") } diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt index 7d9a6180ae..a03c0960c4 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/cli/DiktatProperties.kt @@ -150,7 +150,8 @@ data class DiktatProperties( description = description ) if (args.contains("--$fullName") || shortName?.let { args.contains("-$it") } == true) { - println(readFromResource(resourceName)) + @Suppress("DEBUG_PRINT", "ForbiddenMethodCall") + print(readFromResource(resourceName)) exitProcess(0) } } diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt new file mode 100644 index 0000000000..aa92f14365 --- /dev/null +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt @@ -0,0 +1,34 @@ +/** + * This class contains util methods to operate with java.nio.file.Path + */ +package org.cqfn.diktat.util + +import java.nio.file.InvalidPathException +import java.nio.file.Path +import java.nio.file.Paths +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.PathWalkOption +import kotlin.io.path.exists +import kotlin.io.path.walk + +/** + * Create a matcher and return a filter that uses it. + * @param glob glob pattern to filter files + * @return a sequence of files which matches to [glob] + */ +@OptIn(ExperimentalPathApi::class) +fun Path.walkByGlob(glob: String): Sequence = + fileSystem.getPathMatcher("glob:$glob") + .let { matcher -> + this.walk(PathWalkOption.INCLUDE_DIRECTORIES) + .filter { matcher.matches(it) } + } + +/** + * @return path or null if path is invalid or doesn't exist + */ +fun String.tryToPath(): Path? = try { + Paths.get(this).takeIf { it.exists() } +} catch (e: InvalidPathException) { + null +} diff --git a/diktat-test-framework/pom.xml b/diktat-test-framework/pom.xml index bcb567e5f6..e68a7f8a9a 100644 --- a/diktat-test-framework/pom.xml +++ b/diktat-test-framework/pom.xml @@ -57,45 +57,6 @@ org.jetbrains.kotlin kotlin-maven-plugin - - - compile - process-sources - - compile - - - - src/main/java - src/main/kotlin - src/main/resources - - - kotlinx-serialization - - - - - test-compile - process-test-sources - - test-compile - - - - src/test/java - src/test/kotlin - - - - - - - org.jetbrains.kotlin - kotlin-maven-serialization - ${kotlin.version} - - org.apache.maven.plugins From 034876c0633b8594e9786b3f532ba4d3728b5bed Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 24 Nov 2022 12:47:46 +0300 Subject: [PATCH 27/30] review notes --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 4708139310..8ce992e1dd 100644 --- a/pom.xml +++ b/pom.xml @@ -410,6 +410,7 @@ + src/main/java src/main/kotlin src/main/resources From 58ca4c5688bafa4a93578e7c20920f8f20bdb9fa Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 24 Nov 2022 12:55:08 +0300 Subject: [PATCH 28/30] diktat:fix --- .../src/main/kotlin/org/cqfn/diktat/DiktatMain.kt | 6 ------ .../src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index c59cf7ebc8..fdae2a245d 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -13,15 +13,9 @@ import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactory import org.cqfn.diktat.util.tryToPath import org.cqfn.diktat.util.walkByGlob import mu.KotlinLogging -import java.nio.file.InvalidPathException -import java.nio.file.Path import java.nio.file.Paths -import kotlin.io.path.ExperimentalPathApi -import kotlin.io.path.PathWalkOption import kotlin.io.path.absolutePathString -import kotlin.io.path.exists import kotlin.io.path.extension -import kotlin.io.path.walk import kotlin.io.path.writeText @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR") diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt index aa92f14365..a27b53e099 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt @@ -1,6 +1,7 @@ /** * This class contains util methods to operate with java.nio.file.Path */ + package org.cqfn.diktat.util import java.nio.file.InvalidPathException From ff0dc7acba8c5876dc6f7a4e2de19a08634a5402 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 24 Nov 2022 13:11:14 +0300 Subject: [PATCH 29/30] diktat:fix --- diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt index a27b53e099..c4c4d2068e 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt @@ -14,6 +14,7 @@ import kotlin.io.path.walk /** * Create a matcher and return a filter that uses it. + * * @param glob glob pattern to filter files * @return a sequence of files which matches to [glob] */ From 6b464752474657228266dbea606465146695b165 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 6 Dec 2022 11:29:51 +0300 Subject: [PATCH 30/30] fix review notes --- .../diktat/plugin/maven/DiktatBaseMojo.kt | 3 ++- .../cqfn/diktat/ruleset/utils/FileUtils.kt | 23 +++++++++++++++++-- .../main/kotlin/org/cqfn/diktat/DiktatMain.kt | 12 ++++------ .../org/cqfn/diktat/DiktatProcessCommand.kt | 4 ++-- .../kotlin/org/cqfn/diktat/util/FileUtils.kt | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt index 0b049f9e27..f0ae9ccee1 100644 --- a/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt @@ -6,6 +6,7 @@ package org.cqfn.diktat.plugin.maven import org.cqfn.diktat.DiktatProcessCommand import org.cqfn.diktat.ktlint.unwrap +import org.cqfn.diktat.ruleset.utils.isKotlinCodeOrScript import com.pinterest.ktlint.core.LintError import com.pinterest.ktlint.core.Reporter @@ -197,7 +198,7 @@ abstract class DiktatBaseMojo : AbstractMojo() { directory .walk() .filter { file -> - file.isDirectory || file.extension.let { it == "kt" || it == "kts" } + file.isDirectory || file.toPath().isKotlinCodeOrScript() } .filter { it.isFile } .filterNot { file -> file in excludedFiles || excludedDirs.any { file.startsWith(it) } } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt index 0e349bbeb6..2eaa177b93 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt @@ -4,7 +4,12 @@ package org.cqfn.diktat.ruleset.utils +import java.nio.file.Path +import kotlin.io.path.extension + internal const val SRC_DIRECTORY_NAME = "src" +private const val KOTLIN_EXTENSION = "kt" +private const val KOTLIN_SCRIPT_EXTENSION = KOTLIN_EXTENSION + "s" /** * Splits [this] string by file path separator. @@ -17,11 +22,25 @@ fun String.splitPathToDirs(): List = .split("/") /** - * Checks if [this] String is a name of a kotlin script file by checking whether file extension equals 'kts' + * Checks if [this] [String] is a name of a kotlin script file by checking whether file extension equals 'kts' + * + * @return true if this is a kotlin script file name, false otherwise + */ +fun String.isKotlinScript() = endsWith(".$KOTLIN_SCRIPT_EXTENSION") + +/** + * Check if [this] [Path] is a kotlin script by checking whether an extension equals to 'kts' * * @return true if this is a kotlin script file name, false otherwise */ -fun String.isKotlinScript() = endsWith(".kts") +fun Path.isKotlinScript() = this.extension.lowercase() == KOTLIN_SCRIPT_EXTENSION + +/** + * Check if [this] [Path] is a kotlin code or script by checking whether an extension equals to `kt` or 'kts' + * + * @return true if this is a kotlin code or script file name, false otherwise + */ +fun Path.isKotlinCodeOrScript() = this.extension.lowercase() in setOf(KOTLIN_EXTENSION, KOTLIN_SCRIPT_EXTENSION) /** * Checks if [this] String is a name of a gradle kotlin script file by checking whether file extension equals 'gradle.kts' diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt index fdae2a245d..506d257dc7 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatMain.kt @@ -10,12 +10,12 @@ import org.cqfn.diktat.cli.DiktatProperties import org.cqfn.diktat.common.utils.loggerWithKtlintConfig import org.cqfn.diktat.ktlint.unwrap import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactory -import org.cqfn.diktat.util.tryToPath +import org.cqfn.diktat.ruleset.utils.isKotlinCodeOrScript +import org.cqfn.diktat.util.tryToPathIfExists import org.cqfn.diktat.util.walkByGlob import mu.KotlinLogging import java.nio.file.Paths import kotlin.io.path.absolutePathString -import kotlin.io.path.extension import kotlin.io.path.writeText @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR") @@ -45,12 +45,10 @@ fun main(args: Array) { properties.patterns .asSequence() .flatMap { pattern -> - pattern.tryToPath()?.let { sequenceOf(it) } - ?: run { - currentFolder.walkByGlob(pattern) - } + pattern.tryToPathIfExists()?.let { sequenceOf(it) } + ?: currentFolder.walkByGlob(pattern) } - .filter { file -> file.extension in setOf("kt", "kts") } + .filter { file -> file.isKotlinCodeOrScript() } .distinct() .map { it.normalize() } .map { file -> diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt index 5f50d760b3..3998859905 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/DiktatProcessCommand.kt @@ -5,6 +5,7 @@ import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF import org.cqfn.diktat.ktlint.unwrap import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactory import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProviderV2 +import org.cqfn.diktat.ruleset.utils.isKotlinScript import com.pinterest.ktlint.core.KtLint import com.pinterest.ktlint.core.api.EditorConfigDefaults import com.pinterest.ktlint.core.api.EditorConfigOverride @@ -12,7 +13,6 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import java.nio.file.Path import kotlin.io.path.absolutePathString -import kotlin.io.path.extension import kotlin.io.path.readText /** @@ -50,7 +50,7 @@ class DiktatProcessCommand private constructor( ruleProviders = DiktatRuleSetProviderV2(diktatRuleSetFactory).getRuleProviders(), userData = emptyMap(), cb = callback.unwrap(), - script = file.extension.endsWith("kts", ignoreCase = true), + script = file.isKotlinScript(), editorConfigPath = null, debug = isDebug, editorConfigDefaults = EditorConfigDefaults.emptyEditorConfigDefaults, diff --git a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt index c4c4d2068e..22f5027272 100644 --- a/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt +++ b/diktat-ruleset/src/main/kotlin/org/cqfn/diktat/util/FileUtils.kt @@ -29,7 +29,7 @@ fun Path.walkByGlob(glob: String): Sequence = /** * @return path or null if path is invalid or doesn't exist */ -fun String.tryToPath(): Path? = try { +fun String.tryToPathIfExists(): Path? = try { Paths.get(this).takeIf { it.exists() } } catch (e: InvalidPathException) { null