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

[Clearfacts 7132] [MAIN] commit hooks twig and js lint #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"symfony/test-pack": "^1.0"
},
"autoload": {
"psr-4": {
"psr-4": {
"Clearfacts\\Bundle\\CodestyleBundle\\": "src/",
"Clearfacts\\Bundle\\CodestyleBundle\\Tests\\": "tests/"
"Clearfacts\\Bundle\\CodestyleBundle\\Tests\\": "tests/"
}
},
"bin": ["bin/cf-codestyle"],
Expand All @@ -27,7 +27,8 @@
],
"copy-phpcs-config": "bin/cf-codestyle clearfacts:codestyle:copy-cs-config",
"lint-phpcs": "bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run --diff --using-cache=no --allow-risky=yes --ansi src/ tests/",
"lint-phpcs-fix": "bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --using-cache=no --allow-risky=yes --ansi src/ tests/"
"lint-phpcs-fix": "bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --using-cache=no --allow-risky=yes --ansi src/ tests/",
"lint-twig": "bin/console lint:twig"
},
"config": {
"bin-dir": "bin",
Expand Down
39 changes: 39 additions & 0 deletions templates/hooks/pre-commit-twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

# Grab the staged files
stagedFiles=($(git diff --cached --name-only --diff-filter=AM))
files="${stagedFiles[@]}"
if [ "$files" = '' ]
then
exit 0
fi

# Construct the twig linting command.
command=$(echo "make -s lint:twig ${files}")
echo "$command"

# Run the command on our docker container and capture the results
make -s lint:twig ${files} >> results.txt

results=$(cat results.txt)
$(rm results.txt)

# Block the commit from going through if needed
foundErrors=$(grep -o "begin diff" <<< ${results})
returnCode=0

if [ "$foundErrors" != '' ]
then
echo "${results}" >&2

command=$(echo "make -s lint:twig ${files}")
echo "$command"

make -s lint:twig ${files}

echo "You had some twig errors, don't forget to add these fixes to git before commiting again!" >&2

# Exit so you can stage the files and commit again
returnCode=1
fi
exit $returnCode