Socket
Socket
Sign inDemoInstall

stylelint-order

Package Overview
Dependencies
112
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylelint-order

A collection of order related linting rules for Stylelint.


Version published
Maintainers
1
Weekly downloads
1,506,309
decreased by-2.31%

Weekly downloads

Package description

What is stylelint-order?

The stylelint-order npm package is a plugin for stylelint that provides order related linting rules for CSS properties within declaration blocks. It helps in enforcing a consistent order for CSS properties, which can make code easier to read and maintain.

What are stylelint-order's main functionalities?

Specifying the order of content within declaration blocks

This feature allows you to define the order in which different types of content within a declaration block should appear. For example, you can specify that custom properties should be declared before any other declarations.

{
  "plugins": [
    "stylelint-order"
  ],
  "rules": {
    "order/order": [
      "custom-properties",
      "declarations"
    ],
    "order/properties-order": [
      "position",
      "top",
      "right",
      "bottom",
      "left"
    ]
  }
}

Specifying the order of properties within declaration blocks

This feature allows you to define a specific order for CSS properties within a declaration block. You can list the properties in the order you want them to be linted. This can be a custom order or alphabetical order.

{
  "plugins": [
    "stylelint-order"
  ],
  "rules": {
    "order/properties-order": [
      "position",
      "z-index",
      "top",
      "right",
      "bottom",
      "left"
    ],
    "order/properties-alphabetical-order": {}
  }
}

Grouping and separating properties

This feature allows you to group related properties together and enforce an empty line before the group or between groups. This can improve readability and organization of CSS rules.

{
  "plugins": [
    "stylelint-order"
  ],
  "rules": {
    "order/properties-order": [
      [
        "position",
        "z-index"
      ],
      {
        "emptyLineBefore": "always",
        "properties": [
          "color",
          "font-size",
          "font-weight"
        ]
      }
    ]
  }
}

Other packages similar to stylelint-order

Readme

Source

stylelint-order

npm version npm downloads last month

A plugin pack of order-related linting rules for Stylelint. Every rule supports autofixing (stylelint --fix).

Installation

  1. If you haven't, install Stylelint:
npm install stylelint --save-dev
  1. Install stylelint-order:
npm install stylelint-order --save-dev

Usage

Add stylelint-order to your Stylelint config plugins array, then add rules you need to the rules list. All rules from stylelint-order need to be namespaced with order.

{
	"plugins": [
		"stylelint-order"
	],
	"rules": {
		"order/order": [
			"custom-properties",
			"declarations"
		],
		"order/properties-order": [
			"width",
			"height"
		]
	}
}

Rules

Autofixing

Every rule supports autofixing with stylelint --fix. postcss-sorting is used internally for order autofixing.

Automatic sorting has some limitations that are described for every rule, if any. Please, take a look at how comments are handled by postcss-sorting.

CSS-in-JS styles with template interpolation could be ignored by autofixing to avoid style corruption.

Autofixing in Less syntax may work but isn't officially supported.

Example configs

All these configs have properties-order configured with logical properties groups:

Thanks

properties-order and properties-alphabetical-order code and README were based on the declaration-block-properties-order rule which was a core rule prior to Stylelint 8.0.0.

Keywords

FAQs

Last updated on 08 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc