Browse Source

minor #5112 DX: check file permissions (kubawerlos, SpacePossum)

This PR was merged into the 2.15 branch.

Discussion
----------

DX: check file permissions

Commits
-------

1edfd8ded test 2
41d61ca05 test
d509e6f19 Update CONTRIBUTING.md
750151fcf move
972c68975 Trigger CI
1a34066f4 Fix file permissions
914760770 Add checking file permissions
SpacePossum 4 years ago
parent
commit
3f85b94bf9

+ 0 - 1
.gitattributes

@@ -11,7 +11,6 @@
 /.* export-ignore
 /benchmark.sh export-ignore
 /box.json.dist export-ignore
-/check_trailing_spaces.sh export-ignore
 /dev-tools/ export-ignore
 /phpmd.xml export-ignore
 /phpstan.neon export-ignore

+ 3 - 2
.travis.yml

@@ -52,12 +52,13 @@ jobs:
                     | grep -v tests/Test/IsIdenticalConstraint.php \
                     | grep -v tests/TestCase.php \
                     && (echo "UNKNOWN FILES DETECTED" && travis_terminate 1) || echo "NO UNKNOWN FILES"
-                - ./check_trailing_spaces.sh || travis_terminate 1
+                - ./dev-tools/check_file_permissions.sh || travis_terminate 1
+                - ./dev-tools/check_trailing_spaces.sh || travis_terminate 1
                 - dev-tools/vendor/bin/phpstan analyse
                 - if [ -n "$CHANGED_PHP_FILES" ]; then ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml || travis_terminate 1; fi
                 - ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json) || travis_terminate 1
                 - composer normalize --dry-run --working-dir=./dev-tools ../composer.json
-                - ./dev-tools/check-shell-scripts.sh
+                - ./dev-tools/check_shell_scripts.sh
 
         - &STANDARD_TEST_JOB
             stage: Fast Test

+ 2 - 1
CONTRIBUTING.md

@@ -12,7 +12,8 @@ If you need any help, don't hesitate to ask the community on [Gitter](https://gi
 * Create a new branch, e.g. `feature-foo` or `bugfix-bar`.
 * Make changes.
 * If you are adding functionality or fixing a bug - add a test! Prefer adding new test cases over modifying existing ones.
-* Make sure there is no trailing spaces in code: `./check_trailing_spaces.sh`.
+* Make sure there is no wrong file permissions in the repository: `./dev-tools/check_file_permissions.sh`.
+* Make sure there is no trailing spaces in the code: `./dev-tools/check_trailing_spaces.sh`.
 * Regenerate README: `php php-cs-fixer readme > README.rst` (Windows `php.exe php-cs-fixer readme > README.rst`). Do not modify `README.rst` manually!
 * Install dev tools: `dev-tools/install.sh`
 * Run static analysis using PHPStan: `php -d memory_limit=256M dev-tools/vendor/bin/phpstan analyse`

+ 27 - 0
dev-tools/check_file_permissions.sh

@@ -0,0 +1,27 @@
+#!/bin/sh
+set -eu
+
+files_with_wrong_permissions=$(
+    git ls-files --stage . \
+        ':!*.sh' \
+        ':!php-cs-fixer' \
+    | grep -P "100\d\d(1|3|5|7) " \
+    | sort -fh
+)
+
+if [ "$files_with_wrong_permissions" ]
+then
+    printf '\033[97;41mWrong permissions detected:\033[0m\n'
+    echo "${files_with_wrong_permissions}"
+    exit 3
+fi
+
+if [ -x "php-cs-fixer" ]
+then
+    echo '"php-cs-fixer" is executable'
+else
+    echo '"php-cs-fixer" not is executable'
+    exit 4
+fi
+
+printf '\033[0;32mNo wrong permissions detected.\033[0m\n'

+ 0 - 0
dev-tools/check-shell-scripts.sh → dev-tools/check_shell_scripts.sh


+ 0 - 0
check_trailing_spaces.sh → dev-tools/check_trailing_spaces.sh


+ 0 - 0
tests/Fixer/Operator/TernaryOperatorSpacesFixerTest.php