New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[qa] Added linting of JS and CSS #173 #202
Changes from 6 commits
3439473
6f4aed0
5a05b8c
4e5700d
2053e42
a4f9322
f44f3c2
b2ea06d
bd62a02
95833ae
005b4d1
eb489f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"unused": true, | ||
"esversion": 6, | ||
"curly": true, | ||
"strict": "global", | ||
"globals": { | ||
"django": true, | ||
"gettext": true, | ||
"ReconnectingWebSocket": true, | ||
"notificationApiHost": true, | ||
"notificationSound": true, | ||
"notificationSocket": true, | ||
"owNotifyObjectId": true, | ||
"owNotifyAppLabel": true, | ||
"owNotifyModelName": true, | ||
"owIsChangeForm": true, | ||
"getAbsoluteUrl": true, | ||
"dateTimeStampToDateTimeLocaleString": true | ||
}, | ||
"browser": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"rules": { | ||
"block-no-empty": null, | ||
"color-no-invalid-hex": true, | ||
"comment-empty-line-before": ["always", { | ||
"ignore": ["stylelint-commands", "after-comment"] | ||
}], | ||
"declaration-colon-space-after": "always", | ||
"indentation": [2, { | ||
"except": ["value"] | ||
}], | ||
"max-empty-lines": 4, | ||
"rule-empty-line-before": ["never-multi-line", { | ||
"except": ["first-nested"], | ||
"ignore": ["after-comment", "inside-block"] | ||
}], | ||
"unit-allowed-list": ["em", "rem", "%", "s", "px", "vh", "deg"] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,11 @@ show_help() { | |
printf " [--skip-isort]\n" | ||
printf " [--skip-black]\n" | ||
printf " [--skip-checkrst]\n" | ||
printf " [--csslinter]\n" | ||
printf " [--jslinter]\n" | ||
printf "\n" | ||
printf "Runs all checks for quality assurance. Unneeded checks may be skipped by passing --skip-<check-name> argument.\n" | ||
printf "csslinter and jslinter checks are skipped by default for backward compatibility. To run them pass --csslinter or --jslinter as an argument.\n" | ||
printf "\n" | ||
printf "General options:\n" | ||
printf " --help\t\t\t: Show this help text\n" | ||
|
@@ -37,6 +40,10 @@ show_help() { | |
printf " --skip-black\t\t\t: Skip black check\n" | ||
printf "ReStructuredText check options:\n" | ||
printf " --skip-checkrst\t\t: Skip ReStructuredText check\n" | ||
printf "CSSlinter check options:\n" | ||
printf " --csslinter\t\t\t: Runs stylelint check\n" | ||
printf "Jslinter check options:\n" | ||
printf " --jslinter\t\t\t: Runs jshint check\n" | ||
} | ||
|
||
echoerr() { echo "$@" 1>&2; } | ||
|
@@ -60,6 +67,45 @@ runcheckendline() { | |
fi | ||
} | ||
|
||
runstylelintcheck() { | ||
package='stylelint' | ||
if which node > /dev/null | ||
then | ||
if [ `npm list -g | grep -c $package` -eq 0 ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if I have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will check this and let you know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @atb00ker How should I use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @niteshsinha17 What do you mean? What's the challenge? Can you please elaborate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some version of |
||
echo "MODULE NOT FOUND: please install ${package}" | ||
else | ||
stylelint $(find . -type f -name "*.css") && | ||
echo "SUCCESS: Stylelint check successful!" || | ||
{ | ||
echoerr "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format?" | ||
FAILURE=1 | ||
} | ||
fi | ||
else | ||
echo "MODULE NOT FOUND: please install node and ${package}" | ||
fi | ||
} | ||
|
||
runjshintcheck() { | ||
package='jshint' | ||
if which node > /dev/null | ||
then | ||
if [ `npm list -g | grep -c $package` -eq 0 ]; then | ||
echo "MODULE NOT FOUND: please install ${package}" | ||
else | ||
jshint --verbose $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") && | ||
echo "SUCCESS: Jshint check successful!" || | ||
{ | ||
echoerr "ERROR: Jshint check failed! Hint: please follow js code conventions.\ | ||
visit: https://openwisp.io/docs/developer/contributing.html#javascript-code-conventions" | ||
FAILURE=1 | ||
} | ||
fi | ||
else | ||
echo "MODULE NOT FOUND: please install node and ${package}" | ||
fi | ||
} | ||
|
||
runcheckmigrations() { | ||
if [ "$MIGRATION_PATH" == "" ]; then | ||
echoerr "SKIPPED: No migration path specified!" | ||
|
@@ -151,6 +197,8 @@ SKIP_ISORT=false | |
SKIP_RSTCHECK=false | ||
SKIP_BLACK=false | ||
SKIP_CHECKCOMMIT=false | ||
SKIP_CSS_LINTER=true | ||
SKIP_JS_LINTER=true | ||
MIGRATION_PATH="" | ||
MIGRATIONS_TO_IGNORE="0" | ||
COMMIT_MESSAGE=$(git log $TRAVIS_PULL_REQUEST_SHA --format=%B -n 1) | ||
|
@@ -188,6 +236,12 @@ while [ "$1" != "" ]; do | |
--skip-checkcommit) | ||
SKIP_CHECKCOMMIT=true | ||
;; | ||
--csslinter) | ||
SKIP_CSS_LINTER=false | ||
;; | ||
--jslinter) | ||
SKIP_JS_LINTER=false | ||
;; | ||
--message) | ||
shift | ||
COMMIT_MESSAGE="$1" | ||
|
@@ -235,6 +289,14 @@ if ! $SKIP_FLAKE8; then | |
runflake8 | ||
fi | ||
|
||
if ! $SKIP_CSS_LINTER; then | ||
runstylelintcheck | ||
fi | ||
|
||
if ! $SKIP_JS_LINTER; then | ||
runjshintcheck | ||
fi | ||
|
||
if ! $SKIP_RSTCHECK; then | ||
runrstcheck | ||
fi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ set -e | |
|
||
isort . | ||
black -S . | ||
stylelint $(find . -type f -name "*.css") --fix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please ensure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shell script to automatically format Python code. It runs
isort
.black
andstylelint
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its better.
Shell script to automatically format Python and CSS code. It runs
isort
.black
andstylelint
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention that the command won't fail if
stylelint
is not installed but will skip instead.