Skip to content

pre-commit: fix broken npm package files - #63

Merged
nizamial09 merged 1 commit into
mainfrom
fix-pre-commit
Jul 8, 2022
Merged

nizamial09 merged 1 commit into
mainfrom
fix-pre-commit

Conversation

@avanthakkar

Copy link
Copy Markdown
Contributor

Signed-off-by: Avan Thakkar [email protected]

Comment thread docker/ceph/ci/pre-commit.sh Outdated
source /docker/ci/sanity-checks.sh

NPM_PACKAGE_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB | grep -E "package(-lock){0,1}.json" -c)
NPM_PACKAGE_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB | grep -E "package(-lock){0,1}.json" | wc -l)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[shellcheck] reported by reviewdog 🐶
Consider using grep -c instead of grep|wc -l. SC2126

@nizamial09

Copy link
Copy Markdown
Member

I remember the bot was complaining about this in one of my previous PR. Could you explain how its broken? @avanthakkar

@avanthakkar

Copy link
Copy Markdown
Contributor Author

I remember the bot was complaining about this in one of my previous PR. Could you explain how its broken? @avanthakkar

  • NPM_PACKAGE_FILES=0

I remember the bot was complaining about this in one of my previous PR. Could you explain how its broken? @avanthakkar

Well with grep -c the script exits after NPM_PACKAGE_FILES=0, not sure why. So I think we can ignore bot suggestion here.

echo 'Running pre-commit hook...'
+ source /docker/ci/sanity-checks.sh
++ set -e
++ REPO_DIR=/ceph
++ [[ 1 == 1 ]]
++ [[ 17 -le 14 ]]
++ PYTHON_VERSION=3
++ TRANSLATION_FILE=src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf
++ return
++ git diff --cached --name-only --diff-filter=ACMRTUXB
++ grep -Ec 'package(-lock){0,1}.json'
+ NPM_PACKAGE_FILES=0

@epuertat

epuertat commented Jul 4, 2022

Copy link
Copy Markdown
Member

I remember the bot was complaining about this in one of my previous PR. Could you explain how its broken? @avanthakkar

  • NPM_PACKAGE_FILES=0

I remember the bot was complaining about this in one of my previous PR. Could you explain how its broken? @avanthakkar

Well with grep -c the script exits after NPM_PACKAGE_FILES=0, not sure why. So I think we can ignore bot suggestion here.

echo 'Running pre-commit hook...'
+ source /docker/ci/sanity-checks.sh
++ set -e
++ REPO_DIR=/ceph
++ [[ 1 == 1 ]]
++ [[ 17 -le 14 ]]
++ PYTHON_VERSION=3
++ TRANSLATION_FILE=src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf
++ return
++ git diff --cached --name-only --diff-filter=ACMRTUXB
++ grep -Ec 'package(-lock){0,1}.json'
+ NPM_PACKAGE_FILES=0

That's easy @avanthakkar. The set -e will basically exit the script if any the last command run in a line returns non-zero (success). Not surprisingly grep -c returns non-zero when it doesn't match anything. The way to fix that is ... | grep -c || true, which will always return 0.

@avanthakkar

Copy link
Copy Markdown
Contributor Author

I remember the bot was complaining about this in one of my previous PR. Could you explain how its broken? @avanthakkar

  • NPM_PACKAGE_FILES=0

I remember the bot was complaining about this in one of my previous PR. Could you explain how its broken? @avanthakkar

Well with grep -c the script exits after NPM_PACKAGE_FILES=0, not sure why. So I think we can ignore bot suggestion here.

echo 'Running pre-commit hook...'
+ source /docker/ci/sanity-checks.sh
++ set -e
++ REPO_DIR=/ceph
++ [[ 1 == 1 ]]
++ [[ 17 -le 14 ]]
++ PYTHON_VERSION=3
++ TRANSLATION_FILE=src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf
++ return
++ git diff --cached --name-only --diff-filter=ACMRTUXB
++ grep -Ec 'package(-lock){0,1}.json'
+ NPM_PACKAGE_FILES=0

That's easy @avanthakkar. The set -e will basically exit the script if any the last command run in a line returns non-zero (success). Not surprisingly grep -c returns non-zero when it doesn't match anything. The way to fix that is ... | grep -c || true, which will always return 0.

Ah yes, thanks!

Comment thread docker/ceph/ci/pre-commit.sh Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants