• sanogueralorenzo

    sanogueralorenzo

    2 years ago
    Hello 👋 I was trying to write a pre-commit hook that runs only on changed files (so it takes a second instead of 15 running everything) and I was facing some issues: Some notes: I'm using detekt-cli jar (so I can use the
    -input
    only on changed files) and also to avoid the gradle overhead/plugin
    # Get kotlin changed files
    changedFiles=$(git --no-pager diff --diff-filter=d --name-only HEAD | grep '\.kt[s"]\?$')
    
    if [ -n "$changedFiles" ]; then
      # `paste -sd "," -` replaces newlines with commas so detekt cli -i parameter can take it
      java -jar config/detekt/detekt-cli-1.11.2-all.jar --build-upon-default-config --config "config/detekt/detekt.yml" --baseline "config/detekt/baseline.xml" -p config/detekt/detekt-formatting-1.11.2.jar --auto-correct -i "$( printf "%s" "$changedFiles" | paste -sd "," - )"
    
      if [ $? -ne 0 ]; then
        echo "***********************************************"
        echo "                 Detekt failed                 "
        echo " Please fix the above issues before committing "
        echo "***********************************************"
        exit 1
      fi
    fi
    The above takes around 2 seconds and it is working properly from the tests I've been doing My main issue is that from
    java -jar
    to
    --auto-correct
    is something I already have in my top level detekt task and my top level detekt baseline task (and I wouldn't want to have all that script line repeated in several files since you will have to remember to update all of them when updating version. Is there any way to reuse that part? Thanks! 🙏
    sanogueralorenzo
    b
    4 replies
    Copy to Clipboard
  • kenkyee

    kenkyee

    2 years ago
    There's an open issue
    kenkyee
    1 replies
    Copy to Clipboard
  • Venkat , Bangalore , India

    Venkat , Bangalore , India

    2 years ago
    Hi Everyone, Could you please help me on how Detekt is different from Android lint. would be helpful for me to a deeper knowledge .. I mean what kind of issues Detekt uniquely reports compared to AndroidLint
    Venkat , Bangalore , India
    Zach Klippenstein (he/him) [MOD]
    +1
    5 replies
    Copy to Clipboard
  • gabrielfv

    gabrielfv

    2 years ago
    Hello, how do I find out if a method call stands for an extension for nullable type. If i have the method
    Type?.extForNullable()
    I want to identify in a rule if this method is called, and not a version of it exclusive for a non-null instance of
    Type
    , or a more specialized version of it, like
    SpecificType?.extForNullable()
    , even if
    SpecificType : Type
    . I’m trying to visit dot-qualified expressions, since if I go for a safe expression I’m not calling a nullable version any way, but idk how to follow from here
    gabrielfv
    1 replies
    Copy to Clipboard
  • d

    Daniel Svensson

    2 years ago
    As kotlin doesn't have any granular
    -Werror=...
    etc I was hoping to convince detekt to error out if there are any: unused variables, unused methods, useless
    foo?.bar
    etc, but I can't seem to find it in the configuration. Am I missing something?
    d
    b
    4 replies
    Copy to Clipboard
  • Marcelo Hernandez

    Marcelo Hernandez

    2 years ago
    Hello. I am trying to resolve the return type of a function that returns a
    Flow<T>
    (including subclasses) in
    visitNamedFunction
    . I am new to the APIs in
    kotlin-compiler-embeddable
    . I am trying to use:
    bindingContext[BindingContext.FUNCTION, function].returnType
    but that seems to resolve to an
    UnresolvedType
    . I have also tried
    function.getResolvedCall(bindingContext)
    but that always returns
    null
    . Is there any way to resolve types that are not considered built-in?
    Marcelo Hernandez
    1 replies
    Copy to Clipboard
  • k

    karandeep singh

    2 years ago
    Also, is anyone aware of any issues adding detekt with novoda plugin? (https://github.com/novoda/gradle-static-analysis-plugin)
    k
    seb
    +1
    7 replies
    Copy to Clipboard
  • themishkun

    themishkun

    2 years ago
    Hi everyone, I wonder if detekt can export rules as part of the library (like android lint does). So, If I maintain a kotlin lib and want to highlight common errors, can I provide detekt rules that would be automagically included in consumer's detekt suite after she adds lib dependency (without explicitly declaring rule)?
    themishkun
    1 replies
    Copy to Clipboard
  • r

    robstoll

    1 year ago
    updating to detekt 1.14.1 fails for me with:
    Could not find io.gitlab.arturbosch.detekt:detekt-bom:1.14.1.
                  Searched in the following locations:
                    - <https://plugins.gradle.org/m2/io/gitlab/arturbosch/detekt/detekt-bom/1.14.1/detekt-bom-1.14.1.pom>
                    - <https://repo.maven.apache.org/maven2/io/gitlab/arturbosch/detekt/detekt-bom/1.14.1/detekt-bom-1.14.1.pom>
                    - <https://jcenter.bintray.com/io/gitlab/arturbosch/detekt/detekt-bom/1.14.1/detekt-bom-1.14.1.pom>
    is this version not yet published?
    r
    gammax
    3 replies
    Copy to Clipboard
  • b

    BorzdeG

    1 year ago
    1: Task failed with an exception.
    -----------
    * What went wrong:
    Execution failed for task ':myproject:detekt'.
    > Could not resolve all files for configuration ':myproject:detekt'.
       > Could not resolve org.jetbrains.kotlinx:kotlinx-html-jvm.
         Required by:
             project :myproject > io.gitlab.arturbosch.detekt:detekt-cli:1.14.1 > io.gitlab.arturbosch.detekt:detekt-bom:1.14.1
          > Cannot choose between the following variants of org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
              - jvm-api
              - jvm-runtime
              - metadata-api
            All of them match the consumer attributes:
              - Variant 'jvm-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'jvm-runtime' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'metadata-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'kotlin-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'common' but the consumer didn't ask for it
       > Could not resolve org.jetbrains.kotlinx:kotlinx-html-jvm.
         Required by:
             project :myproject > io.gitlab.arturbosch.detekt:detekt-cli:1.14.1 > io.gitlab.arturbosch.detekt:detekt-core:1.14.1 > io.gitlab.arturbosch.detekt:detekt-report-html:1.14.1
          > Cannot choose between the following variants of org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
              - jvm-api
              - jvm-runtime
              - metadata-api
            All of them match the consumer attributes:
              - Variant 'jvm-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'jvm-runtime' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'metadata-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'kotlin-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'common' but the consumer didn't ask for it
    b
    b
    5 replies
    Copy to Clipboard