> ## Documentation Index
> Fetch the complete documentation index at: https://aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# @aspect_rules_lint//lint:stylelint.bzl

> Bazel rules_lint Stylelint integration: lint_stylelint_aspect to run Stylelint as a Bazel aspect against CSS sources tagged for linting.

Documentation for [@aspect\_rules\_lint@v2.1.0](https://registry.bazel.build/modules/aspect_rules_lint/2.1.0) --  [View source](https://github.com/aspect-build/rules_lint/blob/v2.1.0/lint/stylelint.bzl)

Configures [Stylelint](https://stylelint.io/) to run as a Bazel aspect

First, all CSS sources must be the srcs of some Bazel rule.
You can use a `filegroup` with `lint-with-stylelint` in the `tags`:

```python theme={null}
filegroup(
    name = "css",
    srcs = glob(["*.css"]),
    tags = ["lint-with-stylelint"],
)
```

See the `filegroup_tags` and `rule_kinds` attributes below to customize this behavior.

## Usage

Add `stylelint` as a `devDependency` in your `package.json`, and declare a binary target for Bazel to execute it.

For example in `tools/lint/BUILD.bazel`:

```python theme={null}
load("@npm//:stylelint/package_json.bzl", stylelint_bin = "bin")
stylelint_bin.stylelint_binary(name = "stylelint")
```

Then declare the linter aspect, typically in `tools/lint/linters.bzl`:

```python theme={null}
load("@aspect_rules_lint//lint:stylelint.bzl", "lint_stylelint_aspect")
stylelint = lint_stylelint_aspect(
    binary = Label("//tools/lint:stylelint"),
    config = Label("//:stylelintrc"),
)
```

Finally, register the aspect with your linting workflow, such as in `.aspect/cli/config.yaml` for `aspect lint`.

## Function: `stylelint_action`

Spawn stylelint as a Bazel action

### Parameters

**ctx** `unknown` *required*

an action context OR aspect context

**executable** `unknown` *required*

struct with an \_stylelint field

**srcs** `unknown` *required*

list of file objects to lint

**stderr** `unknown` *required*

output file containing the stderr or --output-file of stylelint

**exit\_code** `unknown` (default: None)

output file containing the exit code of stylelint.
If None, then fail the build when stylelint exits non-zero.
Exit codes may be:
1 - fatal error
2 - lint problem
64 - invalid CLI usage
78 - invalid configuration file

**env** `unknown` (default: \{})

environment variables for stylelint

**options** `unknown` (default: \[])

additional command-line arguments

**format** `unknown` (default: None)

a formatter to add as a command line argument

**patch** `unknown` (default: None)

output file for patch (optional). If provided, uses run\_patcher instead of run\_shell.

## Function: `lint_stylelint_aspect`

A factory function to create a linter aspect.

### Parameters

**binary** `unknown` *required*

the stylelint binary, typically a rule like

```
load("@npm//:stylelint/package_json.bzl", stylelint_bin = "bin")
stylelint_bin.stylelint_binary(name = "stylelint")
```

**config** `unknown` *required*

label(s) of the stylelint config file

**rule\_kinds** `unknown` (default: \["css\_library"])

which [kinds](https://bazel.build/query/language#kind) of rules should be visited by the aspect

**filegroup\_tags** `unknown` (default: \["lint-with-stylelint"])

which tags on a `filegroup` indicate that it should be visited by the aspect


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.