Answer the question
In order to leave comments, you need to log in
How to automatically improve CSS style before commit?
I have a React project. To be precise, I created it from a template gatsby-starter-default
.
Changed files are run through Prettier
. I did it with lint-staged
, husky
and pretty-quick
:
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
CSScombJS
. Husky
with Prettier
? Is there a separate plugin for Husky
?#!/usr/bin/env bash
PATCH_FILE="working-tree.patch"
NPM_BIN="./node_modules/.bin"
function cleanup {
exit_code=$?
if [ -f "$PATCH_FILE" ]; then
patch -p0 < "$PATCH_FILE"
rm "$PATCH_FILE"
fi
exit $exit_code
}
#Прибираемся при выходе из скрипта
trap cleanup EXIT SIGINT SIGHUP
# Создаем патч
git diff > "$PATCH_FILE" --no-prefix
# Сбрасываем не застэйдженный изменения
git checkout -- .
# получаем список файлов в которых были изменения, которые мы хотим закоммитить
git_cached_files=$(git diff --cached --name-only --diff-filter=ACMR | xargs echo)
if [ "$git_cached_files" ]; then
#Собственно натравливаем CSScomb.js
$NPM_BIN/csscomb -v -l $git_cached_files || exit 1
fi
Answer the question
In order to leave comments, you need to log in
In my projects it's done like this:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"!(_*).scss": [
"csscomb --tty-mode",
"stylelint --fix --color --config ./.stylelintrc",
"git add"
],
"*.js": [
"eslint --fix --color",
"prettier --write",
"git add"
]
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question