Hey :wave: can anyone help me? <https://github.com...
# detekt
j
Hey đź‘‹ can anyone help me? https://github.com/arturbosch/detekt/issues/1395
m
Replied on the issue.
I'm not 100% sure if you have to explicitly enable your custom rules in the config.yml but it's worth a try.
j
i try to enable explicit but nothing changed but by default it should be enabled if I understand correctly sources
m
Can you try adding
debug = true
to the
detekt { ... }
block and see if the gradle plugin prints some more hints?
j
YamlConfig(properties={autoCorrect=true, failFast=false, test-pattern={active=true, patterns=[./test/., .*Test.kt, .*Spec.kt, .Context..kt, .Stub..kt, .Ext..kt], exclude-rule-sets=[comments], exclude-rules=[NamingRules, WildcardImport, MagicNumber, MaxLineLength, LateinitUsage, StringLiteralDuplication, SpreadOperator, TooManyFunctions, ForEachOnRange, FunctionMaxLength, TooGenericExceptionCaught]}, build={maxIssues=0, weights=null}, processors={active=true, exclude=null}, console-reports={active=true, exclude=null}, mlca-rules={active=true, FindRetrofitAnnotatedMethods={active=true}}}) enable debug and as you can see my rules enabled, but in runned Rulesets everything except my "mlca-rule": Ruleset: comments Ruleset: complexity Ruleset: empty-blocks Ruleset: exceptions Ruleset: naming Ruleset: performance Ruleset: potential-bugs Ruleset: style - 5min debt
m
It should show the way it invokes the Detekt CLI, do you see a
--plugins
argument in that?
j
no, nothing about plugins [--input, /Users/a.guzenko/StudioProjects/mlca/ui/src/main/java,/Users/a.guzenko/StudioProjects/mlca/business/src/main/java,/Users/a.guzenko/StudioProjects/mlca/data/src/main/java,/Users/a.guzenko/StudioProjects/mlca/checklist/src/main/java,/Users/a.guzenko/StudioProjects/mlca/domain-models/src/main/java, --filters, ./androidTest/.,./assets/.,./res/.,./resources/.,./test/.,./build/., --config, /Users/a.guzenko/StudioProjects/mlca/detekt/config.yml, --baseline, /Users/a.guzenko/StudioProjects/mlca/detekt/baseline.xml, --report, xml:/Users/a.guzenko/StudioProjects/mlca/build/reports/detekt/detekt.xml, --report, html:/Users/a.guzenko/StudioProjects/mlca/detekt/reports/detekt.html, --debug, --parallel]
m
Then something is probably off with the way the custom plugin is built or included in the
detektPlugins
configuration.
in the screenshot you posted in the issue i can see a weird line
reports { detekt
. can you remove the detekt from that line?
probably won't change anything, but that could introduce some weird issues.
Just out of curiosity can you try making your custom rules plugin the only dependency in the
dependencies
block.
j
yeah
Copy code
reports { detekt
it's just misspell, nothing changed
Copy code
apply plugin: 'io.gitlab.arturbosch.detekt'
apply from: rootProject.file('dependencies.gradle')

dependencies {
//    detektPlugins compileDependencies.detektFormatting
//    detekt "io.gitlab.arturbosch.detekt:detekt-cli:$detektVersion"
    detektPlugins project(':mlca-rules')
}
nothing changed, same behaviour
dependencies.gradle it's just file with ext { detektVersion = "1.0.0-RC12" }
m
Can you confirm that the detektFormatting rules are working correctly in your current setup?
j
yeah, it work correctly but it remote dependency, may it influence to anything?
m
does it change anything if you run
./gradlew :mlca-rules:build
before running
./gradlew detekt
?
j
woow now Ruleset: mlca-rules appear but……my rule don't work i had tried just throw report like this
Copy code
class FindRetrofitAnnotatedMethods(config: Config = Config.empty) : Rule(config) {
    override val issue: Issue = Issue("FindRetrofitAnnotatedMethods",
                                      Severity.Maintainability,
                                      "ProGuard obfuscation can cause (de)serialization issues if fields and classes are not in proguard-rules.pro.",
                                      Debt.FIVE_MINS)
 override fun visit(root: KtFile) {
        report(CodeSmell(issue, Entity.from(root), "BOOOM"))
    }
}
just to be sure that my rule work, but it didn't
so i copy rule from the article i mentioned in issue and it also didn't throw any code smell report but test work well
m
Does detekt actually run over any files?
j
yes, there proof: i create file with "internal" word in it path
Copy code
package ru.tinkoff.mlca.internal

class InternalClass {}
and i get empty-blocks report
Copy code
Ruleset: empty-blocks - 5min debt
        EmptyClassBlock - [InternalClass] at /Users/a.guzenko/StudioProjects/mlca/data/src/main/java/ru/tinkoff/mlca/internal/InternalClass.kt:3:1
but not from my ruleset((
m
Updated the issue on github with some more details from this discussion.
j
in addition: i generate jar with my rules and addd it in detekt.gradle config
Copy code
plugins = "mlca-rules.jar"
and when i run detekt it appears in arg
Copy code
--plugins, mlca-rules.jar,
but… result the same: my rule is shown in Rulesets list but no report from custom rules
t
I might lack of understanding the whole context here but you seemed to run into the exact same issue I ran into before https://kotlinlang.slack.com/archives/C88E12QH4/p1542552471058600.