Skip to content
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

Merged
merged 12 commits into from Jun 8, 2021

Conversation

niteshsinha17
Copy link
Member

It also formats css files when we run run-qa-format
closes #173

@niteshsinha17 niteshsinha17 self-assigned this May 27, 2021
@niteshsinha17 niteshsinha17 added this to In progress in [GSoC 2021] Modern UI/UX via automation May 27, 2021
@niteshsinha17 niteshsinha17 moved this from In progress to Needs review in [GSoC 2021] Modern UI/UX May 27, 2021
Copy link
Member

@atb00ker atb00ker left a 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! 😄

@@ -60,6 +60,16 @@ runcheckendline() {
fi
}

runstylelintcheck() {
echo "RUNNING: Stylelint checks"
stylelint -f verbose $(find . -type f -name "*.css")
Copy link
Member

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
    }
}


runjshintcheck() {
echo "RUNNING: jshint checks"
jshint --verbose $(find . -type f -name "*.js" -a ! -path "*vendor/*.js")
Copy link
Member

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 atb00ker moved this from Needs review to In progress in [GSoC 2021] Modern UI/UX May 31, 2021
@niteshsinha17
Copy link
Member Author

@atb00ker I have one doubt. I am writing these test at two placed openwisp-qa-checks and run-qa-checks. If I do not write it in run-qa-checks it never runs on run-qa-checks command but other tests run properly. Am I missing something?

@atb00ker
Copy link
Member

You need to do pip install .[qa,rest] to update the script.

Copy link
Member

@nemesifier nemesifier left a 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

SKIP_STYLELINT=true
;;
--skip-jshint)
SKIP_JSHINT=true
Copy link
Member

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.

Copy link
Member Author

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.

@niteshsinha17 niteshsinha17 force-pushed the issues/173-add-linting-of-js-and-css branch 2 times, most recently from a10b212 to 24b028d Compare June 2, 2021 07:46
@@ -2,7 +2,10 @@
set -e

qa-checks () {
openwisp-qa-check --migration-path "./tests/test_project/migrations"
openwisp-qa-check \
Copy link
Member Author

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

Copy link
Member

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

@niteshsinha17 niteshsinha17 moved this from In progress to Needs review in [GSoC 2021] Modern UI/UX Jun 2, 2021
Copy link
Member

@atb00ker atb00ker left a 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.

echoerr "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format?"
FAILURE=1
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintended space! 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this resolved?

Copy link
Member

@nemesifier nemesifier left a 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 \
Copy link
Member

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

@@ -60,6 +68,26 @@ runcheckendline() {
fi
}

runstylelintcheck() {
stylelint $(find . -type f -name "*.css") &&
Copy link
Member

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.

Copy link
Member Author

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

echoerr "ERROR: Stylelint check failed! Hint: did you forget running openwisp-qa-format?"
FAILURE=1
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this resolved?

}

runjshintcheck() {
jshint --verbose $(find . -type f -name "*.js" -a ! -path "*vendor/*.js") &&
Copy link
Member

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.

Copy link
Member Author

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

@atb00ker atb00ker moved this from Needs review to In progress in [GSoC 2021] Modern UI/UX Jun 2, 2021
@niteshsinha17 niteshsinha17 moved this from In progress to Needs review in [GSoC 2021] Modern UI/UX Jun 3, 2021
Copy link
Member

@atb00ker atb00ker left a 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
Comment on lines 816 to 817
Shell script to automatically format Python code. It runs ``isort`` and ``black``.
It also runs ``stylelint`` to format CSS code.
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

package='stylelint'
if which node > /dev/null
then
if [ `npm list -g | grep -c $package` -eq 0 ]; then
Copy link
Member

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!

Copy link
Member Author

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

Copy link
Member Author

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?

Copy link
Member

@atb00ker atb00ker Jun 5, 2021

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.

Copy link
Member Author

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

Copy link
Member

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. 😄

@atb00ker atb00ker moved this from Needs review to In progress in [GSoC 2021] Modern UI/UX Jun 4, 2021
@niteshsinha17 niteshsinha17 force-pushed the issues/173-add-linting-of-js-and-css branch from 836f8e8 to a4f9322 Compare June 4, 2021 16:31
@nemesifier nemesifier changed the base branch from dev to master June 6, 2021 23:03
Copy link
Member

@nemesifier nemesifier left a 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.

@@ -3,3 +3,4 @@ set -e

isort .
black -S .
stylelint $(find . -type f -name "*.css") --fix
Copy link
Member

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

@coveralls
Copy link

coveralls commented Jun 7, 2021

Coverage Status

Coverage remained the same at 99.295% when pulling eb489f1 on issues/173-add-linting-of-js-and-css into f32eb09 on master.

@niteshsinha17
Copy link
Member Author

@nemesisdesign and @atb00ker Updated this PR once again.
Changes made

  1. This time added some more rules in stylelint
  2. I am failing checks when stylelint and jshint are not installed.
  3. Made changes requested by you last time.

Its ready now

@niteshsinha17 niteshsinha17 moved this from In progress to Needs review in [GSoC 2021] Modern UI/UX Jun 7, 2021
Copy link
Member

@atb00ker atb00ker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 😄

stylelint $(find . -type f -name "*.css") --fix
else
echo "MODULE NOT FOUND: Please install stylelint"
exit 1
Copy link
Member

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
Comment on lines 816 to 817
Shell script to automatically format Python code. It runs ``isort`` and ``black``.
It also runs ``stylelint`` to format CSS code.
Copy link
Member

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.

@niteshsinha17
Copy link
Member Author

niteshsinha17 commented Jun 8, 2021

@nemesisdesign I have fixed them. I will be more careful next time.

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."
Copy link
Member Author

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."

@nemesifier nemesifier merged commit 1ae1682 into master Jun 8, 2021
[GSoC 2021] Modern UI/UX automation moved this from Needs review to Done Jun 8, 2021
@nemesifier nemesifier deleted the issues/173-add-linting-of-js-and-css branch June 8, 2021 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[QA] Add linting of JS and CSS
4 participants