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
Conversation
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 test my recommendations in success case and fail case.
This openwisp-qa-check will never fail our CI; hence marking as request changes! 😄
openwisp-qa-check
Outdated
@@ -60,6 +60,16 @@ runcheckendline() { | |||
fi | |||
} | |||
|
|||
runstylelintcheck() { | |||
echo "RUNNING: Stylelint checks" | |||
stylelint -f verbose $(find . -type f -name "*.css") |
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 this command would spit a lot of unnecessary information even when the test passes.
To avoid it, checkout the how the other functions are suppressing output on success.
Example:
runstylelintcheck() {
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
}
}
openwisp-qa-check
Outdated
|
||
runjshintcheck() { | ||
echo "RUNNING: jshint checks" | ||
jshint --verbose $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") |
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.
Just like above it will give a lot of output even when the test passes.
runjshintcheck() {
jshint $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") &&
echo "SUCCESS: Stylelint check successful!" ||
{
echoerr "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format?"
FAILURE=1
}
}
@atb00ker I have one doubt. I am writing these test at two placed |
You need to do |
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.
This commit shouldn't be here: 2675cff
openwisp-qa-check
Outdated
SKIP_STYLELINT=true | ||
;; | ||
--skip-jshint) | ||
SKIP_JSHINT=true |
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.
Great to see that we are adding this in this script! Will be great for reusability.
But we definitely should not do it this way @niteshsinha17 @atb00ker, because it will cause some existing builds to fail because these linters may not be installed.
We must introduce this feature in a backward compatible way, so either by default these linters should not run (the options could be something like --css
and --js
to activate the respective linters) or before running the shell script should verify the availability of the linter program and skip if it's not present.
Moreover, we'll have to update the show_help
function above in this file and the README of the module to mention these options.
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.
You are right. I was also thinking about this.
a10b212
to
24b028d
Compare
@@ -2,7 +2,10 @@ | |||
set -e | |||
|
|||
qa-checks () { | |||
openwisp-qa-check --migration-path "./tests/test_project/migrations" | |||
openwisp-qa-check \ |
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.
@nemesisdesign @atb00ker Its ready for review. We will need to add css and js test for each module like this to run them in CI.
We can document about this addition here. http://openwisp.io/docs/developer/contributing.html#coding-style-conventions
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.
This section of the README needs to be updated: https://github.com/openwisp/openwisp-utils#openwisp-qa-check
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.
Tested, LGTM. 😄
I just realized.
The optoins --stylelint
& --jshint
describe much better what's going to run.
I wouldn't be able to guess what --css
and --js
are going to do.
openwisp-qa-check
Outdated
echoerr "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format?" | ||
FAILURE=1 | ||
} | ||
|
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.
Unintended space! 😄
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.
is this resolved?
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.
Still not ready, see below.
I just realized.
The optoins--stylelint
&--jshint
describe much better what's going to run.
I wouldn't be able to guess what--css
and--js
are going to do.
@niteshsinha17 what do you think about this suggestion? I'm fine with both nomenclatures.
The advantage of using css
and js
is that in the future we change the underlying linting library, we don't need to change the flag name.
Maybe we can use csslinter
and jslinter
to make it extra clear?
@@ -2,7 +2,10 @@ | |||
set -e | |||
|
|||
qa-checks () { | |||
openwisp-qa-check --migration-path "./tests/test_project/migrations" | |||
openwisp-qa-check \ |
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.
This section of the README needs to be updated: https://github.com/openwisp/openwisp-utils#openwisp-qa-check
openwisp-qa-check
Outdated
@@ -60,6 +68,26 @@ runcheckendline() { | |||
fi | |||
} | |||
|
|||
runstylelintcheck() { | |||
stylelint $(find . -type f -name "*.css") && |
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.
what happens if stylelint
is not installed? Can you make sure the function skips with a warning?
We need this to avoid breaking existing builds which are using the master version of this module.
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.
Added a check for this
openwisp-qa-check
Outdated
echoerr "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format?" | ||
FAILURE=1 | ||
} | ||
|
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.
is this resolved?
openwisp-qa-check
Outdated
} | ||
|
||
runjshintcheck() { | ||
jshint --verbose $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") && |
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.
what happens if jshint
is not installed? Can you make sure the function skips with a warning?
We need this to avoid breaking existing builds which are using the master version of this module.
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.
Added a check for this
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 it's close to merge! 😄
Two comments:
README.rst
Outdated
Shell script to automatically format Python code. It runs ``isort`` and ``black``. | ||
It also runs ``stylelint`` to format CSS code. |
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
and stylelint
.
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
and stylelint
.
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.
openwisp-qa-check
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
What if I have npm
? Does npm
come bundled with node
?
What do you think about using whereis stylelint
instead?
whereis
comes out of the box and works great in such situations!
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 will check this and let you know
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.
@atb00ker How should I use whereis
for this situation?
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.
@niteshsinha17 What do you mean? What's the challenge? Can you please elaborate?
P.S: You can also use which stylelint
& which jshint
.
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.
Yes which stylelint
will work fine.
I am not getting how to write it with whereis
I tried multiple ways but it was not working as expected. Can you please share exact syntax with whereis
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.
Some version of whereis stylelint | grep /stylelint
should work but don't worry about it, let's focus on which
only, whereis
is not a requirement. 😄
836f8e8
to
a4f9322
Compare
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.
The changes to the CSS are working fine, only one detail remaining to handle, see below.
openwisp-qa-format
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
please ensure stylelint
is available before trying to run it
@nemesisdesign and @atb00ker Updated this PR once again.
Its ready now |
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.
LGTM! 😄
openwisp-qa-format
Outdated
stylelint $(find . -type f -name "*.css") --fix | ||
else | ||
echo "MODULE NOT FOUND: Please install stylelint" | ||
exit 1 |
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.
once more time, I think this is wrong. Didn't we agree this feature must be backward compatible?
So why fail if styleling
is not installed? This command must not fail if stylelint is missing. It could simply say "The program "stylelint" is not installed, Skipping CSS auto-formatting." or something similar.
README.rst
Outdated
Shell script to automatically format Python code. It runs ``isort`` and ``black``. | ||
It also runs ``stylelint`` to format CSS code. |
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.
@nemesisdesign I have fixed them. I will be more careful next time. |
openwisp-qa-check
Outdated
stylelint verbose $(find . -type f -name "*.css") && | ||
echo "SUCCESS: Stylelint check successful!" || | ||
{ | ||
echoerr "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format? You may need some manual fixing." |
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 we can change it. to "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format? You may need to do some manual fixing."
It also formats
css
files when we runrun-qa-format
closes #173