anishathalye / dotbot

A tool that bootstraps your dotfiles ⚡️
MIT License
6.9k stars 287 forks source link

Use pre-commit #347

Closed kurtmckee closed 4 months ago

kurtmckee commented 10 months ago

git pre-commit hooks can catch linting issues on developer PCs before they're ever committed to the repo. pre-commit is a widely-used tool that allows projects to specify all of the linters they want to run before each commit.

This PR introduces a pre-commit config that will enforce standard text linting; black, isort, and editorconfig linting; and idiomatic Python 3.6+ syntax.

codecov-commenter commented 10 months ago

Codecov Report

Patch coverage: 80.55% and project coverage change: +0.01% :tada:

Comparison is base (840cd16) 89.13% compared to head (5246ca2) 89.14%. Report is 4 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #347 +/- ## ========================================== + Coverage 89.13% 89.14% +0.01% ========================================== Files 33 33 Lines 1620 1622 +2 Branches 306 307 +1 ========================================== + Hits 1444 1446 +2 Misses 124 124 Partials 52 52 ``` | [Files Changed](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye) | Coverage Δ | | |---|---|---| | [dotbot/cli.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L2NsaS5weQ==) | `67.36% <0.00%> (ø)` | | | [dotbot/util/string.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L3V0aWwvc3RyaW5nLnB5) | `25.00% <0.00%> (ø)` | | | [dotbot/plugins/link.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L3BsdWdpbnMvbGluay5weQ==) | `86.95% <50.00%> (ø)` | | | [dotbot/messenger/messenger.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L21lc3Nlbmdlci9tZXNzZW5nZXIucHk=) | `65.11% <100.00%> (ø)` | | | [dotbot/plugins/clean.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L3BsdWdpbnMvY2xlYW4ucHk=) | `91.30% <100.00%> (ø)` | | | [dotbot/plugins/create.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L3BsdWdpbnMvY3JlYXRlLnB5) | `75.60% <100.00%> (ø)` | | | [dotbot/plugins/shell.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L3BsdWdpbnMvc2hlbGwucHk=) | `94.82% <100.00%> (ø)` | | | [dotbot/util/common.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L3V0aWwvY29tbW9uLnB5) | `100.00% <100.00%> (ø)` | | | [dotbot/util/singleton.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-ZG90Ym90L3V0aWwvc2luZ2xldG9uLnB5) | `100.00% <100.00%> (ø)` | | | [tests/conftest.py](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye#diff-dGVzdHMvY29uZnRlc3QucHk=) | `92.35% <100.00%> (+0.09%)` | :arrow_up: | | ... and [4 more](https://app.codecov.io/gh/anishathalye/dotbot/pull/347?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anish+Athalye) | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

kurtmckee commented 10 months ago

If unfamiliar with pre-commit, you can do the following to test it out:

What you'll see is that pre-commit runs isort against the one staged file (but not both!), isort lints and fixes the file's imports, and the commit fails. Notably, pre-commit stashes changes temporarily so only what you've staged gets checked.

For example, this is the output I see locally when I rearrange the imports in cli.py and another file, but only stage cli.py in a commit:

[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\Kurt\.cache\pre-commit\patch1694373671-15164.
check yaml...........................................(no files to check)Skipped
fix end of files.........................................................Passed
mixed line ending........................................................Passed
trim trailing whitespace.................................................Passed
Enforce Python 3.6 idioms................................................Passed
black....................................................................Passed
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Fixing C:\Users\Kurt\Documents\dev\dotbot\dotbot\cli.py

Check .editorconfig rules................................................Passed
[INFO] Restored changes from C:\Users\Kurt\.cache\pre-commit\patch1694373671-15164.

I have to stage isort's fixes to my commit before I can successfully commit.

kurtmckee commented 4 months ago

Hi Anish! I hope your year is off to a good start!

I'm going to close this PR to reduce cognitive load.

Thanks for your work on dotbot!