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

Setup Detekt Baseline for Incremental Rule Enforcement #267

Open
2 tasks
VahidGarousi opened this issue Dec 16, 2024 · 3 comments
Open
2 tasks

Setup Detekt Baseline for Incremental Rule Enforcement #267

VahidGarousi opened this issue Dec 16, 2024 · 3 comments

Comments

@VahidGarousi
Copy link

VahidGarousi commented Dec 16, 2024

Body:

We need to set up a Detekt baseline in the project to facilitate incremental rule enforcement. This approach will allow us to gradually enable rules and fix existing issues over time.


Steps to Implement:

  1. Create a baseline for Detekt using the DetektCreateBaselineTask.
  2. Store the baseline file under config/detekt/baseline.xml.
  3. Ensure Detekt uses the baseline file for analysis and only reports new issues.
  4. Configure a task to generate/update the baseline when needed.

Goal:

  • Gradually fix existing issues while enforcing Detekt rules for new code changes.

Tasks:

  • Add the baseline configuration to the Detekt setup.
  • Verify that Detekt analysis passes using the new baseline.
@AdamMc331
Copy link
Owner

I have no problem doing this, I'm curious how helpful a baseline file is on a new project, though, that should not have any violations?

Or is the point that, when I turn on a rule (for example, UndocumentedPublicClass that there now would be violations in the template?

I guess the reasoning doesn't change much, just wanted to understand, maybe it means there's a problem with the current detekt config.

@VahidGarousi
Copy link
Author

@AdamMc331 My reason is this:

Why Using a Baseline is Helpful Even in a New Project

  1. Capturing the Current State of the Project

    • Even in a new project, a baseline acts as a snapshot of the current state. It helps document which rules are active and whether there are any violations at the start.
  2. Dealing with Default Templates

    • Many new projects use default templates (e.g., generated by Android Studio). These templates might not fully comply with Detekt rules (e.g., missing documentation for public classes). A baseline ensures that these template-related issues don’t block progress.
  3. Gradual Rule Activation

    • In a new project, you might want to activate only the essential rules at first and add stricter ones over time. A baseline ensures that violations from newly activated rules don't overwhelm developers working on new code.
  4. Maintaining Team Velocity in Early Stages

    • At the start of a project, the focus is often on rapid development. A baseline allows the team to move quickly without being bogged down by minor rule violations that can be addressed later.
  5. Preventing CI/CD Disruptions

    • If the project is integrated with CI/CD pipelines, enabling a new rule might cause builds to fail due to violations in existing code. A baseline ensures that only new issues are reported, preventing disruptions to the pipeline.
  6. Creating Measurable Standards

    • A baseline establishes measurable standards for the project. Even in a new project, it serves as a reference for which rules are being enforced and which violations need to be addressed over time.
  7. Preparing for Future Growth

    • Every project starts small but grows in complexity. Having a baseline from the beginning helps manage technical debt as the project evolves, ensuring new violations are addressed without being overwhelmed by existing ones.

In Summary

Using a baseline, even in a new project, ensures you can:

  • Capture the initial state of rule enforcement.
  • Focus on new code while incrementally addressing existing issues.
  • Maintain team productivity and CI/CD stability.
  • Prepare for the project’s growth and increased complexity over time.

A baseline isn’t just about fixing existing issues—it’s also about managing future changes effectively. 🚀

@VahidGarousi VahidGarousi changed the title Setup Detekt Baseline for Incremental Rule Enforcement #242 Setup Detekt Baseline for Incremental Rule Enforcement Jan 1, 2025
@AdamMc331
Copy link
Owner

AdamMc331 commented Jan 4, 2025

Gotcha. Creating a baseline as-is doesn't work because there are currently no violations, but I might be able to come up with something. Will play around with it.

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

No branches or pull requests

2 participants