diff options
author | VirtualTam <virtualtam@flibidi.net> | 2018-10-13 00:05:04 +0200 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2018-12-02 22:39:16 +0100 |
commit | 04ec8fedd91642d4c0fc96258868086b8a51c899 (patch) | |
tree | bfb4599425404b8484064fd91b482f1f797f7ce6 | |
parent | 37c9c6b4e62ba25f889ebb6486fe5c442acc9095 (diff) | |
download | Shaarli-04ec8fedd91642d4c0fc96258868086b8a51c899.tar.gz Shaarli-04ec8fedd91642d4c0fc96258868086b8a51c899.tar.zst Shaarli-04ec8fedd91642d4c0fc96258868086b8a51c899.zip |
lint: setup PHPCS for PSR-1 and PSR-2
Relates to https://github.com/shaarli/Shaarli/issues/95
See:
- https://github.com/squizlabs/PHP_CodeSniffer
- https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist
- https://www.php-fig.org/psr/psr-1/
- https://www.php-fig.org/psr/psr-2/
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | phpcs.xml | 17 |
2 files changed, 25 insertions, 6 deletions
@@ -2,7 +2,6 @@ | |||
2 | # Makefile for PHP code analysis & testing, documentation and release generation | 2 | # Makefile for PHP code analysis & testing, documentation and release generation |
3 | 3 | ||
4 | BIN = vendor/bin | 4 | BIN = vendor/bin |
5 | PHP_SOURCE = index.php application tests plugins | ||
6 | 5 | ||
7 | all: static_analysis_summary check_permissions test | 6 | all: static_analysis_summary check_permissions test |
8 | 7 | ||
@@ -23,23 +22,26 @@ docker_%: | |||
23 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php | 22 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php |
24 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php | 23 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php |
25 | ## | 24 | ## |
26 | code_sniffer: code_sniffer_full | 25 | PHPCS := $(BIN)/phpcs |
26 | |||
27 | code_sniffer: | ||
28 | @$(PHPCS) | ||
27 | 29 | ||
28 | ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend... | 30 | ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend... |
29 | PHPCS_%: | 31 | PHPCS_%: |
30 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$* | 32 | @$(PHPCS) --report-full --report-width=200 --standard=$* |
31 | 33 | ||
32 | ### - errors by Git author | 34 | ### - errors by Git author |
33 | code_sniffer_blame: | 35 | code_sniffer_blame: |
34 | @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame | 36 | @$(PHPCS) --report-gitblame |
35 | 37 | ||
36 | ### - all errors/warnings | 38 | ### - all errors/warnings |
37 | code_sniffer_full: | 39 | code_sniffer_full: |
38 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 | 40 | @$(PHPCS) --report-full --report-width=200 |
39 | 41 | ||
40 | ### - errors grouped by kind | 42 | ### - errors grouped by kind |
41 | code_sniffer_source: | 43 | code_sniffer_source: |
42 | @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0 | 44 | @$(PHPCS) --report-source || exit 0 |
43 | 45 | ||
44 | ## | 46 | ## |
45 | # Checks source file & script permissions | 47 | # Checks source file & script permissions |
diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..29b95d56 --- /dev/null +++ b/phpcs.xml | |||
@@ -0,0 +1,17 @@ | |||
1 | <?xml version="1.0"?> | ||
2 | <ruleset name="Shaarli"> | ||
3 | <description>The Shaarli coding standards</description> | ||
4 | |||
5 | <file>index.php</file> | ||
6 | <file>application</file> | ||
7 | <file>plugins</file> | ||
8 | <file>tests</file> | ||
9 | |||
10 | <exclude-pattern>*/*.css</exclude-pattern> | ||
11 | <exclude-pattern>*/*.js</exclude-pattern> | ||
12 | |||
13 | <arg name="colors"/> | ||
14 | |||
15 | <rule ref="PSR1"/> | ||
16 | <rule ref="PSR2"/> | ||
17 | </ruleset> | ||