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

13 Commits

Author SHA1 Message Date
Jo 434db54b59 Refine dotnet SDK version handling and tests (#1870) 2026-03-30 22:41:07 +08:00
Thomas Carroll 5c426d2c74 Add language: dotnet support (#1783)
Hi, I thought I'd give a stab at dotnet support for prek. Not really an
amazing language for how it manages tools & its toolchain, so perhaps
some nastiness. Seems to work for `csharpier` at least for me.

There's some missing tests around the windows part of the code in the
coverage but I didn't want to get into messing with CI for windows
runners, maybe we can drop the powershell stuff if we make windows
people run in a bash type environment?

Not very versed in rust but hoping that even if stuff's bad there's a
bit of a start for someone better than I to have a stab at.

closes #48

---------

Co-authored-by: Thomas Carroll <thomas.carroll@kroll.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-03-30 22:41:07 +08:00
Shaan Majid 2b811fb6a2 Add language: deno support (#1516)
---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
2026-03-20 09:24:24 +08:00
Jo 1bead452d8 Improve docs for Rust cli: dependencies (#1748) 2026-03-06 21:25:54 +08:00
Jo 03d1f87e9f rust: support cli: git dependency 4th segment package disambiguation (#1747)
Fixes #1682
Extends #1256

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-03-06 20:44:06 +08:00
is-alnilam e993b04305 Add automatic Ruby download support using rv binaries (#1668)
Current Ruby support can only use Ruby interpreters which are already
installed on the system, although it goes to great lengths to find
interpreters installed by a variety of Ruby managers. This change adds
support for installing new interpreters using the binaries delivered by
the `rv` team. `rv` only provide installers for versions of Ruby still
actively supported (so they don't offer version 3.1, for example), and
only build for a subset of all Ruby-supported platforms. If users need
an unsupported version of Ruby or wish to use an unsupported platform,
they will be prompted to download and install a version of Ruby
manually.

`rv` bundles are named according to the platform, currently including
these components in the filename:
- x86_64_linux
- arm64_linux
- x86_64_linux_musl
- arm64_linux_musl
- ventura (used for macOS on x86_64)
- arm64_sonoma (used for macOS on 64-bit ARM)

If and when upstream `rv` changes these names, the detection code will
need to be updated to match. In particular, this includes the use of
macOS codenames, as if `rv` stop releasing a 'sonoma' package, this will
block installing the macOS versions of Ruby. Currently `rv` seem to be
attempting to keep these codenames, as they already rename their x86_64
builds from 'sequoia' (macOS 15) to 'ventura' (macOS 13). Adding a new
CPU architecture (such as RISC-V) would also need changes, but wouldn't
break existing platform support.

Ruby versions are found by querying the GitHub Releases API, searching
the options returned for an installer that matches the platform and
version requirements, then, if found, downloading and unpacking into the
`prek` tools folder. The `PREK_RUBY_MIRROR` environment variable can be
used to point to a different source for installers, for example to
support mirrors or air-gapped CI environments. Mirrors need to follow
the GitHub URL patterns, but note that although the GitHub hostname
changes between `api.github.com` and `github.com` as needed, any
non-GitHub mirror server will not be remapped in this manner. Where Ruby
is being downloaded from GitHub (either from the upstream `rv` or a
mirror), this remapping does occur, and any `GITHUB_TOKEN` will be sent
with the requests. This both limits impact of rate limiting, and also
allows a private GitHub repository to be used (e.g. for a vetted subset
of `rv` rubies to be mirrored). Note that GitHub tokens will only be
sent to mirrors which are hosted on GitHub.

To allow for passing the `GITHUB_TOKEN` in download requests, the
generic `download_and_extract` function is now a wrapper over a version
which takes an extension function, with the default function not
extending the request. The Ruby code will add the GitHub token if the
request is to GitHub.

Closes #43
Closes #765

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-01 23:03:29 +08:00
Copilot bfade9f6a5 Use --locked for Rust cargo install commands (#1661)
Rust hooks can break when dependency versions change between
installations. `cargo install` without `--locked` will resolve
dependencies freshly, potentially pulling incompatible versions even
when `Cargo.lock` exists.

## Changes

- Add `--locked` flag to both `cargo install` invocations in
`crates/prek/src/languages/rust/rust.rs`:
  - Local package installation: `cargo install --path . --locked`
  - CLI dependencies: `cargo install <package> --locked`
- Document the behavior in `docs/languages.md`

## Example

```yaml
repos:
  - repo: https://github.com/example/rust-hook
    rev: v1.0.0
    hooks:
      - id: my-rust-hook
        # Now installs with exact Cargo.lock versions
```

Note: Packages without a `Cargo.lock` will have `--locked` ignored by
cargo (not an error).

> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `mirrors.aliyun.com`
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install-hooks -incompat
bmemchr-1fe43bea993d3235.rlib breg bsyn-2136fc17f010f281.rlib
3pURqBq1pk3divZeIfIb/target/release/deps/prek_rust_echo_lib_deps-59bce7d6001d3263.prek_rust_echo-c
3pURqBq1pk3divZeIfIb/target/release/deps/prek_rust_echo_lib_deps-59bce7d6001d3263.e4dqohtw0l0ytrcore.useBuiltinFSMonitor=false
lib 6ed2694.rlib 3pURqBq1pk3divZecommit.gpgsign=false b/rustlib/x86_64-c
b/ru b/rustlib/x86_64-c b/rustlib/x86_64core.autocrlf=false
b/rustlib/x86_64-c b/rustlib/x86_64/usr/bin/git b/rustlib/x86_64-c
b/rustlib/x86_64core.useBuiltinFSMonitor=false
b/rustlib/x86_64rev-parse` (dns block)
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install --install-hooks
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.1nzs07cgjxiexpa7i3g2b01rt.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.24lsa75b6fov0tk3qt95numqq.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.27k9375t0pciii4hjcyuhgf4w.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2gbphvwl0vvhd1w9zm3ido74e.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2i6mzsq4vdcksvs36vquiynd0.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2mdk2h4p88ofn49ujd91zdlk0.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.30nea9p9x6pr2
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.33cvujd6pv5nrd021hs6r57ur.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.33svn44fanwynb1ljchzak5c5.1elqi5j.rcgu.o
u.1. in.so /lto-wrapper 1.93-x86_64-REDACTED-linux-gnu/bi-c
-f448dbb239ade73cc 0a5a4d1a26cf608--m64
orznfljxz.rcgu.o/tmp/rustcq8iZJY/symbols.o
1.93-x86_64-unkn/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.0b78bzeosorigin`
(dns block)
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install-hooks -I
angecoder aZFf pi -I p/bin/as hemars_derive-8b/usr/bin/git
hemars_derive-8b-c hemars_derive-8bcore.useBuiltinFSMonitor=false
hemars_derive-8bdiff hema hemars_derive-8b--no-textconv
hemars_derive-8b--ignore-submodules hemars_derive-8b--
hemars_derive-8bgit hemars_derive-8bcommit hemars_derive-8b-m
hemars_derive-8bUpdate documentation for --locked flag usage

Co-authored-by: j178 &lt;10510431&#43;j17--eh-frame-hdr` (dns block)
> - `mirrors.cloud.tencent.com`
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install-hooks -incompat
bmemchr-1fe43bea993d3235.rlib breg bsyn-2136fc17f010f281.rlib
3pURqBq1pk3divZeIfIb/target/release/deps/prek_rust_echo_lib_deps-59bce7d6001d3263.prek_rust_echo-c
3pURqBq1pk3divZeIfIb/target/release/deps/prek_rust_echo_lib_deps-59bce7d6001d3263.e4dqohtw0l0ytrcore.useBuiltinFSMonitor=false
lib 6ed2694.rlib 3pURqBq1pk3divZecommit.gpgsign=false b/rustlib/x86_64-c
b/ru b/rustlib/x86_64-c b/rustlib/x86_64core.autocrlf=false
b/rustlib/x86_64-c b/rustlib/x86_64/usr/bin/git b/rustlib/x86_64-c
b/rustlib/x86_64core.useBuiltinFSMonitor=false
b/rustlib/x86_64rev-parse` (dns block)
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install --install-hooks
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.1nzs07cgjxiexpa7i3g2b01rt.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.24lsa75b6fov0tk3qt95numqq.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.27k9375t0pciii4hjcyuhgf4w.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2gbphvwl0vvhd1w9zm3ido74e.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2i6mzsq4vdcksvs36vquiynd0.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2mdk2h4p88ofn49ujd91zdlk0.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.30nea9p9x6pr2
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.33cvujd6pv5nrd021hs6r57ur.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.33svn44fanwynb1ljchzak5c5.1elqi5j.rcgu.o
u.1. in.so /lto-wrapper 1.93-x86_64-REDACTED-linux-gnu/bi-c
-f448dbb239ade73cc 0a5a4d1a26cf608--m64
orznfljxz.rcgu.o/tmp/rustcq8iZJY/symbols.o
1.93-x86_64-unkn/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.0b78bzeosorigin`
(dns block)
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install-hooks -I
angecoder aZFf pi -I p/bin/as hemars_derive-8b/usr/bin/git
hemars_derive-8b-c hemars_derive-8bcore.useBuiltinFSMonitor=false
hemars_derive-8bdiff hema hemars_derive-8b--no-textconv
hemars_derive-8b--ignore-submodules hemars_derive-8b--
hemars_derive-8bgit hemars_derive-8bcommit hemars_derive-8b-m
hemars_derive-8bUpdate documentation for --locked flag usage

Co-authored-by: j178 &lt;10510431&#43;j17--eh-frame-hdr` (dns block)
> - `notexistentatallnevergonnahappen.com`
> - Triggering command: `/usr/lib/git-core/git-remote-https
/usr/lib/git-core/git-remote-https origin REDACTED est 2onf
70f92045177692.r-c unwind-35a18a198core.autocrlf=false
-6d361988d845791-c ags)&#39; ine-9a4df3979b2crev-parse
6a0d9f8e67558a02--show-toplevel -f448dbb239ade73-c dema
tect-9b165106d41init own-0c83c3b51a9f5653.rlib
cal/share/prek/tests/.tmp1lfoNL/-c oxide-ec844042f1/usr/bin/git
-fa28e789c10e1e7rev-parse -REDACTED-linux-g--show-toplevel
cal/share/prek/tests/.tmp1lfoNL/-c` (dns block)
> - Triggering command: `/usr/lib/git-core/git-remote-https
/usr/lib/git-core/git-remote-https origin REDACTED est 2onf prek.dev
2onfp.rcgu.o k/_temp/ghcca-no-c ags)&#39; 2onfp.rcgu.o .lld 2onfp.rcgu.o
2onf alse .lld e 2onfp.rcgu.o lse
ip-0.0.17/src/licore.useBuiltinFSMonitor=false est` (dns block)
> - `pypi.tuna.tsinghua.edu.cn`
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install-hooks -incompat
bmemchr-1fe43bea993d3235.rlib breg bsyn-2136fc17f010f281.rlib
3pURqBq1pk3divZeIfIb/target/release/deps/prek_rust_echo_lib_deps-59bce7d6001d3263.prek_rust_echo-c
3pURqBq1pk3divZeIfIb/target/release/deps/prek_rust_echo_lib_deps-59bce7d6001d3263.e4dqohtw0l0ytrcore.useBuiltinFSMonitor=false
lib 6ed2694.rlib 3pURqBq1pk3divZecommit.gpgsign=false b/rustlib/x86_64-c
b/ru b/rustlib/x86_64-c b/rustlib/x86_64core.autocrlf=false
b/rustlib/x86_64-c b/rustlib/x86_64/usr/bin/git b/rustlib/x86_64-c
b/rustlib/x86_64core.useBuiltinFSMonitor=false
b/rustlib/x86_64rev-parse` (dns block)
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install --install-hooks
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.1nzs07cgjxiexpa7i3g2b01rt.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.24lsa75b6fov0tk3qt95numqq.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.27k9375t0pciii4hjcyuhgf4w.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2gbphvwl0vvhd1w9zm3ido74e.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2i6mzsq4vdcksvs36vquiynd0.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.2mdk2h4p88ofn49ujd91zdlk0.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.30nea9p9x6pr2
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.33cvujd6pv5nrd021hs6r57ur.1elqi5j.rcgu.o
/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.33svn44fanwynb1ljchzak5c5.1elqi5j.rcgu.o
u.1. in.so /lto-wrapper 1.93-x86_64-REDACTED-linux-gnu/bi-c
-f448dbb239ade73cc 0a5a4d1a26cf608--m64
orznfljxz.rcgu.o/tmp/rustcq8iZJY/symbols.o
1.93-x86_64-unkn/home/REDACTED/work/prek/prek/target/debug/deps/install-cf41a32d524c5058.0b78bzeosorigin`
(dns block)
> - Triggering command: `/home/REDACTED/work/prek/prek/target/debug/prek
/home/REDACTED/work/prek/prek/target/debug/prek install-hooks -I
angecoder aZFf pi -I p/bin/as hemars_derive-8b/usr/bin/git
hemars_derive-8b-c hemars_derive-8bcore.useBuiltinFSMonitor=false
hemars_derive-8bdiff hema hemars_derive-8b--no-textconv
hemars_derive-8b--ignore-submodules hemars_derive-8b--
hemars_derive-8bgit hemars_derive-8bcommit hemars_derive-8b-m
hemars_derive-8bUpdate documentation for --locked flag usage

Co-authored-by: j178 &lt;10510431&#43;j17--eh-frame-hdr` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/j178/prek/settings/copilot/coding_agent)
(admins only)
>
> </details>

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>Add an option to allow installing Rust tools with
`--locked`</issue_title>
> <issue_description>Without the `--locked` option and without
dependencies properly specified in the hook, a new version release of a
dependency can cause the hook that previously worked to suddenly stop
working. Therefore, I propose adding an option to use `--locked`, as
propsed in https://github.com/pre-commit/pre-commit/issues/3162 .
> 
> Alternatively, as proposed in https://github.com/j178/prek/issues/681,
supporting `cargo-binstall` would also resolve this issue for users with
limited security concerns.</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> <comment_new><author>@j178</author><body>
> I think we should probably always use `--locked`, would that be a
breaking change?</body></comment_new>
> <comment_new><author>@j178</author><body>
> > would that be a breaking change?
> 
> Yeah. For crates that don’t ship a `Cargo.lock`, `cargo install
--locked` will fail.</body></comment_new>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes j178/prek#1567

<!-- START COPILOT CODING AGENT TIPS -->
---

 Let Copilot coding agent [set things up for
you](https://github.com/j178/prek/issues/new?title=+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
2026-02-18 21:32:40 +08:00
Les Freire 0a4be22599 Support Julia language (#1519)
resolve #1446

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-02-01 16:13:55 +08:00
Les Freire d12e0be035 Support haskell language (#1484)
resolve #1445

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-01-31 20:28:42 +08:00
Shaan Majid e4d3dfd10a Add language: swift support (#1463)
* feat(swift): add Swift language support

Implement Swift language support for prek:
- Query swift executable and parse version from `swift --version`
- Handle both macOS (Apple Swift) and Linux version formats
- Normalize versions without patch component (e.g., "6.1" -> "6.1.0")
- Handle pre-release versions (e.g., "6.2-dev")
- Build Package.swift repos with `swift build -c release`
- Use `swift build --show-bin-path` to resolve target-specific bin directory
- Add built binaries to PATH when running hooks
- Health check verifies swift executable still exists

Include unit tests for version parsing covering:
- macOS format with swift-driver prefix
- Linux format
- Multiline output handling
- Versions without patch component
- Development/nightly versions
- Invalid input handling

* test(swift): add Swift language tests

* docs(swift): mark Swift as supported in language documentation

* ci: stabilize swift toolchain setup across platforms

- pin Swift version in env to keep CI deterministic\n- use SwiftyLab/setup-swift on Windows where swift-actions fails\n- install Swift on macOS and reset TOOLCHAINS back to Xcode\n- force CC/CXX/SDKROOT from Xcode so Ruby native gems compile\n\nThis keeps Swift hooks available while restoring Xcode's clang/SDK,\nwhich avoids msgpack native extension failures on macOS.
2026-01-23 11:28:18 +08:00
Shaan Majid 8d464397e6 Add language: bun support (#1411)
* feat(bun): add Bun language support

* test(bun): add integration tests for Bun language support

Add three integration tests covering the key functionality:
- basic_bun: simple hook execution using bun -e
- additional_dependencies: verify deps installed via bunx cowsay
- language_version: test version specification with language_version: "1"

The additional_dependencies test runs twice to verify health_check and
cache reuse works correctly.

* docs: add Bun to supported languages documentation

- Add Bun to toolchain list in README features section
- Add Bun to managed toolchain downloads list in languages.md
- Add full Bun language section with version format documentation

* ci: add Bun setup to test jobs

* feat(bun): use GITHUB_TOKEN to avoid API rate limits

When listing Bun versions from GitHub releases, use the GITHUB_TOKEN
environment variable if available to authenticate requests. This
increases the rate limit from 60 to 5,000 requests/hour.

GITHUB_TOKEN is automatically set in GitHub Actions workflows.

* fix(bun): use consistent bin_dir path on all platforms

Bun installs global packages to $BUN_INSTALL/bin/ on all platforms,
so bin_dir should always return prefix/bin. The Windows special case
was incorrectly copied from Node (which uses npm's different install
structure).

* Add toolchain download test

* Add tests

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-01-22 11:05:41 +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
Jo 52c20ab065 Document language support details (#1380) 2026-01-17 17:48:11 +08:00