# astro-html-validate

[![npm version](https://img.shields.io/npm/v/astro-html-validate)](https://www.npmjs.com/package/astro-html-validate)
[![License](https://img.shields.io/github/license/martinsilha/astro-html-validate)](LICENSE)

[![GitHub stars](https://img.shields.io/github/stars/martinsilha/astro-html-validate?style=social)](https://github.com/martinsilha/astro-html-validate/stargazers)
[![npm downloads](https://img.shields.io/npm/dm/astro-html-validate?style=social)](https://www.npmjs.com/package/astro-html-validate)

[![GitHub release date](https://img.shields.io/github/release-date/martinsilha/astro-html-validate)](https://github.com/martinsilha/astro-html-validate/releases)
[![GitHub last commit](https://img.shields.io/github/last-commit/martinsilha/astro-html-validate)](https://github.com/martinsilha/astro-html-validate/commits/main)

[![CI](https://img.shields.io/github/actions/workflow/status/martinsilha/astro-html-validate/ci.yml?branch=main&label=ci)](https://github.com/martinsilha/astro-html-validate/actions/workflows/ci.yml)
[![Release](https://img.shields.io/github/actions/workflow/status/martinsilha/astro-html-validate/release.yml?branch=main&label=release)](https://github.com/martinsilha/astro-html-validate/actions/workflows/release.yml)
[![semantic-release](https://img.shields.io/badge/semantic--release-automatic-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)

Validate generated Astro HTML with [html-validate](https://html-validate.org/) during `astro build`.

This integration uses your existing html-validate configuration (for example `.htmlvalidate.json`).

## Installation

```bash
# Astro CLI (recommended)
pnpm astro add astro-html-validate

# pick one
pnpm add -D astro-html-validate html-validate
npm install -D astro-html-validate html-validate
yarn add -D astro-html-validate html-validate
```

## Usage

```ts
// astro.config.mjs
import { defineConfig } from "astro/config";
import htmlValidate from "astro-html-validate";

export default defineConfig({
  integrations: [
    htmlValidate({
      patterns: ["**/*.html"],
      formatter: "text",
      failOnWarning: false,
      allowEmpty: true,
    }),
  ],
});
```

## Options

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `patterns` | `string \| string[]` | `['**/*.html']` | File globs to validate, relative to Astro output directory. |
| `formatter` | `string` | `'text'` | html-validate formatter to use for console output. |
| `failOnWarning` | `boolean` | `false` | Fail build when warnings are present. |
| `allowEmpty` | `boolean` | `true` | If no files match, warn instead of failing. |

## How config is resolved

`html-validate` auto-discovers configuration from your project root and file paths, so your existing `.htmlvalidate.*` config will be applied to build output.

## Development

```bash
pnpm install
pnpm run lint
pnpm run build
```

## Commit Conventions

This repository enforces [Conventional Commits](https://www.conventionalcommits.org/) with `commitlint` in CI and a local Husky `commit-msg` hook.

Examples:

- `feat: add formatter option docs`
- `fix: handle empty output dir warning`
- `feat!: rename integration option`

## Releases

Releases are automated with `semantic-release` from `main`.

Version bump rules:

- `fix:` => patch
- `feat:` => minor
- `!` or `BREAKING CHANGE:` => major

Local checks before merging:

```bash
pnpm run check:release
pnpm run release:dry-run
```

## License

MIT
