Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: type and symbol solving #2259

Closed
3 tasks done
schalkms opened this issue Jan 15, 2020 · 12 comments · Fixed by #3225
Closed
3 tasks done

Doc: type and symbol solving #2259

schalkms opened this issue Jan 15, 2020 · 12 comments · Fixed by #3225
Assignees
Milestone

Comments

@schalkms
Copy link
Member

schalkms commented Jan 15, 2020

On the homepage there should be a separate chapter regarding rules that use type and symbol solving and how to configure them in Gradle. The existing section are missing some essential information.

From the Slack chat:

dependencies {
    detekt(project(":detekt-cli"))
    detektPlugins(project(":detekt-formatting"))
}
val detektAll by tasks.registering(Detekt::class) {
    description = "Runs over whole code base without the starting overhead for each module."
    parallel = true
    buildUponDefaultConfig = true
    include("**/*.kt")
    exclude("**/resources/**")
    exclude("**/build/**")
    exclude("**/*.kts")
    // baseline.set(file("$rootDir/config/detekt/baseline.xml"))
    classpath.setFrom(project.configurations.getByName("detekt"))
    reports {
        xml.enabled = false
        html.enabled = false
        txt.enabled = false
    }
}
@BraisGabin
Copy link
Member

Is this the same as #1943 ?

@schalkms
Copy link
Member Author

schalkms commented Apr 21, 2020

@BraisGabin yes thanks, this issue further improves the documentation. I closed the old one, since work is ongoing here in this issue.

@Whathecode
Copy link
Contributor

Whathecode commented Jul 29, 2020

For anyone using Groovy and not Kotlin for Gradle, here is an example similar to the original posted by @schalkms:

tasks.register("detektCustom", io.gitlab.arturbosch.detekt.Detekt.class) { detektTask ->
    detektTask.source = files("$projectDir/src/")
    detektTask.config.from("$rootDir/detekt.yml")
    detektTask.buildUponDefaultConfig = true
    detektTask.ignoreFailures = false
    detektTask.classpath.setFrom(project.configurations.getByName("detekt"))
}

In regards to "some peculiarities": maybe the entire output of 'unresolved references', 'cannot access' internal classes, and multi platform projects being experimental is among them?

But, ignoring that, my rule relying on type solving now seems to work.

At least, in simple projects. In a multi-project build of mine types of other projects cannot be loaded. It only works for type resolution within a single project. I tried adding /src/ folders of the other projects to the classPath set, without luck, e.g.:

    detektTask.classpath.setFrom([
        "$rootDir/carp.common/src/",
        "$projectDir/src/"
    ])

@schalkms
Copy link
Member Author

@Whathecode thanks for posting more helpful content. This will be added to the page as well.

@Whathecode
Copy link
Contributor

Whathecode commented Aug 6, 2020

I just saw that the specific configured classpath is not even used in BindingContext other than an early out in case none are specified: https://github.com/detekt/detekt/blob/master/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/BindingContext.kt

Instead, to get multi-project analysis, you need to pass all source folders of the projects you want to analyze to source. Thus, what I tried to do above through classpath would look like:

    detektTask.source = files(
        "$rootDir/carp.common/src/",
        "$projectDir/src/"
    )

@BraisGabin
Copy link
Member

How is the status of this issue? We did some improvements already in our documentation in this regard. Should we update the tasks that should be done so we can close this issue?

@cortinico
Copy link
Member

How is the status of this issue? We did some improvements already in our documentation in this regard. Should we update the tasks that should be done so we can close this issue?

I have a draft for this page. I'd love to pick it up and send it out for review in the next days (unless someone else wants to pick it up).

@BraisGabin BraisGabin assigned cortinico and unassigned schalkms Nov 4, 2020
@BraisGabin
Copy link
Member

Sure, go for it!

@schalkms
Copy link
Member Author

schalkms commented Nov 4, 2020

Sorry for the inconvenience. This one is on me.
It's a pity, but I haven't had the chance to tackle this issue and write the blog post.
However, I created the initial page in the corresponding homepage section.
Please feel free to go for it. I'll happily review the PR.

https://detekt.github.io/detekt/type-resolution.html

cortinico added a commit to cortinico/detekt that referenced this issue Nov 11, 2020
schalkms added a commit that referenced this issue Nov 21, 2020
* Add documentation page on type resolution

Fixes #2259

* Update docs/pages/gettingstarted/type-resolution.md

Co-authored-by: Brais Gabín <braisgabin@gmail.com>

* Apply suggestions from code review

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>

* Add note on lintWithContext

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
@cortinico
Copy link
Member

The page is now available here: https://detekt.github.io/detekt/type-resolution.html

Feel free to contribute, open issues & give suggestions 👌

@arturbosch arturbosch added this to the 1.15.0 milestone Dec 14, 2020
@arturbosch
Copy link
Member

Great work! I will highlight it in the release notes to get further feedback.

arturbosch pushed a commit that referenced this issue Dec 21, 2020
* Add documentation page on type resolution

Fixes #2259

* Update docs/pages/gettingstarted/type-resolution.md

Co-authored-by: Brais Gabín <braisgabin@gmail.com>

* Apply suggestions from code review

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>

* Add note on lintWithContext

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
arturbosch pushed a commit that referenced this issue Jan 16, 2021
* Add documentation page on type resolution

Fixes #2259

* Update docs/pages/gettingstarted/type-resolution.md

Co-authored-by: Brais Gabín <braisgabin@gmail.com>

* Apply suggestions from code review

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>

* Add note on lintWithContext

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
@karandeep26
Copy link

can we use this approach to run type resolutions? (detektMain?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants