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

Baseline suppression not working correctly with KDocSection tag elements #4637

Closed
mkrussel77 opened this issue Mar 15, 2022 · 2 comments
Closed
Labels

Comments

@mkrussel77
Copy link

Expected Behavior

Multiple warnings from the same KDoc element but different sections should all be suppressed when included in baseline file.
All the warnings show up in the detekt-baseline.xml file but only some get suppressed.

Observed Behavior

Only the last one in the baseline gets suppressed.

Steps to Reproduce

Create a rule that logs multiple warnings for a given class documentation.
Create a class that triggers the rule violation multiple times.
Run gradle detekt
See all the warnings
Run gradle detektBaseline
Run gradle detekt again
Some of the warnings are gone but not all

Context

I was creating new custom rule but only wanted to fix new instances of it and slowly fix old ones. Was trying to use baselines to not report old instances until they can be fixed.

I was able to work around the bug by flagging only one issue for the entire class at the class's documentation element.

Your Environment

  • Version of detekt used: 1.19.0
  • Version of Gradle used (if applicable): 7.2
  • Gradle scan link (add --scan option when running the gradle task):
  • Operating System and version: Mac OS 11.6.4
  • Link to your project (if it's a public repository):

I don't have this in a public repo, but a sample rule would be

class PropertiesDocumentedInClassDocumentation(config: Config = Config.empty) : Rule(config) {
    override val issue: Issue
        get() = Issue(
            this.javaClass.simpleName,
            Severity.Style,
            "Documenting properties as tag in class documentation is not allowed due to how they are rendered in Xcode when using frameworks",
            Debt.FIVE_MINS
        )

    override fun visitClass(klass: KtClass) {
        super.visitClass(klass)
        klass.docComment?.getChildrenOfType<KDocSection>()
            ?.filter { it.name == "property" }
            .forEach { docSection ->
                reportPropertyDoc(klass, docSection)
            }
    }

    private fun reportPropertyDoc(classDeclaration: KtClass, docSection: KDocSection) {
        val propertyName = "${classDeclaration.fqName.toString()}.${docSection.getSubjectName()}"

        report(
            CodeSmell(
                issue, Entity.from(docSection),
                "Documentation for $propertyName should not be in class documentation"
            )
        )
    }
}

The run it against

 /**
  * Simple class.
  * @property bar The bar.
  * @property other Some other documentation.   
  */
class Foo(
    val bar: Bar,
    val other: String,
)
@mkrussel77 mkrussel77 added the bug label Mar 15, 2022
@mkrussel77
Copy link
Author

mkrussel77 commented Mar 15, 2022

Here's a git repository that reproduces the problem.

https://github.com/mkrussel77/DetektBaselineWithDocSegment

@cortinico
Copy link
Member

Thanks for providing a reproducer 🙏

Just tested your repo on 1.20.0-RC1, it works fine.
The offending issue is:

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

No branches or pull requests

2 participants