1
0
mirror of https://github.com/j178/prek.git synced 2026-04-25 02:11:36 +02:00
Commit Graph

23 Commits

Author SHA1 Message Date
Jo 393d0ad41d Improve merge conflict marker detection (#1937)
## Summary

- make `check-merge-conflict` detect conflict blocks contextually
instead of flagging any bare `=======`
- add support for diff3 ancestor markers (`|||||||`)

Closes #1924 
Closes #1523
2026-04-14 10:59:51 +08:00
RicardoVercetti b13d37887b Add forbid-new-submodules as builtin hook (#1853)
for #1849

## Summary:
- Added the pre-commit `forbid_new_submodule` hook

## Usage:

```yaml
repos:
  - repo: builtin
    hooks:
      - id: forbid-new-submodules
```

---------

Co-authored-by: Jehoniah <aaram@appliedpaymentstech.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-25 17:59:39 +08:00
Felix Blom ba62c04078 Add pretty_format_json as builtin hook (#915)
## Description

Following the information provided in
[880](https://github.com/j178/prek/issues/880). This is an
implementation of the `pretty-format-json` hook.

The
[pretty-format-json](https://grep.app/search?f.path.pattern=.pre-commit-config.yaml&q=pretty-format-json)
has 1k grep.app hits. It's the final unimplemented hook used by
`airflow` as mentioned in [this
comment](https://github.com/j178/prek/issues/880#issuecomment-3405716137).

----

##  Notes

- **Preserve JSON Order**  
- Added the `preserve_order` feature to `serde_json`. This prevents
`serde` from automatically ordering JSON data, which is important for
comparisons with older implementations.
  - This change does not appear to affect other tests/features.  
- By default, `serde` uses a `BTreeMap` for `Object`. Enabling
`preserve_order` switches it to `IndexMap`.
  - This keeps the sorting logic within the `sort-keys` argument.

- **Git-Style Diff with `similar`**  
  - Added the `similar` library to perform git-style diff checks.  
  - Binary size increase is minimal.  
- Useful as a general utility and could be leveraged in other parts of
the project, maybe needed to be relocated?
- Added color highlighting to the diffs, improving readability compared
to original `pre-commit`.


```bash
cargo clean
cargo build --release 
```
- Master branch:  **8.49 MB**
- Feature branch: **8.55 MB**
- **+66,176 bytes** (**+0.74%**) increase from master to feature branch

_Q: why is my size so much smaller than both sizes mentioned
[here](https://github.com/j178/prek/pull/884#issuecomment-3406885242)?_

-----

### Performance

Ran these commands on the `airflow` repository:
```bash
# old
pre-commit run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.03s

# Old prek implementation (python)
prek run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.03s

# New implementation (rust)
prek run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.00s
```

## Output
Old pre-commit:
<img width="601" height="376" alt="image"
src="https://github.com/user-attachments/assets/f0553015-24cf-4d23-98e8-2759f912c9b3"
/>

New:
<img width="707" height="430" alt="image"
src="https://github.com/user-attachments/assets/fa7ce303-caa9-4139-9e77-6e58db5f0725"
/>

Where both would autofix to the same:
<img width="349" height="304" alt="image"
src="https://github.com/user-attachments/assets/67baf526-787b-4aa6-a0fe-7859a2a5fb8b"
/>

---------

Co-authored-by: Felix Blom <70511386+Felix-Blom@users.noreply.github.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-23 14:58:11 +08:00
Jo 24f2d627bf Add destroyed-symlinks builtin hook (#1851)
Closes #1848

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-22 21:19:50 +08:00
Jo fc529df132 Add check-shebang-scripts-are-executable builtin hook (#1847) 2026-03-22 00:59:38 +08:00
Jo addddb8989 Add file-contents-sorter as builtin hook (#1846)
Closes #1843
2026-03-21 23:42:44 +08:00
Matt Van Horn cb3f71c322 Add check-vcs-permalinks as builtin hook (#1842)
## Summary

Add a native Rust fast path for the `check-vcs-permalinks` hook from
`pre-commit/pre-commit-hooks`.

## Why this matters

Without a fast path, prek must clone the `pre-commit/pre-commit-hooks`
repo, install Python, and run the hook script. The native implementation
avoids that overhead for a simple regex-based check.

## Changes

- New file:
`crates/prek/src/hooks/pre_commit_hooks/check_vcs_permalinks.rs`
- Port of the [upstream Python
implementation](https://github.com/pre-commit/pre-commit-hooks/blob/main/pre_commit_hooks/check_vcs_permalinks.py)
- Detects GitHub blob URLs that use a branch name (e.g. `main`,
`master`) instead of a commit hash, combined with a `#L` line number
anchor
- Scans files concurrently using the existing
`run_concurrent_file_checks` helper
  - Reports file path, line number, and offending line content
  - Includes unit tests for permalinks, branch links, and edge cases
- Updated `crates/prek/src/hooks/pre_commit_hooks/mod.rs`: added
`CheckVcsPermalinks` variant

## Testing

- `cargo check -p prek` passes
- Unit tests verify both positive (branch link) and negative (commit
hash permalink) cases

Fixes #1833

This contribution was developed with AI assistance (Claude Code).

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-21 22:54:25 +08:00
Matt Van Horn 307254d3fc Add check-illegal-windows-names as builtin hook (#1841)
## Summary

Add a native Rust fast path for the `check-illegal-windows-names` hook
from `pre-commit/pre-commit-hooks`.

## Why this matters

Without a fast path, prek must clone the `pre-commit/pre-commit-hooks`
repo and parse `.pre-commit-hooks.yaml` just to run a regex-based
filename check. The native implementation skips that overhead entirely.

## Changes

- New file:
`crates/prek/src/hooks/pre_commit_hooks/check_illegal_windows_names.rs`
- Uses the same regex from upstream's
[`.pre-commit-hooks.yaml`](https://github.com/pre-commit/pre-commit-hooks/blob/f1dff44d3a9ae852957f34def96390f28719c232/.pre-commit-hooks.yaml#L49)
- Detects reserved names (CON, PRN, AUX, NUL, COM1-9, LPT1-9), illegal
characters (<>:"|?*), control characters, and trailing dots/spaces
- Includes unit tests for legal filenames, reserved names, illegal
characters, and trailing dots/spaces
- Updated `crates/prek/src/hooks/pre_commit_hooks/mod.rs`: added
`CheckIllegalWindowsNames` variant to enum and wired up the `run`
dispatch

## Testing

- `cargo check -p prek` passes
- Unit tests cover legal names, reserved names, illegal characters, and
trailing dots/spaces

Fixes #1835

This contribution was developed with AI assistance (Claude Code).

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-21 22:43:51 +08:00
Shaan Majid f5262b6b2c docs: fix HTML anchors, grammar, capitalization, and add missing tracking issues (#1448) 2026-01-22 02:06:13 +08:00
Matthias Schoettle 0784ddfaea Add mdformat pre-commit hook (#1416) 2026-01-20 11:26:37 +08:00
Jo b7b453d500 Document that check-json5 now rejects duplicate keys (#1391) 2026-01-18 17:01:09 +08:00
Jo be8f49e6f3 Document builtin hooks (#1370) 2026-01-16 15:23:39 +08:00
Jo 352685fdbd Add check-json5 as builtin hooks (#1367)
* Add `check-json5` as builtin hooks

* Refactor

* Add tests

* Tweak

* Document JSON5 duplicate key behavior in test (#1368)

* Initial plan

* Add documentation explaining duplicate key behavior in JSON5

Co-authored-by: j178 <10510431+j178@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-01-16 14:51:51 +08:00
Louis Maddox 5785a1aa42 Implement check-case-conflict as builtin hook (#888)
* feat(check-case-conflict): implement builtin hook

# Conflicts:
#	crates/prek/src/hooks/pre_commit_hooks/check_case_conflict.rs
#	crates/prek/tests/builtin_hooks.rs
#	src/builtin/pre_commit_hooks/mod.rs

* fix: exit test gracefully on case insensitive file system

* Add docs

* Fix tests

* Add to builtin hooks

* Reduce allocs

* Further reduce

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2025-12-18 13:42:10 +08:00
ChiLin Chiu 95eb880b5a Fix typo “Not” to “Note” in the Automatic Fast Path section (#1148) 2025-11-23 16:28:51 +08:00
Jo 3e88436974 Add support repo: builtin (#1118)
* Add support `repo: builtin`

* Add docs

* Fixes

* Skip install for builtin hooks
2025-11-19 17:29:14 +08:00
Felix Blom aa6cd18cde Implement check-executables-have-shebangs as builtin-hook (#924)
* feat: Implement check-executables-have-shebangs hook

* Tweak

* Minor

* Tweak

* Minor

* feat: Implement check-executables-have-shebangs hook

* Fix paths

* Debug

* Debug

* Fix ls-files split

* Update docs

---------

Co-authored-by: Felix Blom <70511386+Felix-Blom@users.noreply.github.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2025-10-30 16:29:24 +08:00
Les Freire 93a70da4da Update built-in hook documentation (#943) 2025-10-20 16:23:45 +08:00
Jo 17e3629be1 Update document (#809) 2025-09-28 17:08:11 +08:00
Jo cd3a934d9d Clarify built-in hooks activation conditions and behavior (#781) 2025-09-22 17:12:54 +08:00
Jo 65c29da7b6 Update some docs (#745)
* .

* Improve some docs
2025-09-15 15:59:13 +08:00
Kushagra Udai 4b89c003f2 Add built in byte-order-marker fixer (#700)
* Add built in byte-order-marker fixer

* fmt

* feedback

* fmt
2025-09-11 10:39:42 +08:00
Jo cd2cb80c9f Add docs about builtin hooks (#678) 2025-09-09 11:59:43 +08:00