A Prettier plugin to sort CSS or SCSS properties. Using postcss-scss for parse source.
Following the Prettier plugin guidelines, this package depends on Prettier as a peer dependency:
npm install prettier-grundy-scss-order --save-dev
To enable the plugin use the Prettier API, CLI or configuration file. For example using the JS configuration:
{
"plugins": ["prettier-grundy-scss-order"]
}This plugin adds next configurable keys to Prettier:
| Option Name | Description | Default value |
|---|---|---|
grundyScssSorterGroupsOrder | array of groups in needed order |
|
grundyScssSorterWithRoot | flag if need sort on root level |
true |
grundyScssSorterSplitGroup | flag if need split groups in result with empty line |
false |
grundyScssSorterGroups | define custom groups to sort, extend default groups | |
grundyScssSorterPreset |
predefined properties, for example: csscomb |
Available presets for migrate from other plugins
| Preset | Description |
|---|---|
preset for migrate from csscomb sorter with default preset | |
| csscomb-yandex |
preset for migrate from csscomb sorter with yandex preset |
| csscomb-zen |
preset for migrate from csscomb sorter with zen preset |
@use - scss use statements@mixin - scss @mixin statements--variable - css custom properties:$variable - scss variablesdecl - any css properties: color: ..., backgroud: ..., etc.@include - scss @include statementsrule - css selector rule: .class {...}, tag{...}, #id{...}, etc.@if - scss @if with optionally @else/@else if statements@media - css @media statements@supports - css @supports statementsWith option grundyScssSorterGroups possibly add custom groups satisfying the criterias
example, add group @font - in this group select all properties started with font: font, font-size, etc.
"{\"@font\": { \"startsWith\": \"font\" }}";Then possibly use this group in grundyScssSorterGroupsOrder:
["--variable", "$variable", "@font", "decl"];To define custom group available next criterias
startsWith - check name starts with parameter
oneOf - check name one of array string
type - check node type one of predefined type
| Criteria | Sample | Description | Applied to |
|---|---|---|---|
| type |
|
select "@use" statements |
|
| startsWith |
|
select statements starts with "font" |
|
| oneOf |
|
select statements with name that exactly matches one of the array elements |
|