Skip to content
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

Run phpbcf for added MediaWiki rules #17419

Closed
wants to merge 5 commits into from

Conversation

anomiex
Copy link
Contributor

@anomiex anomiex commented Oct 8, 2020

Changes proposed in this Pull Request:

This is the result of running

composer php:autofix -- -p --sniffs=MediaWiki.AlternativeSyntax.LeadingZeroInFloat,MediaWiki.Classes.UnsortedUseStatements,MediaWiki.Classes.UnusedUseStatement,MediaWiki.ExtraCharacters.ParenthesesAroundKeyword,MediaWiki.Usage.DirUsage,MediaWiki.Usage.DoubleNotOperator,MediaWiki.Usage.InArrayUsage,MediaWiki.Usage.MagicConstantClosure,MediaWiki.Usage.NestedFunctions,MediaWiki.Usage.PHPUnitAssertEquals,MediaWiki.Usage.PlusStringConcat,MediaWiki.Usage.ReferenceThis,MediaWiki.WhiteSpace.MultipleEmptyLines,MediaWiki.WhiteSpace.SpaceAfterClosure

then cleaning up some whitespace issues the MW sniffs leave behind that would normally be fixed anyway by whitespace-fixing sniffs.

I'm not sure we actually want to merge this particular big cleanup patch, but it could be useful to see what the new sniffs touch. And to see whether the PHPUnit changes from assertEquals to stricter methods break anything.

Jetpack product discussion

Related to #17406.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Nothing should have changed.

Proposed changelog entry for your changes:

  • None, developer only.

There's no point in scanning the copies of WordPress or
WordPress-develop checked out for Docker, or the built files in
_inc that are already listed in .gitignore.

Also one file being .gitignored is no longer used, so let's remove it
from there.
This will make it a bit cleaner in the future to manage tests and
dependencies for the coding standard.

And, if some other repo wants to use our coding standards, they can more
easily do so.

The new coding standard package imports the PHPCompatibility and
WordPress standards, so those are removed from `.phpcs.xml.dist`.
The phpcs configuration specific to Jetpack remains in
`.phpcs.xml.dist`.
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 ()`.
And cleaned up some whitespace issues the MW sniffs leave behind without
whitespace-fixing sniffs coming along behind them.

Not verified because touching the files makes it whine about all the
other existing errors in these files. 😀
@anomiex
Copy link
Contributor Author

anomiex commented Oct 8, 2020

anomiex requested review from georgestephanis, kraftbj, Automattic/jetpack-infinity and Automattic/jetpack-search as code owners 2 minutes ago

No I didn't. Github apparently did that automatically in my name.

@anomiex anomiex removed request for a team and georgestephanis October 8, 2020 16:13
@anomiex anomiex added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Status] Blocked / Hold and removed [Status] In Progress [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Oct 8, 2020
@kraftbj
Copy link
Contributor

kraftbj commented Oct 9, 2020

GitHub auto-requests "code owners" as indicated in this file: https://www.github.com/Automattic/jetpack/tree/master/.github%2FCODEOWNERS

Since we don't require codeowner approval, it's basically a way to alert individuals and teams that changes are made to code they have opted into have a vested interest in.

@anomiex anomiex force-pushed the add/phpcs-rules-from-MediaWiki branch 5 times, most recently from 59f51a6 to 8985c17 Compare October 22, 2020 15:35
Base automatically changed from add/phpcs-rules-from-MediaWiki to master October 27, 2020 20:32
@kraftbj
Copy link
Contributor

kraftbj commented Nov 2, 2020

Closing this. We covered already clean files in #17617, #17618 #17619 #17620. Other files will be covered as they get PHPCBF'd in time.

@kraftbj kraftbj closed this Nov 2, 2020
@kraftbj kraftbj deleted the try/run-phpbcf-for-added-mediawiki-rules branch November 2, 2020 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants