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

Add Gradle pre-commit hook to docs #6892

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

matejdro
Copy link
Contributor

Currently, pre-commit hook page only mentions CLI steps. This requires user to maintain separate detekt binary in the project and it's not compatible with type resolution.

With this PR, I have also added instructions on how to only scan staged files with Gradle.

Setup is kinda verbose, since you have to run through several hoops to get it to work with configuration cache. This is also kts only (it can probably be converted to groovy, but I'm not very well versed in groovy).

@detekt-ci
Copy link
Collaborator

detekt-ci commented Jan 22, 2024

Warnings
⚠️ This PR is approved with no milestone set. If merged, it won't appear in the detekt release notes.
Messages
📖

Thank you very much for making our website better ❤️!

Generated by 🚫 dangerJS against ac45d72

Copy link

codecov bot commented Jan 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.70%. Comparing base (8e9c993) to head (a5cd4e9).
Report is 7 commits behind head on main.

❗ Current head a5cd4e9 differs from pull request most recent head ac45d72. Consider uploading reports for the commit ac45d72 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6892      +/-   ##
============================================
- Coverage     84.71%   84.70%   -0.02%     
+ Complexity     3986     3983       -3     
============================================
  Files           580      578       -2     
  Lines         12162    12151      -11     
  Branches       2496     2495       -1     
============================================
- Hits          10303    10292      -11     
  Misses          625      625              
  Partials       1234     1234              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matejdro
Copy link
Contributor Author

Any ideas what Vercel error is and how can I fix it? I've only updated markdown files

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this @matejdro !

@@ -80,3 +80,112 @@ if [ $EXIT_CODE -ne 0 ]; then
exit $EXIT_CODE
fi
```

## Only run on staged files - Gradle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be moved before the CLI, as the initial script suggests to use ./gradlew.

So this page will look like:

  1. Run gradlew on everything
  2. Run gradlew only on modified files
  3. Run CLI only on modified files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the top


## Only run on staged files - Gradle

If the CLI is not your cup of tea (you don't want to keep separate CLI binary set up, you want type resolution etc.),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the style we use in the rest of the docs, could we simplify a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated that part.

If the CLI is not your cup of tea (you don't want to keep separate CLI binary set up, you want type resolution etc.),
you can also configure Gradle detekt to only run on staged files.

First, we need to declare `GitPreCommitFilesTask` task - a gradle task that will retrieve list of staged files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be useful to specify where to create this file for folks that are not used to precompiled script plugins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated that part.

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cortinico Is there something left to do in this PR to get it merged?
Otherwise, we should give it a go, since it improves detekt's doc.

@cortinico
Copy link
Member

@schalkms yes versioned docs were missing for all the 1.23.x versions.
I've udpated them all and we can merge this now 👍

@matejdro
Copy link
Contributor Author

By the way, since making this PR, I have found a couple of improvements to this approach:

If you want, I can include those on Monday and it can be merged after that.

@cortinico
Copy link
Member

If you want, I can include those on Monday and it can be merged after that.

Yes please 👍

@matejdro
Copy link
Contributor Author

Done

Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments also apply to the versioned files

website/docs/gettingstarted/git-pre-commit-hook.md Outdated Show resolved Hide resolved
```kotlin
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
if (project.hasProperty("precommit")) {
dependsOn(gitPreCommitFileList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? And, if so, where is this task defined?

Copy link
Contributor Author

@matejdro matejdro Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, forgot to remove this one. Will delete it. Good catch.

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants