Skip to content

Commit

Permalink
Merge branch 'S48-949-various-bugs'
Browse files Browse the repository at this point in the history
  • Loading branch information
stkec committed Dec 29, 2021
2 parents f6c5852 + 03100a0 commit 37cab8a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ Copy files and install npm packages:
```shell
warden env exec php-fpm chmod +x vendor/space48/magento2-code-quality/script/install.sh
warden env exec php-fpm ./vendor/space48/magento2-code-quality/script/install.sh
vendor/bin/grumphp git:init
```

Add git precommit hook:
```shell
chmod +x vendor/space48/magento2-code-quality/script/add-hook.sh
vendor/space48/magento2-code-quality/script/add-hook.sh
```

Create `.git` folder in warden:
Expand All @@ -133,7 +138,8 @@ linters-init: # init linters on local machine
warden env exec php-fpm chmod +x vendor/space48/magento2-code-quality/script/install.sh
warden env exec php-fpm ./vendor/space48/magento2-code-quality/script/install.sh
warden env exec php-fpm /bin/bash -c '[ -d .git ] || mkdir .git'
vendor/bin/grumphp git:init
chmod +x vendor/space48/magento2-code-quality/script/add-hook.sh
vendor/space48/magento2-code-quality/script/add-hook.sh

analyse: # analyses all code from starting commit hash to HEAD
git diff a000z999..HEAD | warden env run --rm php-fpm 'vendor/phpro/grumphp/bin/grumphp' run
Expand Down
9 changes: 9 additions & 0 deletions githooks/warden/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

[ -f vendor/phpro/grumphp/bin/grumphp ] || (echo "Code Quality tool not found" && exit 0);

# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false -c diff.noprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)

# Run GrumPHP
[ "$DIFF" == '' ] || (cd "./" && printf "%s\n" "${DIFF}" | warden env run --rm php-fpm 'vendor/phpro/grumphp/bin/grumphp' 'git:pre-commit' '--skip-success-output')
5 changes: 1 addition & 4 deletions rulesets/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
<exclude name="Magento2.Exceptions.ThrowCatch" />
<exclude name="Magento2.Commenting.ClassAndInterfacePHPDocFormatting.InvalidDescription" />
<exclude name="Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge" />

<!-- Covered by Magento2.Files.LineLength -->
<exclude name="Generic.Files.LineLength" />
</rule>

<rule ref="Squiz.Commenting.DocCommentAlignment.SpaceBeforeStar">
Expand All @@ -30,7 +27,7 @@
</properties>
</rule>

<rule ref="Magento2.Files.LineLength">
<rule ref="Generic.Files.LineLength">
<exclude-pattern>*\.phtml$</exclude-pattern>
<properties>
<property name="ignoreComments" value="true"/>
Expand Down
14 changes: 14 additions & 0 deletions script/add-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

ENV=${1:-warden}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
HOOKSPATH="$(git rev-parse --show-toplevel)/.git/hooks"

if [ -f "$HOOKSPATH/pre-commit" ]; then
BACKUPFILE="$HOOKSPATH/pre-commit.$(date +'%s').backup"
echo "you already have 'pre-commit' hook, it was moved to $BACKUPFILE"
mv "$HOOKSPATH/pre-commit" $BACKUPFILE
fi

cp $DIR/../githooks/$ENV/pre-commit $HOOKSPATH
chmod +x $HOOKSPATH/pre-commit

0 comments on commit 37cab8a

Please sign in to comment.