-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: php-cs-fixer #154
Merged
Merged
Feat: php-cs-fixer #154
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
64f5483
Feat: php-cs-fixer
Rom1-B 599f570
fix rules
Rom1-B ebce427
clean config
Rom1-B 25306d8
clean rules
Rom1-B e6acf11
trailing_comma_in_multiline
Rom1-B 4893b3b
Revert "trailing_comma_in_multiline"
Rom1-B 7529afb
php 7.4 compatiblity
Rom1-B 36db86c
remove php_codesniffer
Rom1-B File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
|
||
/** | ||
* Read excluded paths from .gitignore | ||
* | ||
* @param string $dir | ||
* | ||
* @return string[] | ||
*/ | ||
function getGitignorePaths(string $dir): array | ||
{ | ||
$gitignoreFile = $dir . '/.gitignore'; | ||
$paths = []; | ||
|
||
if (!file_exists($gitignoreFile)) { | ||
return $paths; | ||
} | ||
|
||
$lines = file($gitignoreFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); | ||
if (!empty($lines)) { | ||
foreach ($lines as $line) { | ||
// Ignore comments and empty lines | ||
if (strpos($line, '#') === 0 || trim($line) === '') { | ||
continue; | ||
} | ||
// Add relative paths | ||
$paths[] = trim($line); | ||
} | ||
} | ||
|
||
return $paths; | ||
} | ||
|
||
$projectDir = __DIR__; | ||
$finder = Finder::create() | ||
->in($projectDir) | ||
->name('*.php'); | ||
|
||
// Exclude paths from .gitignore | ||
$gitignorePaths = getGitignorePaths($projectDir); | ||
foreach ($gitignorePaths as $path) { | ||
$finder->notPath($path); | ||
} | ||
|
||
$config = new Config(); | ||
|
||
$rules = [ | ||
'@PSR12' => true, | ||
'@PER-CS2.0' => true, | ||
AdrienClairembault marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'array_indentation' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'binary_operator_spaces' => ['default' => 'align_single_space_minimal'], | ||
'blank_line_after_namespace' => true, | ||
'blank_line_after_opening_tag' => true, | ||
'blank_line_before_statement' => ['statements' => ['return']], | ||
'braces' => ['allow_single_line_closure' => true], | ||
'cast_spaces' => ['space' => 'single'], | ||
'class_attributes_separation' => ['elements' => ['method' => 'one']], | ||
'concat_space' => ['spacing' => 'one'], | ||
'declare_equal_normalize' => ['space' => 'single'], | ||
'function_typehint_space' => true, | ||
'lowercase_cast' => true, | ||
'no_whitespace_in_blank_line' => true, | ||
'single_blank_line_at_eof' => true, | ||
'single_quote' => true, | ||
'space_after_semicolon' => true, | ||
'trailing_comma_in_multiline' => ['elements' => ['arrays']], | ||
'trim_array_spaces' => true, | ||
'unary_operator_spaces' => true, | ||
'whitespace_after_comma_in_array' => true, | ||
AdrienClairembault marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]; | ||
|
||
return $config | ||
->setRules($rules) | ||
->setFinder($finder) | ||
->setUsingCache(false); |
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the documentation:
What kind of files do you want to exclude with this function ? Most of the time, the defaut exclusions will do the job, and manually adding a specific dir is probably simplier than maintaining this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially intended to create a generic configuration that could be identical across each plugin, allowing for simple copy-and-paste. However, it might not be optimal, so I will remove it.