# @codacy/tools-stylelint-0

## Table of Contents

- [Overview](#overview)
- [Updating patterns](#updating-patterns)
- [Updating the Stylelint version](#updating-the-stylelint-version)
- [Development](#development)
- [Notes for maintainers](#notes-for-maintainers)

---

## Overview

CSS/SCSS/Less linter using [Stylelint](https://stylelint.io). Uses the Library execution strategy — calls the Stylelint API directly rather than spawning a subprocess.

| Property      | Value                                  |
| ------------- | -------------------------------------- |
| Tool ID       | `Stylelint`                            |
| Codacy UUID   | `1f03328a-086e-459e-bfa3-73e56f01020f` |
| Strategy      | Library                                |
| Languages     | CSS, LESS, SASS                        |
| Dependency    | `stylelint` npm package (v17.x)        |
| File patterns | `**/*.css`, `**/*.scss`, `**/*.less`   |

## Updating patterns

```bash
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch

# Commit the result
git add src/patterns.json
```

Pattern IDs follow the format `Stylelint_block-no-empty`, `Stylelint_color-no-invalid-hex`, etc.

## Updating the Stylelint version

1. Update the `stylelint` version in `devDependencies` of `package.json`, and `preferredVersion` in `src/metadata.ts`
2. Run `pnpm install`
3. Run `pnpm generate-payloads stylelint-0` from the repo root to re-pin `payload/package.json` and regenerate its lockfile
4. Run `pnpm prefetch` to check for new/removed rules
5. Run `pnpm test` to verify compatibility
6. If the major version changes, create a new adapter package (`stylelint-1/`)

## Development

```bash
pnpm build    # Build with tsup
pnpm test     # Run tests
```

## Notes for maintainers

- Stylelint v16+ is **pure ESM**. The adapter uses dynamic `import()` at runtime to stay CJS-compatible with the tsup build.
- `stylelint-config-standard` is used as the default config when no local config or Codacy patterns are provided. Without it, Stylelint has zero rules enabled.
- Stylelint appends the rule name in parentheses to warning text (e.g. `"Unexpected empty block (block-no-empty)"`). The adapter strips this suffix for cleaner messages.
- `checkAvailability` dynamically imports Stylelint and runs a trivial lint to verify it loads.
- The tool is an npm _payload_, not a dependency: it is resolved at run time (a Codacy-managed install under `~/.codacy/tools/<id>/`, a `CODACY_TOOL_ROOT_<ID>` root, or this package's own `node_modules` in the monorepo) and `install` runs `npm ci` against the committed `payload/package-lock.json`. See `src/payload.ts`.
