Open aaemnnosttv opened 4 years ago
@felixarntz I've been looking into the IB for this one and it looks like the work to be done is fairly substantial - especially since we have no custom sniffs of our own yet - and may need to be broken into multiple issues. There's also a question as to whether this repo is the right place for these rules to be defined as it seems like some of these are filling in rules that aren't implemented in WPCS yet.
Either way I don't think it makes sense to plan this one for the upcoming sprint as there is more investigation/definition needed here.
@aaemnnosttv I believe we should move forward with this and implement these rules as part of the repository. We're now enforcing them in JS (see #1493), and it makes sense to add the same strictness to our PHP codebase.
I believe contributing this to WPCS would be a great effort, and we should do so, but I suggest decoupling that. We can replace our own implementation with theirs if such rules get adopted there.
Sounds good, thanks for confirming @felixarntz.
I'm going to remove the GFI label though since I don't think it meets that criteria based on my previous investigation here.
I've added an IB and an estimate.
@benbowler – is this ready for review?
Yes, moved into the review column.
A minor few issues with the IB:
includes/CodeStandards/GoogleSiteKit/Sniffs/Semantical
but "Semantical" isn't a word. Did you mean "Semantic"?includes/**CodeStandards**/GoogleSiteKit
and includes/**CodeStandards**/GoogleSiteKit
. Are they meant to be different folders? That's sort of confusing if so.I think the approach looks proper though—I'm not wildly familiar with writing PHP Sniff rules but I'd think this would work similar to the ESLint rules and this approach matches that from what I can tell.
Can you address the two issues I mentioned? After that this should be good to go 🙂
Hey @tofumatt, I've replaced all examples of Semantical
with Semantic
and updated all of the folder names to CodeStandards
.
IB ✅
Bumping the estimate here since this one will undoubtedly be a beast and will also require a large number of changes across the codebase in order to conform to the new style rules.
cc: @eclarke1 @fhollis
@aaemnnosttv Assigning to you for now; can you check who would want to proceed with the work that Ben started?
@felixarntz – happy to take this over although there are a few things I'd like to discuss first; let's discuss on our next call.
@felixarntz given our conversation about the changes here, do you think this makes sense to keep in execution or move it back to definition since the implementation will be substantially different? I suppose the ACs could remain the same, but we should probably move and plan this issue to be specific to the final integration of the new sniffs since the majority of the engineering will no longer be part of the SK codebase.
@aaemnnosttv Yeah, let's move this back to ACs for now and later update them once the path forward is clear.
@eclarke1 @fhollis moving back to ACs and removing from the sprint as this issue will be redefined to be much simpler but won't be something we can do until later.
@felixarntz moving to stalled for now as this likely won't be actionable in the near future.
Moving this back to Backlog as we now have the new repository and #4187 as a prerequisite so this can soon move forward.
Just stumbled upon https://github.com/GoogleChromeLabs/wpcs-core-extra-sniffs & this issue.
Are you planning on submitting some of these rules to WPCS directly? Seems like most of them would be happily accepted there as they also apply to core.
@swissspidy Eventually, yes. We wanted to start them in their own repository though to be independent of WPCS itself. It would also allow us to "prove" them in the wild (in Site Kit) before proposing them for merge.
@felixarntz what do you think about converting this to an epic? I think we probably have a single issue for laying the foundation and then each rule could probably have its own issue which could also potentially allow for some to happen at the same time.
@aaemnnosttv Good idea, that makes sense. Although I think we can skip the epic here and break this down into multiple issues without one - we already have a label to mark anything related to that other repository. First we should get started with #4187 though.
Feature Description
In addition to following WordPress core coding styles for PHP, there are some additional coding style rules which are applied that are not covered by the PHPCS configuration.
This may be partially covered by #547 but some rules will likely still not be enforced.
E.g.
We should extend the PHPCS configuration to include these additions as much as possible.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
There should be PHPCS rules to enforce the following:
Semantic
Organizational
since
tag.since
(multiple entries allowed),deprecated
,access
,static
,global
,var
,param
(multiple entries allowed),return
.since
/deprecated
/access
/static
should be grouped together, separated by a blank line fromparam
/return
which should be grouped together. If there isglobal
, it should be separated from both others by a blank line (essentially be its own group).param
tag types and descriptions in a single doc-block should be indented in a way that they are aligned with each other.Bonus points for opening this also against WordPress core, which probably could use all of it :-)
Implementation Brief
Create a new directory
includes/CodeStandards/GoogleSiteKit/
where our new coding sniffs will live.Create a new ruleset file:
includes/CodeStandards/GoogleSiteKit/ruleset.xml
to define our new ruleset:To get composer to include our new coding standard rules whenever the vendor version of phpcs in run, add the following to the
phpcs.xml
file inside the<ruleset>
tags:For each of the required rules in the table below go through the following steps:
includes/CodeStandards/GoogleSiteKit/Sniffs/Semantic
orincludes/CodeStandards/GoogleSiteKit/Sniffs/Organizational
using the file name from the table.register
function from the table and coding the validation in theprocess
function and using the class name from the table:namespace PHP_CodeSniffer\Standards\MyStandard\Sniffs\Commenting;
use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File;
class DisallowHashCommentsSniff implements Sniff { /**
@return array(int) */ public function register() { return array(T_COMMENT);
}
/**
@return void */ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['content']{0} === '#') { $error = 'Hash comments are prohibited; found %s'; $data = array(trim($tokens[$stackPtr]['content'])); $phpcsFile->addError($error, $stackPtr, 'Found', $data); }
} }
?>