Metadata-Version: 2.5
Name: autohooks-plugin-hadolint
Version: 0.1.0
Summary: An autohooks plugin for Dockerfile linting via hadolint
Project-URL: Homepage, https://github.com/RSMuthu/autohooks-plugin-hadolint
Project-URL: Repository, https://github.com/RSMuthu/autohooks-plugin-hadolint
Project-URL: Issues, https://github.com/RSMuthu/autohooks-plugin-hadolint/issues
Author-email: Muthu Kumaran R <muthukumaranr95@gmail.com>
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Keywords: autohooks,docker,dockerfile,git,hadolint,hooks,linting
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: autohooks>=25.2.0
Description-Content-Type: text/markdown

# autohooks-plugin-hadolint

[![PyPI release](https://img.shields.io/pypi/v/autohooks-plugin-hadolint.svg)](https://pypi.org/project/autohooks-plugin-hadolint/)

An [autohooks](https://github.com/greenbone/autohooks) plugin for Dockerfile
linting via [hadolint](https://github.com/hadolint/hadolint).

On `git commit` the plugin runs hadolint against every **staged** Dockerfile. If
hadolint reports a violation the commit is aborted and the findings are printed.

## Installation

### Install the plugin

Using [uv](https://docs.astral.sh/uv/) (recommended):

```bash
uv add --dev autohooks-plugin-hadolint
```

Using pip:

```bash
python3 -m pip install --user autohooks-plugin-hadolint
```

### Install hadolint

hadolint is a standalone binary and **not** a Python package, so it is not
installed as a dependency of this plugin. Pick whichever route suits you:

```bash
brew install hadolint
```

```bash
sudo apt-get install hadolint
```

Or download a release binary from
[hadolint/hadolint](https://github.com/hadolint/hadolint/releases) and put it on
your `PATH`.

You can also skip the local install entirely and run hadolint through Docker —
see [Running hadolint from a container](#running-hadolint-from-a-container).

## Usage

Activate the plugin:

```bash
uv run autohooks plugins add autohooks.plugins.hadolint
```

or add it to your *pyproject.toml* directly:

```toml
[tool.autohooks]
mode = "uv"
pre-commit = ["autohooks.plugins.hadolint"]
```

and install the git hook itself:

```bash
uv run autohooks activate --mode uv
```

## Configuration

All settings live under `[tool.autohooks.plugins.hadolint]` in your
*pyproject.toml*. Every key is optional.

| Key | Default | Description |
| --- | --- | --- |
| `command` | `["hadolint"]` | Full argv prefix used to run hadolint. `{root}` is replaced with the project root path. |
| `arguments` | `["--no-color", "--format", "tty"]` | Arguments appended to `command`. Replaces the defaults entirely when set. |
| `include` | `["Dockerfile", "Dockerfile.*", "*.Dockerfile", "*.dockerfile", "Containerfile", "Containerfile.*"]` | Patterns deciding which staged files are Dockerfiles. Matched against both the full path and the file name with [fnmatch](https://docs.python.org/3/library/fnmatch.html). |

Each key also accepts a bare string instead of a list.

### Running a local binary

```toml
[tool.autohooks.plugins.hadolint]
command = ["hadolint"]
arguments = ["--no-color", "--format", "tty", "--failure-threshold", "warning"]
```

### Running hadolint from a container

The plugin passes each Dockerfile as a path **relative to the project root**, so
mounting the root into the container is all that is needed. Use the `{root}`
placeholder for the mount source:

```toml
[tool.autohooks.plugins.hadolint]
command = [
    "docker", "run", "--rm",
    "-v", "{root}:/repo", "-w", "/repo",
    "hadolint/hadolint", "hadolint",
]
```

The same works for `podman` or a wrapper script — the first element of
`command` is what the plugin checks for on your `PATH`.

### hadolint's own configuration

Rules are configured by hadolint itself, for example through a `.hadolint.yaml`
in the repository root:

```yaml
ignored:
  - DL3008
```

When running from a container, make sure the config file is inside the mounted
directory (it is, with the `{root}` mount above).

## Example

Copy [examples/binary](examples/binary) or [examples/docker](examples/docker)
into a git repository of its own and follow
[examples/README.md](examples/README.md) to watch a commit get rejected and then
pass.

## Contributing

Contributions are welcome. Please
[open a pull request](https://github.com/RSMuthu/autohooks-plugin-hadolint/pulls)
on GitHub — for larger changes, please
[open an issue](https://github.com/RSMuthu/autohooks-plugin-hadolint/issues)
first so the approach can be discussed.

### Development setup

The project uses [uv](https://docs.astral.sh/uv/):

```bash
uv sync
```

Run the tests:

```bash
uv run pytest
```

One test exercises the real hadolint binary and is skipped when hadolint is not
on your `PATH`, so install it to run the full suite.

Lint and format with [ruff](https://docs.astral.sh/ruff/):

```bash
uv run ruff check . && uv run ruff format .
```

The repository uses its own hooks — ruff and this plugin run on every commit.
Install them once with:

```bash
uv run autohooks activate --mode uv
```

## License

Copyright (C) 2026 Muthu Kumaran R

Licensed under the [GNU General Public License v3.0 or later](LICENSE).
