-
Notifications
You must be signed in to change notification settings - Fork 846
Import several phpcs sniffs from MediaWiki #17406
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
Conversation
|
Submitting this now as a proof of concept. If we want to go ahead with this, I'll need to poke upstream about a few things:
|
|
I did some testing by running phpcbf for these rules, to see that they didn't wind up creating a flood of other rule violations or something. Then I uploaded the results at #17419 in case that would be useful to see. |
Any success poking upstream? |
I was waiting for feedback here. I'll go poke them now. |
|
Sounds good; thanks! |
Poked upstream at https://phabricator.wikimedia.org/T265735. It did turn out to be a one-line change. |
7eec79d to
cadfcaa
Compare
0786777 to
b6d69e5
Compare
|
I'd be okay merging this into the codesniffer package PR OR merging that one, then merging this immediately following, as it is now. If/when MediaWiki updates the package so we can pin a specific version, we can do that in a follow-up. |
I'd prefer the latter, it seems cleaner to have the major refactor and the added functionality be separate in master so future git archaeologists can see what was what. |
b6d69e5 to
1dc8f56
Compare
|
Scheduled Jetpack release: November 10, 2020. E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-17406 Thank you for the great PR description! When this PR is ready for review, please apply the |
|
We'll likely need to do this https://github.com/Automattic/jetpack/blob/master/tests/setup-travis.sh#L15 for this package as well. |
Yeah, I see Travis is failing. BTW, I wish Travis would email me when it fails on one of my PRs. It looks like it would by default, but specifying recipients unfortunately overrides that (travis-ci/travis-ci#8868). And I don't want emails about everyone's Travis failures... |
We've discussed this a bit over the years. I think updating the status of the PR itself (via a comment from a bot for example) would allow us to hit 3 birds with one stone:
Edit: cross-linking to #17094, where @brbrr has already started looking into moving some of our tests to GitHub actions; doing so would allow to update the PR at the end of the action run. |
494df99 to
781f334
Compare
2670c53 to
59f51a6
Compare
|
Ok, Travis is passing now (other than the flaky sync tests). I'm not entirely happy with what I had to do to make that happen, but it works. |
MediaWiki has a large suite of custom phpcs sniffs, several of which would be useful for Jetpack. * MediaWiki.AlternativeSyntax.LeadingZeroInFloat: Prefer `0.5` over `.5` for better readability. * MediaWiki.Classes.UnsortedUseStatements: Require `use` statements be sorted. * MediaWiki.Classes.UnusedUseStatement: Attempts to flag `use` statements where the used class isn’t actually used. * MediaWiki.ExtraCharacters.ParenthesesAroundKeyword: Flags things like `clone( $x )`, `continue( 2 )`, and `break( 2 )`, in addition to things like `require_once( '...' )` that are already getting flagged by PEAR.Files.IncludingFile.BracketsNotRequired. * MediaWiki.Usage.DirUsage: Prefer `__DIR__` to `dirname( __FILE__ )`. * MediaWiki.Usage.DoubleNotOperator: `! ! $x` is "clever code", `(bool) $x` would be clearer. * MediaWiki.Usage.InArrayUsage: Flags constructs like `in_array( $key, array_keys( $array ) )` and `in_array( $key, array_flip( $array ) )` that could be done more clearly and efficiently with `isset( $array[ $key ] )` or `array_key_exists( $key, $array )`. * MediaWiki.Usage.MagicConstantClosure: Flag use of `__METHOD__` and `__FUNCTION__` inside closures, as they don’t produce useful output. * MediaWiki.Usage.NestedFunctionsSniff: Defining a function (not a closure) inside a function is "clever code", if not an outright bug. * MediaWiki.Usage.PHPUnitAssertEquals: Prefer other PHPUnit assertions over `assertEquals()` in some cases for better type safety. * MediaWiki.Usage.PlusStringConcat: Flag attempts to concatenate strings with `+` rather than `.`. Useful for programmers coming from JS. * MediaWiki.Usage.ReferenceThis: `&$this` raises warnings since PHP 7.1, warn against it. Surprisingly not caught by the "PHPCompatibility" sniffs we’re importing. * MediaWiki.WhiteSpace.MultipleEmptyLines: Forbids multiple empty lines everywhere, versus Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines which only does so inside functions. * MediaWiki.WhiteSpace.SpaceAfterClosure: The WordPress sniffs seem to have good coverage of whitespace stuff, but miss that `function()` should be `function ()`.
Uninstall automattic/jetpack-codesniffer for 5.6 and 7.0, since mediawiki/mediawiki-codesniffer requires 7.2+. Also, since we're uninstalling the phpcs standard, don't try to run phpcs. And we need a way to avoid having run-travis.sh run the tests for the codesniffer package when PHP is too old. Sigh.
59f51a6 to
8985c17
Compare
|
@anomiex What's outstanding on this before ready for review? |
|
If you're still willing to merge it with the dev-master dependency, nothing. Otherwise, I should poke upstream to make a release. edit: poked them on one of their IRC channels. edit: They say they'll have a new version in a few minutes. |
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 follow up with a few PRs to implement these to prevent too much churn in a single PR.
Marking for 9.2 so we don't get caught with PHPCS updates needed during beta week. Let's merge this ASAP after code freeze.
Changes proposed in this Pull Request:
MediaWiki has a large suite of custom phpcs sniffs, several of which would be useful for Jetpack.
0.5over.5for better readability.usestatements be sorted.usestatements where the used class isn’t actually used.clone( $x ),continue( 2 ), andbreak( 2 ), in addition to things likerequire_once( '...' )that are already getting flagged by PEAR.Files.IncludingFile.BracketsNotRequired.__DIR__todirname( __FILE__ ).! ! $xis "clever code",(bool) $xwould be clearer.in_array( $key, array_keys( $array ) )andin_array( $key, array_flip( $array ) )that could be done more clearly and efficiently withisset( $array[ $key ] )orarray_key_exists( $key, $array ).__METHOD__and__FUNCTION__inside closures, as they don’t produce useful output.assertEquals()in some cases for better type safety.+rather than.. Useful for programmers coming from JS.&$thisraises warnings since PHP 7.1, warn against it. Surprisingly not caught by the "PHPCompatibility" sniffs we’re importing.function()should befunction ().Jetpack product discussion
p9dueE-1Y9-p2
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
composer php:linton various files to see what it finds.Proposed changelog entry for your changes: