# stylelint-css-modules

> Extended ruleset for stylelint on CSS modules

Latest version **1.2.2** (published 2022-03-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install stylelint-css-modules
pnpm add stylelint-css-modules
yarn add stylelint-css-modules
bun add stylelint-css-modules
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2022-03-22 |
| First published | 2018-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Juan Carlos Medina |
| Maintainers | juanca |
| Keywords | stylelint, css modules |

## Links

- npm: https://www.npmjs.com/package/stylelint-css-modules
- Repository: https://github.com/juanca/stylelint-css-modules
- Homepage: https://github.com/juanca/stylelint-css-modules#readme
- Issues: https://github.com/juanca/stylelint-css-modules/issues
- npm.io page: https://npm.io/package/stylelint-css-modules

## Dependencies (1)

- [enhanced-resolve](https://npm.io/package/enhanced-resolve.md) ^4.3.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2022-03-22
- 1.2.1 — 2022-02-01
- 1.2.0-stylelint14-2 — 2022-02-01
- 1.2.0-stylelint14 — 2022-01-26
- 1.2.0-globals — 2020-08-22
- 1.2.0 — 2020-08-22
- 1.1.0 — 2020-07-11
- 0.9.0 — 2019-07-24
- 0.8.4 — 2019-07-12
- 0.8.3-interp — 2019-07-12
- 0.8.3 — 2019-03-23
- 0.8.2 — 2019-03-23
- 0.8.1 — 2019-03-23
- 0.8.0 — 2019-03-23
- 0.0.9 — 2018-10-24
- … 8 more at https://npm.io/package/stylelint-css-modules/versions

## README

# stylelint-css-modules

[![NPM version](http://img.shields.io/npm/v/stylelint-css-modules.svg)](https://www.npmjs.org/package/stylelint-css-modules)
[![CircleCI status](https://circleci.com/gh/juanca/stylelint-css-modules.svg?style=shield)](https://circleci.com/gh/juanca/stylelint-css-modules)

> Extended ruleset for stylelint on CSS modules

## Example usage

1. Install

```
npm install stylelint-css-modules --save-dev
```

2. Configure

```
plugins: [
  'stylelint-css-modules',
],
rules: {
  'css-modules/composed-class-names': true,
  'css-modules/css-variables': true,
},
```

3. Advanced configuration

The stylelint plugin uses `enhanced-resolve` to find referenced files.
Each rule can configure the resolver with a `resolve` object.
By default, this stylelint plugin is configured with:

```js
{
  resolve: {
    extensions: ['.css'],
  },
}
```

In order to find SASS files, add an additional extension:

```js
plugins: [
  'stylelint-css-modules',
],
rules: {
  'css-modules/composed-class-names': true,
  'css-modules/css-variables': [true, {
    resolve: {
      extensions: ['.css', '.scss'],
    },
  }],
},
```

In order to leverage the SASS `~` operator, add an additional module:

```js
plugins: [
  'stylelint-css-modules',
],
rules: {
  'css-modules/composed-class-names': true,
  'css-modules/css-variables': [true, {
    resolve: {
      modules: ['node_modules', 'app/src'],
    },
  }],
},
```

## Contributing

1. Fork
2. Install with a variant of Stylelint
  - `npm run test9`
  - `npm run test10`
  - `npm run test11`
  - `npm run test12`
  - `npm run test13`
3. Test: `npm test` (for running tests without installing Stylelint)
4. Submit a Pull Request

We are looking for simple and tested code.
A green build is a requirement.

## Ruleset

### css-modules/composed-class-names

Ensures each composed class name exists in the targeted file.

#### Good

```
.solo-class {}

.nested-root .intermediary-node .nested-child {}

.chained-root.chained-node.chained-child {}

.lots-of-compositions {
  composes: solo-class;
  composes: nested-root;
  composes: intermediary-node;
  composes: nested-child;
  composes: chained-root;
  composes: chained-node;
  composes: chained-child;
  composes: solo-class nested-child;
  composes: global from global;
  composes: baz from './baz.css';
}
```

where `baz.css`:

```
.baz {}
```


#### Bad

```
.lots-of-compositions {
  composes: does-not-exist;
  composes: does-not-exist from './baz.css';
}
```

where `baz.css`

```
.baz {}
```

### css-modules/css-variables

Ensures each CSS variable is defined locally or in some imported file unless it has a fallback.

#### Good

```
@import './baz.css';

:root {
  --some-var: 1;
}

.foo {
  margin: var(--some-var);
  padding: var(--baz-some-var);
  padding: var(--bar-some-var, 10px);
}
```

where `baz.css`:

```
:root {
  --bar-some-var: 1;
}
```

#### Bad

```
.foo {
  margin: var(--some-undefined-var);
  padding: var(--baz-some-var);
}
```

where `baz.css`:

```
:root {
  --bar-some-var: 1;
}
```

---
_Source: https://npm.io/package/stylelint-css-modules · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
