stylelint-semantic-groups
Opinionated group based SCSS property ordering for better maintainability
and perception
.
📖 Theory behind: Harry Potter and the Order of CSS
Usage
- install required packages
yarn add stylelint-order stylelint-semantic-groups
Recommended configuration
const { propertyOrdering, selectorOrdering } = require('stylelint-semantic-groups');
module.exports = {
plugins: ['stylelint-order'],
rules: {
'order/order': selectorOrdering,
'order/properties-order': propertyOrdering,
},
};
Minimal configuration
const { propertyOrdering } = require('stylelint-semantic-groups');
module.exports = {
plugins: ['stylelint-order'],
rules: {
'order/order': [
'custom-properties',
'dollar-variables',
'declarations',
'at-rules',
'rules',
],
'order/properties-order': propertyOrdering,
},
};
Stylelint config that sorts related property declarations by grouping together following the order:
- (optional) SCSS/CSS variables, handled by
order/order
- Layout Positioning - Element bound properties (in terms of BEM) such as
grid-area
. Note: in the current implementation it is mostly about grids and grids only.
- Positioning
- Box Model
- Typography
- Visual
- Misc
- Animation
- (optional) at-rules, handled by
order/order
- (optional) nested rules, handled by
order/order
.declaration-order {
--color: #fff;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 10;
display: block;
float: right;
width: 100px;
height: 100px;
margin: 10px;
padding: 10px;
color: #888;
font: normal 16px Helvetica, sans-serif;
line-height: 1.3;
text-align: center;
background-color: #eee;
border: 1px solid #888;
border-radius: 4px;
opacity: 1;
transition: all 1s;
user-select: none;
}
See also
Licence
MIT