hudochenkov / postcss-sorting

PostCSS plugin to keep rules and at-rules content in order.
MIT License
516 stars 30 forks source link

Support for alphabetical sort with specific properties before all #113

Closed damiaanh closed 1 year ago

damiaanh commented 1 year ago

I am using CSS Modules. For CSS Modules it is important that their custom composes property comes before all other properties. That said, I also want to use the alphabetical sort for all other properties.

current:

.container {
    width: 100%;
    align-self: flex-start;
    white-space: nowrap;
    overflow: hidden;
    composes: my_custom_rule;
    text-overflow: ellipsis;
}

expected:

.container {
    composes: my_custom_rule;
    align-self: flex-start;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

I tried the following but none seem to work:

    "postcssSorting.config": {
        "order": ["composes", "declarations"],
        "properties-order":  "alphabetical"
    }
    "postcssSorting.config": {
        "properties-order":  ["composes", "alphabetical"]
    }

Is this possible using postcss-sorting?

hudochenkov commented 1 year ago

This should work for this use case:

    "postcssSorting.config": {
        "properties-order":  ["composes"],
        "unspecified-properties-position": "bottomAlphabetical"
    }