Recess-based property sort order for Stylelint.
npx @tessl/cli install tessl/npm-stylelint-config-recess-order@7.2.0Stylelint Config Recess Order provides a shareable Stylelint configuration that enforces CSS property ordering based on the Recess property order methodology, originally used by Bootstrap. This configuration automatically sorts CSS properties in a consistent, opinionated order that follows established conventions from the Bootstrap ecosystem.
npm install --save-dev stylelint stylelint-order stylelint-config-recess-order// For extending in Stylelint configuration
module.exports = {
extends: ['stylelint-config-recess-order'],
// ... other config
};For custom configuration:
const propertyGroups = require('stylelint-config-recess-order/groups');ES Modules:
import config from 'stylelint-config-recess-order';
import propertyGroups from 'stylelint-config-recess-order/groups';// stylelint.config.js
module.exports = {
extends: ['stylelint-config-recess-order'],
rules: {
// Add overrides and additional rules here
},
};This configuration will automatically enforce property ordering in CSS files. Properties will be sorted according to Recess methodology:
/* Before: Properties in any order */
div {
background-color: slategray;
box-sizing: border-box;
flex: 1 1 auto;
position: relative;
}
/* After: Properties sorted by Recess order */
div {
position: relative;
box-sizing: border-box;
flex: 1 1 auto;
background-color: slategray;
}Stylelint Config Recess Order is built around two main components:
index.js): A pre-configured Stylelint configuration that applies the stylelint-order plugin with Recess-based property ordering rulesgroups.js): A structured dataset containing 39 distinct property groups, each organizing related CSS properties according to their functional purpose and the Recess methodologyThe package follows the Recess property ordering methodology, originally developed by Twitter and adopted by Bootstrap, which organizes CSS properties by their impact on layout and visual rendering.
Ready-to-use Stylelint configuration with Recess-based property ordering.
/**
* Default Stylelint configuration object with stylelint-order plugin
* and Recess-based property ordering rules
*/
const config: StylelintConfig;
interface StylelintConfig {
/** Array of plugin names required for this configuration */
plugins: ['stylelint-order'];
/** Stylelint rules configuration object */
rules: {
'order/properties-order': PropertyGroup[];
};
}Usage:
// Extend the default configuration
module.exports = {
extends: ['stylelint-config-recess-order'],
rules: {
// Override or add additional rules
'color-hex-case': 'lower',
},
};Array of CSS property groups organized by functionality for custom configuration.
/**
* Array of property groups defining Recess-based CSS property ordering
* Each group contains related CSS properties that should be ordered together
*/
const propertyGroups: PropertyGroup[];
interface PropertyGroup {
/** Array of CSS property names in this group */
properties: string[];
}Property Group Categories:
The property groups array contains 39 distinct groups organized by CSS functionality:
composesallposition, inset, top, right, bottom, left, z-index, float, clearbox-sizing, display, visibilityflex, flex-grow, flex-shrink, flex-basis, etc.grid, grid-area, grid-template, etc.gap, align-content, justify-content, etc.orderwidth, height, min-width, max-width, etc.padding, margin and their logical propertiescontain, container, content-visibilityoverflow, text-overflow, line-clamp, etc.overscroll-behavior propertiesfont, font-family, font-size, etc.line-height, vertical-align, etc.color, webkit text fill propertiestext-align, text-transform, white-space, etc.text-decoration, text-shadow, etc.src, font-display, unicode-range, etc.appearance, cursor, outline, etc.color-schemetable-layout, border-collapse, etc.content, quoteslist-style, counter-reset, etc.scroll-snap-type, scroll-padding, etc.scrollbar-color, scrollbar-widthobject-fit, image-rendering, etc.background, border and all related propertiesmix-blend-mode, isolation, opacityfilter, backdrop-filterclip, mask propertiesshape-outside, shape-margin, etc.direction, writing-mode, etc.fill, stroke, SVG-specific propertiestransform, transform-origin, etc.transition and related propertiesanimation and related propertieswill-changebreak-before, widows, orphansUsage:
// Custom configuration with additional options
const propertyGroups = require('stylelint-config-recess-order/groups');
module.exports = {
extends: [], // Do not extend the config here
rules: {
// Configure the rule manually with custom options
'order/properties-order': propertyGroups.map((group) => ({
...group,
emptyLineBefore: 'always',
noEmptyLineBetween: true,
})),
},
};The property groups can be customized with additional stylelint-order options:
const propertyGroups = require('stylelint-config-recess-order/groups');
module.exports = {
rules: {
'order/properties-order': propertyGroups.map((group) => ({
...group,
// Add empty line before each group
emptyLineBefore: 'always',
// No empty lines between properties in the same group
noEmptyLineBetween: true,
})),
},
};This configuration can be combined with other Stylelint configurations:
module.exports = {
extends: [
'stylelint-config-standard',
'stylelint-config-recess-order',
],
rules: {
// Additional rules or overrides
'property-no-vendor-prefix': null,
},
};This package requires the following peer dependencies to be installed:
order/properties-order ruleInstall all dependencies:
npm install --save-dev stylelint stylelint-order stylelint-config-recess-orderWhen properties are not in the correct order, Stylelint will report errors like:
Expected "box-sizing" to come before "background-color" (order/properties-order)These errors can be automatically fixed using Stylelint's --fix option:
npx stylelint "**/*.css" --fix/**
* Type definition for property group objects
*/
interface PropertyGroup {
/** Array of CSS property names that belong to this group */
properties: string[];
}
/**
* Type definition for the main Stylelint configuration
*/
interface StylelintConfig {
/** Array of plugin names required by this configuration */
plugins: string[];
/** Object containing Stylelint rule configurations */
rules: {
[ruleName: string]: any;
};
}