Skip to content

Commit 08d17b5

Browse files
committed
Adapt for google-java-format
1 parent d49933e commit 08d17b5

6 files changed

Lines changed: 74 additions & 91 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@ jobs:
1212
with:
1313
env: '["py311"]'
1414
os: windows-latest
15-
wheel-tags: true
1615
main-macos:
1716
uses: asottile/workflows/.github/workflows/tox.yml@v1.11.1
1817
with:
1918
env: '["py311"]'
2019
os: macos-latest
21-
wheel-tags: true
22-
main-macos-intel:
23-
uses: asottile/workflows/.github/workflows/tox.yml@v1.11.1
24-
with:
25-
env: '["py311"]'
26-
os: macos-15-intel
27-
wheel-tags: true
2820
main-linux:
2921
uses: asottile/workflows/.github/workflows/tox.yml@v1.11.1
3022
with:

‎.pre-commit-hooks.yaml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
- id: shellcheck
2-
name: shellcheck
3-
description: Test shell scripts with shellcheck
4-
entry: shellcheck
1+
- id: google-java-format
2+
name: google-java-format
3+
description: Format Java source files with google-java-format
4+
entry: google-java-format
5+
args:
6+
- --replace # Format in-place
57
language: python
6-
types: [shell]
7-
exclude_types: [zsh]
8-
require_serial: true # shellcheck can detect sourcing this way
8+
types: [java]

‎LICENSE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

33
Copyright (c) 2019 Ryan Rhee
4+
Copyright (c) 2026 Nhat Nguyen
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

‎README.md‎

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,57 @@
1-
[![build status](https://github.com/shellcheck-py/shellcheck-py/actions/workflows/main.yml/badge.svg)](https://github.com/shellcheck-py/shellcheck-py/actions/workflows/main.yml)
2-
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/shellcheck-py/shellcheck-py/main.svg)](https://results.pre-commit.ci/latest/github/shellcheck-py/shellcheck-py/main)
1+
# google-java-format-pre-commit
32

4-
# shellcheck-py
3+
A performant [pre-commit] hook for [google-java-format] utilizing the GraalVM native binary without requiring a Java runtime.
54

6-
A python wrapper to provide a pip-installable [shellcheck] binary.
5+
This repo is based on [shellcheck-py] and maintains the exact same approach to provide the `google-java-format` native binary.
76

8-
Internally this package provides a convenient way to download the pre-built
9-
shellcheck binary for your particular platform.
7+
For more details, see the [Motivation](#motivation) section.
108

11-
### installation
9+
## Usage
1210

13-
```bash
14-
pip install shellcheck-py
11+
This is only intended to be used with [pre-commit]. See [pre-commit] for more details.
12+
13+
Sample `.pre-commit-config.yaml`:
14+
15+
```yaml
16+
- repo: https://github.com/natecrafts/google-java-format-pre-commit
17+
rev: v2.0.0
18+
hooks:
19+
- id: google-java-format
1520
```
1621
17-
### usage
22+
## Motivation
1823
19-
After installation, the `shellcheck` binary should be available in your
20-
environment (or `shellcheck.exe` on windows).
24+
The [google-java-format] project publishes a native binary built via GraalVM
25+
besides the traditional JAR file. The native binary offers a few benefits over
26+
the JAR file:
2127
22-
### As a pre-commit hook
28+
- The native binary is more performant, which is desirable for a code formatter.
29+
- The native binary does not require a local JDK/JRE installation to run.
2330
24-
See [pre-commit] for instructions
31+
A native binary is published as part of each GitHub release of [google-java-format].
2532
26-
Sample `.pre-commit-config.yaml`:
33+
At the time this was written, [pre-commit] did not yet have a direct way to
34+
download binaries and use them for hooks.
35+
See issue https://github.com/pre-commit/pre-commit/issues/1453.
2736
28-
```yaml
29-
- repo: https://github.com/shellcheck-py/shellcheck-py
30-
rev: v0.11.0.1-1
31-
hooks:
32-
- id: shellcheck
33-
```
37+
On the other hand, an alternative approach has been used by [shellcheck-py] to
38+
create a hook for the `shellcheck` binary. The basic idea is making the
39+
`shellcheck` binary available inside a Python environment and utilizing the
40+
`python` language of [pre-commit]. This involves the use of the setuptools
41+
plugin [setuptools-download] running at build time of the Python package to
42+
download the binaries. Since the download happens during build time,
43+
[pre-commit] is able to correctly cache the downloaded binaries for repeated
44+
use of the hook. This repo is a fork of [shellcheck-py], adopting the same
45+
approach and only adjusting where it is relevant for [google-java-format]
46+
instead of `shellcheck`.
47+
48+
## Acknowledgements
49+
50+
- [google-java-format] by Google.
51+
- [pre-commit] and [setuptools-download] by Anthony Sottile.
52+
- [shellcheck-py] by Ryan Rhee and Anthony Sottile for the packaging and pre-commit hook pattern.
3453

35-
[shellcheck]: https://shellcheck.net
3654
[pre-commit]: https://pre-commit.com
55+
[google-java-format]: https://github.com/google/google-java-format
56+
[shellcheck-py]: https://github.com/shellcheck-py/shellcheck-py
57+
[setuptools-download]: https://github.com/asottile/setuptools-download

‎setup.cfg‎

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[metadata]
2-
name = shellcheck_py
3-
version = 0.11.0.1
4-
description = Python wrapper around invoking shellcheck (https://www.shellcheck.net/)
2+
name = google_java_format_pre_commit
3+
version = 2.0.0
4+
description = Python wrapper invoking google-java-format (https://github.com/google/google-java-format)
55
long_description = file: README.md
66
long_description_content_type = text/markdown
7-
url = https://github.com/ryanrhee/shellcheck-py
8-
author = Ryan Rhee
9-
author_email = pypi@rhee.io
7+
url = https://github.com/natecrafts/google-java-format-pre-commit
8+
author = Nhat Nguyen
109
license = MIT
1110
license_files = LICENSE
1211
classifiers =
@@ -22,55 +21,25 @@ setup_requires =
2221

2322
[setuptools_download]
2423
download_scripts =
25-
[shellcheck]
26-
group = shellcheck-binary
27-
marker = sys_platform == "linux" and platform_machine == "armv6hf"
28-
marker = sys_platform == "linux" and platform_machine == "armv7l"
29-
url = https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.armv6hf.tar.xz
30-
sha256 = 8afc50b302d5feeac9381ea114d563f0150d061520042b254d6eb715797c8223
31-
extract = tar
32-
extract_path = shellcheck-v0.11.0/shellcheck
33-
[shellcheck]
34-
group = shellcheck-binary
24+
[google-java-format]
25+
group = google-java-format-binary
3526
marker = sys_platform == "linux" and platform_machine == "aarch64"
36-
url = https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.aarch64.tar.xz
37-
sha256 = 12b331c1d2db6b9eb13cfca64306b1b157a86eb69db83023e261eaa7e7c14588
38-
extract = tar
39-
extract_path = shellcheck-v0.11.0/shellcheck
40-
[shellcheck]
41-
group = shellcheck-binary
42-
marker = sys_platform == "linux" and platform_machine == "riscv64"
43-
url = https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.riscv64.tar.xz
44-
sha256 = 693c987777e7b524dd311d9b8c704885a39c889c9804bb1ef1fd29b48567b0b3
45-
extract = tar
46-
extract_path = shellcheck-v0.11.0/shellcheck
47-
[shellcheck]
48-
group = shellcheck-binary
27+
url = https://github.com/google/google-java-format/releases/download/v2.0.0/google-java-format_linux-arm64
28+
sha256 = 3193ae2e3a32634a45effc9f575005e7adf202699ab4d9d6488ff1a715588d10
29+
[google-java-format]
30+
group = google-java-format-binary
4931
marker = sys_platform == "linux" and platform_machine == "x86_64"
50-
url = https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz
51-
sha256 = 8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198
52-
extract = tar
53-
extract_path = shellcheck-v0.11.0/shellcheck
54-
[shellcheck]
55-
group = shellcheck-binary
32+
url = https://github.com/google/google-java-format/releases/download/v2.0.0/google-java-format_linux-x86-64
33+
sha256 = c351f587e6dd1f11836be7296894ea2ab3bd91847dbd14101f4f04d390380fe9
34+
[google-java-format]
35+
group = google-java-format-binary
5636
marker = sys_platform == "darwin" and platform_machine == "arm64"
57-
url = https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.darwin.aarch64.tar.xz
58-
sha256 = 56affdd8de5527894dca6dc3d7e0a99a873b0f004d7aabc30ae407d3f48b0a79
59-
extract = tar
60-
extract_path = shellcheck-v0.11.0/shellcheck
61-
[shellcheck]
62-
group = shellcheck-binary
63-
marker = sys_platform == "darwin" and platform_machine == "x86_64"
64-
url = https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.darwin.x86_64.tar.xz
65-
sha256 = 3c89db4edcab7cf1c27bff178882e0f6f27f7afdf54e859fa041fca10febe4c6
66-
extract = tar
67-
extract_path = shellcheck-v0.11.0/shellcheck
68-
[shellcheck.exe]
69-
group = shellcheck-binary
37+
url = https://github.com/google/google-java-format/releases/download/v2.0.0/google-java-format_darwin-arm64
38+
sha256 = 04b13ad486bcc29ef64f7168c2d3eb330e73ae458610ba5bcf44f6018b655dc4
39+
[google-java-format.exe]
40+
group = google-java-format-binary
7041
marker = sys_platform == "win32" and platform_machine == "AMD64"
7142
marker = sys_platform == "win32" and platform_machine == "ARM64"
7243
marker = sys_platform == "cygwin" and platform_machine == "x86_64"
73-
url = https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.zip
74-
sha256 = 8a4e35ab0b331c85d73567b12f2a444df187f483e5079ceffa6bda1faa2e740e
75-
extract = zip
76-
extract_path = shellcheck.exe
44+
url = https://github.com/google/google-java-format/releases/download/v2.0.0/google-java-format_windows-x86-64.exe
45+
sha256 = 6e757021d3b5a8133ca3b5b1915c4cf38dc46ad0886bc9059fcc2ccb7b6036e5

‎tox.ini‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ envlist = py,pre-commit
33

44
[testenv]
55
commands =
6-
shellcheck --version
7-
shellcheck --help
6+
google-java-format --version
7+
google-java-format --help
88

99
[testenv:pre-commit]
1010
skip_install = true

0 commit comments

Comments
 (0)