{"id":15636691,"url":"https://github.com/macisamuele/language-formatters-pre-commit-hooks","last_synced_at":"2025-04-08T09:10:57.740Z","repository":{"id":37561598,"uuid":"141039888","full_name":"macisamuele/language-formatters-pre-commit-hooks","owner":"macisamuele","description":"Collection of custom pre-commit hooks.","archived":false,"fork":false,"pushed_at":"2025-03-29T01:22:19.000Z","size":403,"stargazers_count":125,"open_issues_count":11,"forks_count":62,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-01T08:42:51.773Z","etag":null,"topics":["formatting","pre-commit"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/macisamuele.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-15T15:55:49.000Z","updated_at":"2025-03-30T09:38:26.000Z","dependencies_parsed_at":"2023-12-03T12:28:46.983Z","dependency_job_id":"50c21f71-2443-4808-9e8d-e62ab98ffb8f","html_url":"https://github.com/macisamuele/language-formatters-pre-commit-hooks","commit_stats":{"total_commits":355,"total_committers":35,"mean_commits":"10.142857142857142","dds":0.3718309859154929,"last_synced_commit":"2cb68b58b67bed31ac76df6912dae79a5a98b572"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macisamuele%2Flanguage-formatters-pre-commit-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macisamuele%2Flanguage-formatters-pre-commit-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macisamuele%2Flanguage-formatters-pre-commit-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macisamuele%2Flanguage-formatters-pre-commit-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macisamuele","download_url":"https://codeload.github.com/macisamuele/language-formatters-pre-commit-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatting","pre-commit"],"created_at":"2024-10-03T11:06:17.910Z","updated_at":"2025-04-08T09:10:57.699Z","avatar_url":"https://github.com/macisamuele.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Language Formatters Pre Commit Hooks\n\n[![Github Actions CI](https://github.com/macisamuele/language-formatters-pre-commit-hooks/workflows/Build/badge.svg)](https://github.com/macisamuele/language-formatters-pre-commit-hooks/actions)\n[![Coverage](https://img.shields.io/codecov/c/github/macisamuele/language-formatters-pre-commit-hooks/master.svg)](https://codecov.io/gh/macisamuele/language-formatters-pre-commit-hooks)\n[![PyPi version](https://img.shields.io/pypi/v/language-formatters-pre-commit-hooks.svg)](https://pypi.python.org/pypi/language-formatters-pre-commit-hooks/)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/language-formatters-pre-commit-hooks.svg)](https://pypi.python.org/pypi/language-formatters-pre-commit-hooks/)\n\n## About\n\nThis package provides utilities for ensuring that your code is nicely formatted by using [`pre-commit`](https://pre-commit.com/) hooks\n\n## List of pretty-format hooks\n\n* `pretty-format-golang`\n* `pretty-format-ini`\n* `pretty-format-java`\n* `pretty-format-kotlin`\n* `pretty-format-rust`\n* `pretty-format-toml`\n* `pretty-format-yaml`\n\n⚠: the list above could be out-of-sync respect the exposed pre-commit hooks.\n\nPlease refer to [`.pre-commit-hooks.yaml`](.pre-commit-hooks.yaml) for a more updated list.\n\n## Example Usage\n\nAdd a similar snippet into your `.pre-commit-config.yaml` file\n\n```yaml\n\n- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n  rev: ${LATEST_SHA_OR_VERSION}\n  hooks:\n  - id: pretty-format-java\n    args: [--autofix]\n  - id: pretty-format-kotlin\n    args: [--autofix]\n  - id: pretty-format-yaml\n    args: [--autofix, --indent, '2']\n```\n\n## Development\n\nThis tool uses tox as main tool to build virtual environments.\n\nTo get started will be enough to run `make development`.\n\nIf you have [`aactivator`](https://github.com/Yelp/aactivator) installed this step will happen automatically.\n\n### Contributing\n\nContributions are _always_ welcome.\n\n1. [Fork the project](http://github.com/macisamuele/language-formatters-pre-commit-hooks/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Add your modifications\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## FAQ\n\n### How to deal with different Google Java Formatter versions?\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-java\n        args: [--autofix, --aosp, --google-java-formatter-version=1.16.0]\n```\n\n### How to deal with multiple Java versions?\n\nThis might be relevant for `pretty-format-java` and `pretty-format-kotlin` hooks.\nThe hooks depends on having `java` on version **11** or greater installed on your machine.\n\nAs you're working with _compiled-to-JVM_ languages, we assume that you have `java` installed on your system. You might not have the minimum required version installed.\n\nTo work-around such scenario you have 2 approaches available:\n\n1. Have multiple `java` versions installed on your system and ensure that while running the pre-commit hooks JRE 11+ is available on your `PATH` variable (ie. `PATH=${JRE_11_PATH}:${PATH} pre-commit run`).\n\n2. Work around the issue by using [`docker`](https://www.docker.com/).\n    ⚠: This approach has been tested (at the time of writing) on Linux and MacOS.\n\n    The latter approach should be preferred if you cannot install an additional JRE version on your system or if doing is unfeasible (e.g. on a CI system). Please note you need to have `docker` installed on your system.\n\n    Add the following `Dockerfile` on your repository root (same directory where `.pre-commit-config.yaml` is stored)\n\n    ```Dockerfile\n    FROM python:3.7-alpine\n\n    # Install JRE-11 as we will run pre-commit hooks that depends an Java 11+\n    RUN apk add --no-cache openjdk11-jre\n\n    ENV PRE_COMMIT_HOME /pre-commit-docker-cache\n    ENV PRE_COMMIT_LANGUAGE_FORMATTERS_VERSION ${version of the library to install}\n\n    RUN set -x \\\n        \u0026\u0026 pip install --no-cache-dir language-formatters-pre-commit-hooks==${PRE_COMMIT_LANGUAGE_FORMATTERS_VERSION} \\\n\n        # Run pre-commit-hook to ensure that jars are downloaded and stored in the docker image\n        # Run the hooks that you're planning to run within docker.\n        # This reduces premission issues as well has makes all the run fast as the lazy-dependencies are pre-fetched\n        \u0026\u0026 pretty-format-java  \\\n\n        # Update permissions as hooks will be run as your host-system user (your username) but the image is built as root\n        \u0026\u0026 chmod a+r ${PRE_COMMIT_HOME}/*\n    ```\n\n    and the following hook into your `.pre-commit-config.yaml` file\n\n    ```yaml\n    repos:\n    - repo: local\n      hooks:\n      - id: pretty-format-java-in-docker    # Useful to eventually SKIP pre-commit hooks\n        name: pretty-format-java-in-docker  # This is required, put something sensible\n        language: docker                    # Self explanatory\n        entry: pretty-format-java           # Hook that you want to run in docker\n        args: [...]                         # Arguments that would would pass to the hook (as if it was local)\n        files: ^.*\\.java$                   # File filter has to be added ;)\n    ```\n\n    By doing the following, the selected hook (`pretty-format-java` in the example) will be executed within the docker container.\n\n    Side note: We're not embedding the Dockerfile in the repository as this is more a workaround to support whom cannot of installing a more recent Java version on the library-user system and as such we are not planning to fully support this other than giving possible solutions (Java 11+ was released in September, 2018).\n\n### How to use a pre-downloaded [google-java-format jar](https://github.com/google/google-java-format) file?\n\nYou can pass the jar file path to `--google-java-formatter-jar` argument:\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-java\n        args: [--google-java-formatter-jar=/usr/bin/google-java-format-1.17.0-all-deps.jar]\n```\n\n### How to use a pre-downloaded [ktlint jar](https://github.com/pinterest/ktlint) file?\n\nYou can pass the jar file path to the `--ktlint-jar` argument:\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-kotlin\n        args: [--ktlint-jar=/usr/bin/ktlint.jar]\n```\n\n### How to use a pre-downloaded [ktfmt jar](https://github.com/facebook/ktfmt) file?\n\nYou can pass the jar file path to the `--ktfmt-jar` argument:\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-kotlin\n        args: [--ktfmt, --ktfmt-jar=/usr/bin/ktfmt-0.47.jar]\n```\n\n### How can I verify the checksum of the jar?\n\n_Only supported for the `pretty-format-java` and `pretty-format-kotlin-hooks`_\n\nUse the corresponding `[...]-checksum` argument\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-java\n        args: [\n          --google-java-formatter-version=1.17.0,\n          --formatter-jar-checksum=33068bbbdce1099982ec1171f5e202898eb35f2919cf486141e439fc6e3a4203,\n        ]\n```\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-kotlin\n        args: [\n          --ktlint-version=1.2.1,\n          --formatter-jar-checksum=2e28cf46c27d38076bf63beeba0bdef6a845688d6c5dccd26505ce876094eb92,\n        ]\n```\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-kotlin\n        args: [\n          --ktfmt,\n          --ktfmt-version=0.47,\n          --formatter-jar-checksum=af61161faacd74ac56374e0b43003dbe742ddc0d6a7e2c1fe43e15415e65ffbd,\n        ]\n```\n\n### How to use ktfmt instead of ktlint?\n\n```yaml\n  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks\n    rev: ...\n    hooks:\n      - id: pretty-format-kotlin\n        args: [--ktfmt, --ktfmt-style=google]\n```\n\nSupported styles are google (default), dropbox and kotlinlang\n\n## License\n\n`language-formatters-pre-commit-hooks` is licensed with [`Apache License version 2.0`](http://www.apache.org/licenses/LICENSE-2.0.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacisamuele%2Flanguage-formatters-pre-commit-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacisamuele%2Flanguage-formatters-pre-commit-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacisamuele%2Flanguage-formatters-pre-commit-hooks/lists"}