# eslint-plugin-styled-components-order

> ESLint rules for consistently ordering CSS declarations in styled-components templates.

Latest version **2.0.2** (published 2026-09-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-styled-components-order
pnpm add eslint-plugin-styled-components-order
yarn add eslint-plugin-styled-components-order
bun add eslint-plugin-styled-components-order
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2026-09-23 |
| First published | 2023-08-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=20.19.0 |
| Dependencies | 1 |
| Unpacked size | 31.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | swiftwella |
| Maintainers | swiftwella |
| Keywords | eslint, eslintplugin, eslint-plugin, styled-components, css, sorting |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-styled-components-order
- Repository: https://github.com/Swiftwella/eslint-plugin-styled-components-order
- Homepage: https://github.com/Swiftwella/eslint-plugin-styled-components-order#readme
- Issues: https://github.com/Swiftwella/eslint-plugin-styled-components-order/issues
- npm.io page: https://npm.io/package/eslint-plugin-styled-components-order

## Dependencies (1)

- [postcss](https://npm.io/package/postcss.md) ^8.5.28

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2026-09-23
- 2.0.1 — 2026-09-23
- 2.0.0 — 2026-09-23
- 1.0.3 — 2023-08-04
- 1.0.2 — 2023-08-04
- 1.0.1 — 2023-08-04
- 1.0.0 — 2023-08-04

## README

# eslint-plugin-styled-components-order

[![npm version](https://img.shields.io/npm/v/eslint-plugin-styled-components-order.svg)](https://www.npmjs.com/package/eslint-plugin-styled-components-order)
[![CI](https://github.com/Swiftwella/eslint-plugin-styled-components-order/actions/workflows/ci.yml/badge.svg)](https://github.com/Swiftwella/eslint-plugin-styled-components-order/actions/workflows/ci.yml)
[![license](https://img.shields.io/npm/l/eslint-plugin-styled-components-order.svg)](./LICENSE)

Automatically enforce a consistent order for CSS declarations inside
styled-components tagged templates. Both rules are autofixable and support
nested selectors, at-rules, interpolated values, the `css` helper, `.attrs()`,
intrinsic elements, and custom components.

## Requirements

- Node.js 20.19 or newer
- ESLint 8.57 or newer

## Installation

```sh
npm install --save-dev eslint eslint-plugin-styled-components-order
```

## Configuration

Choose one ordering strategy. The recommended preset uses alphabetical order.

### Flat config

```js
// eslint.config.js
const styledComponentsOrder = require("eslint-plugin-styled-components-order");

module.exports = [
  styledComponentsOrder.configs["flat/recommended"],
  // Or: styledComponentsOrder.configs["flat/concentric"],
];
```

To configure a rule directly:

```js
const styledComponentsOrder = require("eslint-plugin-styled-components-order");

module.exports = [
  {
    plugins: {
      "styled-components-order": styledComponentsOrder,
    },
    rules: {
      "styled-components-order/sort-declarations-alphabetically": "error",
    },
  },
];
```

### Legacy eslintrc

```json
{
  "extends": ["plugin:styled-components-order/recommended"]
}
```

For concentric ordering, use
`"plugin:styled-components-order/concentric"` instead.

## Rules

### `sort-declarations-alphabetically`

Sorts declarations by property name.

```js
const Button = styled.button`
  color: white;
  display: inline-flex;
  padding: 0.5rem 1rem;
`;
```

### `sort-declarations-concentrically`

Sorts declarations by structural impact, then from outside-in within the box
model. The order is: custom properties; generated content; positioning and
layout; display and visibility; clipping; animation; box model; backgrounds;
typography; interaction; and nested selectors or at-rules. Related property
families stay together, physical longhands use top-right-bottom-left order, and
unknown properties are placed last alphabetically.

```js
const Card = styled.article`
  --card-background: white;
  position: relative;
  display: grid;
  margin: 1rem;
  border: 1px solid;
  background: var(--card-background);
  color: black;
`;
```

Run ESLint with `--fix` to reorder declarations automatically:

```sh
npx eslint . --fix
```

## Supported syntax

```js
styled.div`...`;
styled(Component)`...`;
styled.div.attrs({ role: "button" })`...`;
css`...`;
```

Declarations inside nested selectors and block at-rules are sorted
independently. JavaScript interpolations are preserved exactly as written.
Templates containing invalid CSS are left untouched.

## Development

```sh
npm install
npm run check
```

The `check` command runs ESLint, the Node.js test suite, and Prettier's format
check. Use `npm run format` to apply formatting.

Commits must follow the [Conventional Commits](https://www.conventionalcommits.org/)
format. Validate a commit message with:

```sh
echo "feat: add a feature" | npm run commitlint
```

## License

[Apache-2.0](./LICENSE)

---
_Source: https://npm.io/package/eslint-plugin-styled-components-order · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
