5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sass書いてる時に、プロパティをソートしたい

Last updated at Posted at 2015-11-01

css書いていると、どんどんスパゲッティになっていくんですが、
少しでも機械的に整理しようということで
プロパティをソートさせます。

style.sass
.class 
  text-align: center
  margin-top: 10px
  padding: 5px
style.sass
.class 
  margin-top: 10px
  padding: 5px
  text-align: center

単純なcssならcsscombというのがあるんですが、sassの独特の書式でソートしてくれるのは
なかなかありませんでしたが、
https://www.npmjs.com/package/sort-sass
npmのsort-sassを利用すると、簡単にできました。

npm install -g sort-sass
sortsass style.sass

を実行すると、ソートされた結果が同一ファイル名で保存されます。
上書きされたくないなら

cp -a style.sass temp.sass && sortsass temp.sass

で結果を見てみたらいいと思います。

結果に満足であれば、
gruntなり、emacsのbefore-save-hookなりに仕込めばいいと思います。

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?