diff --git a/.editorconfig b/.editorconfig index 21985b5..c6b90d4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,7 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = false insert_final_newline = true + +[*.{bat,cmd}] +end_of_line = crlf +charset = latin1 diff --git a/.travis.yml b/.travis.yml index f8c318a..5545520 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ jobs: language: go go: '1.13' before_script: GO111MODULE=on go install mvdan.cc/sh/v3/cmd/shfmt - script: shfmt -d -s -ln posix -i 0 -ci -kp install-php-extensions scripts/common scripts/travisci-test-extensions scripts/travisci-update-readme scripts/update-readme + script: ./scripts/invoke-shfmt check - <<: *test-extensions-job-template name: Test extensions on Alpine 3.7 diff --git a/README.md b/README.md index 69ac319..de913fc 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,10 @@ Some extension has special requirements: ## How to contribute +### Formatting code + +Before submitting any pull request, be sure to execute the `lint` script in the `scripts` directory (or `lint.bat` on Windows). + ### Adding support to a new PHP extension? 1. change the `install-php-extensions` script diff --git a/scripts/invoke-shfmt b/scripts/invoke-shfmt new file mode 100755 index 0000000..801c6f6 --- /dev/null +++ b/scripts/invoke-shfmt @@ -0,0 +1,28 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +PARAMS='-s -ln posix -i 0 -ci -kp' + +case "${1:-}" in + check) + PARAMS="$PARAMS -d" + ;; + fix) + PARAMS="$PARAMS -w" + ;; + *) + fprintf 'Syntax: %s ' "$0" >&2 + exit 1 + ;; +esac + +shfmt $PARAMS \ + install-php-extensions \ + scripts/common \ + scripts/invoke-shfmt \ + scripts/lint \ + scripts/travisci-test-extensions \ + scripts/travisci-update-readme \ + scripts/update-readme diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 0000000..01edbeb --- /dev/null +++ b/scripts/lint @@ -0,0 +1,16 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +if ! docker --version >/dev/null 2>/dev/null; then + printf 'Docker is not installed, or it is not running\n' >&2 + exit 1 +fi + +SRC_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && cd .. pwd)" + +if ! docker run --rm -v "$SRC_DIR:/src" -w /src --entrypoint /src/scripts/invoke-shfmt mvdan/shfmt:latest fix; then + printf 'ERROR!' >&2 + exit 1 +fi diff --git a/scripts/lint.bat b/scripts/lint.bat new file mode 100644 index 0000000..80a6386 --- /dev/null +++ b/scripts/lint.bat @@ -0,0 +1,21 @@ +@echo off +setlocal + +docker --version >NUL 2>NUL +if errorlevel 1 goto :no-docker + +cd /d "%~dp0.." +if errorlevel 1 goto err +set SRC_DIR=%CD% + +docker run --rm -v "%SRC_DIR%:/src" -w /src --entrypoint /src/scripts/invoke-shfmt mvdan/shfmt:latest fix +if errorlevel 1 goto :err +goto :eof + +:no-docker +echo Docker is not installed, or it's not running >&2 +goto :eof + +:err +echo ERROR! >&2 +goto :eof