-
Notifications
You must be signed in to change notification settings - Fork 154
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
[TASK] Update our coding standard #1264
Conversation
80e254d
to
fceabc1
Compare
It looks like I'll need to tweak the ruleset a bit to retain compatibility with PHP 7.3 and 7.4. |
d3a69f5
to
7590cb4
Compare
@JakeQZ friendly ping :-) |
Sorry, I missed this amongst the other 464 emails in the last 5 days. Not even exaggerating - I just counted them ;) |
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'll need to go through the removed settings in more detail, which will take a bit of time I don't have right now. But there is the match
PHP 8 issue.
config/php-cs-fixer.php
Outdated
'no_unused_imports' => true, | ||
'ordered_imports' => true, | ||
// overwrite the PER2 defaults to restore compatibility with PHP 7.x | ||
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match']], |
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.
As per issue on sister project, we can't include match
here, until PHP-CS-Fixer fixes the issue.
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.
It's removed now.
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.
The match
doesn't appear to be removed from where I'm looking.
(BTW, I've realized now that the defaults haven't changed with the new PHP-CS-Fixer version, it's rather than it's included in the @PER-CS2.0
rule set - and that may have changed between Fixer versions.)
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.
Oh, it seems match
was there 2 times. I've removed the other one now as well, and also created MyIntervals/PHP-CSS-Parser#629.
f78f3be
to
42b7359
Compare
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've been through all the added and removed rules, and checked what the defaults are, and whether they are included in any of the rule sets that will be active following this change.
Quite a few of the removed rules I think we need to keep, because they are not applied by default, nor included in an rule set.
Many of the other removed rules seemed to be incorrectly specified as a Boolean, when in fact what is expected is an array of configuration values. I've ignored those, assuming they were invalid and would have had no effect anyway. I don't know if I'm missing something, like if it's possible to provide a Boolean when an array is expected, and that would result in enabling all options (though in some cases the options aren't Boolean either).
Some of the added rules appear unnecessary as they are the default values anyway. At least one of the added rules is given as a Boolean when an array is expected.
config/php-cs-fixer.php
Outdated
// casing | ||
'magic_constant_casing' => true, | ||
'native_function_casing' => true, |
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 think we need to keep these, since they are not part of any of the rule sets.
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.
GitHub diff isn't highlighting the lines I selected, so you'll need to check the smallprint, e.g. "Comment on lines -39 to -41" to see how many preceding lines I'm referring to. If there's nothing there, it means I'm just commenting on a single line.
config/php-cs-fixer.php
Outdated
'modernize_types_casting' => true, | ||
'no_short_bool_cast' => true, |
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.
Ditto these two.
// class notation | ||
'class_attributes_separation' => true, | ||
'no_blank_lines_after_class_opening' => true, | ||
'no_php4_constructor' => true, |
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.
And this one.
// (no rules used from this section) | ||
|
||
// comment | ||
'no_empty_comment' => true, |
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.
And this one.
|
||
// control structure | ||
'elseif' => true, | ||
'no_superfluous_elseif' => true, |
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.
This one...
'phpdoc_separation' => true, | ||
'phpdoc_trim' => true, | ||
'phpdoc_types' => true, | ||
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], |
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.
And this.
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], | ||
|
||
// return notation | ||
'no_useless_return' => true, |
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.
And this.
config/php-cs-fixer.php
Outdated
'no_empty_statement' => true, | ||
'no_singleline_whitespace_before_semicolons' => true, | ||
'semicolon_after_instruction' => true, |
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.
And these three.
'space_after_semicolon' => true, | ||
|
||
// strict | ||
'declare_strict_types' => true, |
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.
And this.
'declare_strict_types' => true, | ||
|
||
// string notation | ||
'escape_implicit_backslashes' => ['single_quoted' => true], |
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.
This should be replaced with string_implicit_backslashes => ['single_quoted' => 'escape']
, which isn't in any of the rule sets used (escape_implicit_backslashes
is deprecated).
Switch to the PER2 coding standard and reduce the number of custom rules. This basically aligns our code style with that used by the PHP-CSS-Parser project, which is very close to the PER-2 coding standard. Fixes #1262
42b7359
to
a741dc8
Compare
@JakeQZ Thank your for doing the painstaking work of going through this with a fine-grained comb! 🙏 I've now updated the ruleset accordingly. |
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 think I've checked most if not all the initial review change suggestions. However, it's tricky since GitHub drops some of the original review comments from the diff if it can't work out where to place them now. (In some cases that's quite poor - e..g. lines added then removed - the review comment disappears too.)
One thing I have spotted: if we don't want no_useless_else
, we probably also don't want no_superfluous_elseif
, for consistency.
'no_superfluous_elseif' => true, | ||
'no_unneeded_control_parentheses' => true, | ||
'no_unneeded_curly_braces' => true, | ||
'no_useless_else' => true, |
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.
On that basis, we also need to remove the no_superfluous_elseif
.
config/php-cs-fixer.php
Outdated
|
||
// control structure | ||
'elseif' => true, | ||
'no_superfluous_elseif' => true, |
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.
If we remove no_useless_else
, we should also remove no_superfluous_elseif
.
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.
Done.
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.
Having finalized this for now (it will change in future, I'm sure) here, we should probably update the equivalent on the sister project to match. And like the contrubution guidelines, CoC, and other bits and bobs, keep them in sync.
I wonder if there's a way of using a template to keep cross-project files like these in sync. You mentioned that the CoC came from a GitHub template (I think). Can we introduce our own repository-owner templates to help?
Switch to the PER2 coding standard and reduce the number of custom rules.
This basically aligns our code style with that used by the PHP-CSS-Parser project, which is very close to the PER-2 coding standard.
Fixes #1262