Hey guys, we have created a linter (checker + auto...
# announcements
a
Hey guys, we have created a linter (checker + autofixer) for Kotlin with a huge number of rules. Will be great if you will support it at least with a very simple thing: star on a GitHub: https://github.com/cqfn/diKTat But if you will have a chance try it in your CI/CD :) We are already added to awesome-kotlin and awesome-static-analysis, but still need some support from you!
Diktat - is a a formal codestyle and a custom ruleset with a much more detection rules than ktlint has in itโ€™s ruleset. We have ~100 configurable rules and a formal codestyle for detecting issues. We have more rules than ktlint, they are much more complex and we have a formal style guide that describes all rules that we are checking and fixing. Also we have a great configuration mechanism that allow you to change and customize your ruleset. ktlint is not configurable. You cannot customize it in the way diktat can. You cannot customize rules that you are using. And detekt itself is used for different purposes - it is a functional bugs detection system. For code style it uses ktlint, so see the first point :) Diktat itself - is a static analyzer that uses ktlint for codestyle and codesmell issues under the hood. The idea is simple: you have different tools. One is - a static analyzer that does some searching for bugs (but actually bugs are pretty simple). It is detekt. The second approach - is ktlint - a checker and autofixer. It handles all your problems related to codestyle. And if you are lazy - it can fix them for you automatically :) Diktat - is a plugin for ktlint. A huge number of rules that can check and fix codestyle issues.
To get more information you can see our read me and soon will able to check our white paper.
a
Hi, This looks great, but is there a way to set this up with gradle easily (maybe with a plugin like: https://github.com/jlleitschuh/ktlint-gradle)
๐Ÿ‘ 1
It throws infinite (almost)
Copy code
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
[ERROR] 2020-10-31 16:26:26 Not able to find an external configuration for domain name in the common configuration (is it missing in yml config?)
errors, can you help me solve it?
a
Yes, as it is written in ERROR - there is a configuration for a package name
name: DIKTAT_COMMON configuration: # put your package name here - it will be autofixed and checked domainName: your.name.here testDirs: test
You need to put a โ€œdomainNameโ€ of your company in the configuration file
a
Ah, thanks. Is there wiki/docs for this repo/project/linter?
a
Yes, of course:
a
The error is still there ๐Ÿ˜ž
wait
Yes it is still there, here's the config
Copy code
- name: DIKTAT_COMMON
  configuration:
    domainName: com.github.animeshz.observable_collections
    testDirs: test
a
Which version are you using?
Of diktat
a
0.1.2
a
I will reproduce it right now
a
Gradle (kts) script:
Copy code
object Versions {
    // ...
    const val ktlint = "0.39.0"
    const val diktat = "0.1.2"
}

// ...

val ktlint: Configuration by configurations.creating

tasks.create<JavaExec>("diktatCheck") {
    group = "diktat"

    inputs.files(project.fileTree(mapOf("dir" to "src", "include" to "**/*.kt")))
    outputs.dir("${project.buildDir}/reports/diktat/")

    description = "Check Kotlin code style."
    classpath = ktlint
    main = "com.pinterest.ktlint.Main"
    args = listOf("src/*/kotlin/**/*.kt")

    outputs.upToDateWhen { false }
    isIgnoreExitValue = true

    dependencies {
        ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
            exclude("com.pinterest.ktlint", "ktlint-ruleset-standard")
        }

        ktlint("org.cqfn.diktat:diktat-rules:${Versions.diktat}")
    }
}
If you'd like to check it out
a
Have you put the config.yml to the root of the directory
a
config.yml? According to readme, I've created diktat-analysis.yml and put config into it ๐Ÿ™‚
a
Yes, where did you put diktat-analysis.yml? ๐Ÿ˜Š
a
Well renaming it to config.yml did the trick, but config.yml shouldn't be reserved as its a common name ๐Ÿ˜…
I put it on the root directory of gradle project
a
No, something very strange. Our team will investigate it right now
a
May I know where does the execution start, so I can help as well ๐Ÿ˜…
a
I will create an issue, @Animesh Sahu thanks for a report! If you have a github account and will tell me itโ€™s name I will mention you in the issue
๐Ÿ˜ 1
a
๐Ÿ‘ 1
Seems like I found the issue
a
I still cannot reproduce :)
a
I put the
diktat-analysis.yml
in
src/main/resources
and it is reading it. Probably the problem is in this file https://github.com/cqfn/diKTat/blob/master/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/ApplicationProperties.kt#L20
May I know how this class is being used in the project so I can help further
a
@Animesh Sahu yes, diktat gradle plugin expects the configuration file in the root directory of the project (on the build.gradle level)
This is the example
a
In root level, it doesn't seem to read diktat-analysis.yml but seems to read config.yml. However it is reading diktat.yml if it is placed uner src/main/resources :^
image.png,image.png
a
The example by the link above is used in our tests and it is working somehow ๐Ÿ˜…
๐Ÿ™„ 1
Delete the file in the resources :)
And put it to build.gradle.kts level
a
^ not working
a
5 minutes, will get to a PC and test :)
a
Copy code
[ERROR] 2020-10-31 17:08:47 Cannot read config file diktat-analysis.yml due to: 
com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class org.cqfn.diktat.common.config.rules.RulesConfig] value failed for JSON property configuration due to missing (therefore NULL) value for creator parameter configuration which is a non-nullable type
 at [Source: (BufferedReader); line: 2, column: 3] (through reference chain: java.util.ArrayList[0]->org.cqfn.diktat.common.config.rules.RulesConfig["configuration"])
	at com.fasterxml.jackson.module.kotlin.KotlinValueInstantiator.createFromObjectWith(KotlinValueInstantiator.kt:112)
	at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:202)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:490)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1322)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:331)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:164)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:290)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4526)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3489)
	at org.cqfn.diktat.common.config.rules.RulesConfigReader.parseResource(RulesConfigReader.kt:140)
	at org.cqfn.diktat.common.config.rules.RulesConfigReader.parseResource(RulesConfigReader.kt:49)
	at org.cqfn.diktat.common.config.reader.JsonResourceConfigReader.readResource(JsonResourceConfigReader.kt:34)
	at org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider.get(DiktatRuleSetProvider.kt:29)
	at com.pinterest.ktlint.KtlintCommandLine.loadRulesets(Main.kt:550)
	at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:222)
	at com.pinterest.ktlint.Main.main(Main.kt:62)
[ERROR] 2020-10-31 17:08:47 Cannot read config file diktat-analysis.yml due to: 
com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class org.cqfn.diktat.common.config.rules.RulesConfig] value failed for JSON property configuration due to missing (therefore NULL) value for creator parameter configuration which is a non-nullable type
 at [Source: (BufferedReader); line: 2, column: 3] (through reference chain: java.util.ArrayList[0]->org.cqfn.diktat.common.config.rules.RulesConfig["configuration"])
	at com.fasterxml.jackson.module.kotlin.KotlinValueInstantiator.createFromObjectWith(KotlinValueInstantiator.kt:112)
....
Ok, so after increasing intellij console buffer size, I can see the exception:
a
Could you please paste your diktat-config.yml to
@Animesh Sahu I have reproduced your error
๐Ÿ˜ƒ 1
In your yml config you have not added spaces
It should be the following
โ“ 1
โ€ข name: configuration: domainName testDirs
a
wrap around triple backticks (`)
a
I will write it to the issue
๐Ÿ‘Œ 1
a
Nope!
a
๐Ÿ˜…
a
Doing either
Copy code
- name: DIKTAT_COMMON
    configuration:
        domainName: com.github.animeshz.observable_collections
        testDirs: test
or
Copy code
- name: DIKTAT_COMMON
    configuration:
    domainName: com.github.animeshz.observable_collections
    testDirs: test
following exception comes (mentioned in issue)
Yah, thanks!
a
Worked? :)
a
๐Ÿ™‚ That space before the
-
got me ๐Ÿ˜›
a
In the version 0.1.3 the logging will be improved. We will catch your case
๐Ÿ˜„ 1
Also - your plugin for gradle looks much better than our
If you will have a chance - please create it for us
๐Ÿ‘ 1
We will use it
a
I'm just a student (and in India formal studies have too much importance) Will do, maybe later (a few days) after I finished my homework/assignments. I'll maybe even improve this style, this was just for testing.
a
Thanks, you are always welcome to contribute :)
a
How to not pass configuration property (under
- name
tag) when disabling the lint i.e.
enabled: false
?
Copy code
com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class org.cqfn.diktat.common.config.rules.RulesConfig] value failed for JSON property configuration due to missing (therefore NULL) value for creator parameter configuration which is a non-nullable type
a
By the default all rules are enabled. If you are disabling the rules, just add empty configuration: โ€œconfiguration: {}โ€
a
Ah {} is a syntax ๐Ÿ˜ฎ