Skip to content

Commit

Permalink
phpcbf lint-staged integration [1], force fix exit code 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkraav committed Sep 24, 2020
1 parent 36471f9 commit b0069f9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bin/phpcbf-fix-exit-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env php
<?php
/**
* PHP Code Beautifier and Fixer fixes violations of a defined coding standard.
* This version is for https://github.com/okonet/lint-staged, which requires
* all success exit codes to complete its mission.
*
* @author Leho Kraav <leho@cxl.com>
* @see https://github.com/squizlabs/PHP_CodeSniffer/blob/master/bin/phpcbf
* @see https://github.com/squizlabs/PHP_CodeSniffer/issues/1359
*/

if (is_file(__DIR__.'/../../../squizlabs/php_codesniffer/autoload.php') === true) {
include_once __DIR__.'/../../../squizlabs/php_codesniffer/autoload.php';
} else {
include_once 'PHP/CodeSniffer/autoload.php';
}

$runner = new PHP_CodeSniffer\Runner();
$exitCode = $runner->runPHPCBF();

if ( 1 === $exitCode ){
$exitCode = 0;
}
exit($exitCode);
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "cxl/phpcs-ruleset",
"description": "PHP CS coding standards for CXL projects.",
"type": "phpcodesniffer-standard",
"bin": [
"bin/phpcbf-fix-exit-0"
],
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"wp-coding-standards/wpcs": "^2.3"
Expand Down

0 comments on commit b0069f9

Please # to comment.