Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#5678 Add PHP-CS formatter and pre-commit hook to format c…
…ommitted changes
- Loading branch information
Showing
4 changed files
with
640 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ temp | |
.buildpath | ||
.settings | ||
.DS_Store | ||
.php_cs.cache | ||
node_modules | ||
js/build.js | ||
js/hot-updates | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__); | ||
|
||
// Apply formatting to all plugins that are not git submodules | ||
$pluginsDir = __DIR__ . DIRECTORY_SEPARATOR . 'plugins'; | ||
$files = scandir($pluginsDir); | ||
foreach ($files as $file) { | ||
$categoryDir = $pluginsDir . DIRECTORY_SEPARATOR . $file; | ||
if (!in_array($file, ['.', '..']) && is_dir($categoryDir)) { | ||
$pluginDirs = scandir($categoryDir); | ||
foreach ($pluginDirs as $pluginDir) { | ||
$fullPluginPath = join(DIRECTORY_SEPARATOR, [$categoryDir, $pluginDir]); | ||
$gitPath = join(DIRECTORY_SEPARATOR, [$fullPluginPath, '.git']); | ||
if (!in_array($pluginDir, ['.', '..']) && is_dir($fullPluginPath) && !file_exists($gitPath)) { | ||
$finder->in($fullPluginPath); | ||
} | ||
} | ||
} | ||
} | ||
|
||
$finder->exclude([ | ||
'cache', | ||
'cypress', | ||
'dbscripts', | ||
'docs', | ||
'js', | ||
'lib/pkp', | ||
'lib/ui-library', | ||
'locale', | ||
'node_modules', | ||
'public', | ||
'plugins', | ||
'registry', | ||
'schemas', | ||
'styles', | ||
'templates', | ||
]) | ||
->name('*.php') | ||
->name('_ide_helper') | ||
->notName('*.blade.php') | ||
->ignoreDotFiles(true) | ||
->ignoreVCS(true); | ||
|
||
$rules = include './lib/pkp/.php_cs_rules'; | ||
|
||
$config = new PhpCsFixer\Config(); | ||
return $config->setRules($rules) | ||
->setFinder($finder); |
Oops, something went wrong.