Skip to content

Commit aebe6a9

Browse files
[change] Switched to prettier for CSS/JS linting #367
Closes #367 --------- Co-authored-by: Federico Capoano <[email protected]>
1 parent 1103df5 commit aebe6a9

File tree

16 files changed

+398
-400
lines changed

16 files changed

+398
-400
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: |
4848
pip install -U pip wheel setuptools
4949
pip install -U -r requirements-test.txt
50-
sudo npm install -g jshint stylelint
50+
sudo npm install -g prettier
5151
pip install -e .[qa,rest,selenium]
5252
pip install ${{ matrix.django-version }}
5353

.jshintrc

Lines changed: 0 additions & 23 deletions
This file was deleted.

.stylelintrc.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/developer/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Install development dependencies:
5252
5353
pip install -e .[qa,rest]
5454
pip install -r requirements-test.txt
55-
sudo npm install -g jshint stylelint
55+
sudo npm install -g prettier
5656
5757
Set up the git *pre-push* hook to run tests and QA checks automatically
5858
right before the git push action, so that if anything fails the push

docs/developer/qa-checks.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ It runs ``isort`` and ``black`` to format python code (these two
2020
dependencies are required and installed automatically when running ``pip
2121
install openwisp-utils[qa]``).
2222

23-
The ``stylelint`` and ``jshint`` programs are used to perform style checks
24-
on CSS and JS code respectively, but they are optional: if ``stylelint``
25-
and/or ``jshint`` are not installed, the check(s) will be skipped.
23+
The ``prettier`` programs is used to perform style checks on CSS and JS
24+
code, but it is optional: if ``prettier`` is not installed, the check(s)
25+
will be skipped.
2626

2727
``openwisp-qa-check``
2828
---------------------
@@ -38,9 +38,9 @@ Shell script to run the following quality assurance checks:
3838
- ``isort`` - Sorts python imports alphabetically, and separated into
3939
sections
4040
- ``black`` - Formats python code using a common standard
41-
- ``csslinter`` - Formats and checks CSS code using stylelint common
41+
- ``csslinter`` - Formats and checks CSS code using prettier common
4242
standard
43-
- ``jslinter`` - Checks Javascript code using jshint common standard
43+
- ``jslinter`` - Checks Javascript code using prettier common standard
4444

4545
If a check requires a flag, it can be passed forward in the same way.
4646

openwisp-qa-check

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ show_help() {
4141
printf "ReStructuredText check options:\n"
4242
printf " --skip-checkrst\t\t: Skip ReStructuredText check\n"
4343
printf "CSSlinter check options:\n"
44-
printf " --csslinter\t\t\t: Runs stylelint check\n"
44+
printf " --csslinter\t\t\t: Runs prettier check on css files\n"
4545
printf "Jslinter check options:\n"
46-
printf " --jslinter\t\t\t: Runs jshint check\n"
46+
printf " --jslinter\t\t\t: Runs prettier check on javascript files\n"
4747
}
4848

4949
echoerr() { echo "$@" 1>&2; }
@@ -67,13 +67,13 @@ runcheckendline() {
6767
fi
6868
}
6969

70-
runstylelintcheck() {
71-
package='stylelint'
72-
if which stylelint > /dev/null; then
73-
stylelint verbose $(find . -type f -name "*.css") &&
74-
echo "SUCCESS: Stylelint check successful!" ||
70+
runcssprettiercheck() {
71+
package='prettier'
72+
if which prettier > /dev/null; then
73+
prettier $(find . -type f -name "*.css") --check &&
74+
echo "SUCCESS: Prettier check successful!" ||
7575
{
76-
echoerr "ERROR: Stylelint check failed! Hint: did you forget to run openwisp-qa-format?"
76+
echoerr "ERROR: Prettier check failed! Hint: did you forget to run openwisp-qa-format?"
7777
FAILURE=1
7878
}
7979
else
@@ -82,13 +82,13 @@ runstylelintcheck() {
8282
fi
8383
}
8484

85-
runjshintcheck() {
86-
package='jshint'
87-
if which jshint > /dev/null; then
88-
jshint --verbose $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") &&
89-
echo "SUCCESS: Jshint check successful!" ||
85+
runjsprettiercheck() {
86+
package='prettier'
87+
if which prettier > /dev/null; then
88+
prettier $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") --check &&
89+
echo "SUCCESS: Prettier check successful!" ||
9090
{
91-
echoerr "ERROR: Jshint check failed! Hint: please follow js code conventions. Visit: https://openwisp.io/docs/developer/contributing.html#javascript-code-conventions"
91+
echoerr "ERROR: Prettier check failed! Hint: please follow js code conventions. Visit: https://openwisp.io/docs/developer/contributing.html#javascript-code-conventions"
9292
FAILURE=1
9393
}
9494
else
@@ -283,11 +283,11 @@ if ! $SKIP_FLAKE8; then
283283
fi
284284

285285
if ! $SKIP_CSS_LINTER; then
286-
runstylelintcheck
286+
runcssprettiercheck
287287
fi
288288

289289
if ! $SKIP_JS_LINTER; then
290-
runjshintcheck
290+
runjsprettiercheck
291291
fi
292292

293293
if ! $SKIP_RSTCHECK; then

openwisp-qa-format

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ isort .
55
black -S .
66
docstrfmt --no-docstring-trailing-line --ignore-cache --line-length 74 .
77

8-
if which stylelint > /dev/null; then
9-
stylelint $(find . -type f -name "*.css") --fix
8+
if which prettier > /dev/null; then
9+
prettier $(find . -type f -name "*.css") --write
10+
prettier $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") --write
1011
else
11-
echo "SKIPPED CSS FILES: Please install stylelint"
12+
echo "SKIPPED CSS FILES: Please install prettier"
1213
fi
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#id_user_consented {
2-
float: left;
3-
margin-right: 8px;
4-
vertical-align: top;
5-
margin-bottom: 0px;
2+
float: left;
3+
margin-right: 8px;
4+
vertical-align: top;
5+
margin-bottom: 0px;
66
}
7-
#id_metric_collection_consent_form > span.helptext{
8-
display: block;
9-
margin-top: 8px;
7+
#id_metric_collection_consent_form > span.helptext {
8+
display: block;
9+
margin-top: 8px;
1010
}

0 commit comments

Comments
 (0)