mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
Update PHPCS overrides
There's now a different rule for the same thing in
mediawiki/mediawiki-codesniffer v43.0.0. Also document the reason for
the override. Follow-up to 8b00546749
.
Change-Id: I392ee10639ffda6de55b091555e8c3cadd2af485
This commit is contained in:
parent
8b00546749
commit
b16dd9dd96
15
.phpcs.xml
15
.phpcs.xml
|
@ -1,7 +1,20 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset>
|
||||
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
|
||||
<exclude name="MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures" />
|
||||
<!--
|
||||
Code such as this:
|
||||
while ( ( $foo = $foo->nextSibling ) && someCondition( $foo ) ) { … }
|
||||
is often convenient when working on DOM tree structures, which we do a lot of in this extension.
|
||||
|
||||
It's particularly helpful in combination with Phan, which can infer that `$foo` is non-null from
|
||||
the code above, but it can't infer that `$foo->nextSibling` is non-null in code like this:
|
||||
while ( $foo->nextSibling && someCondition( $foo->nextSibling ) ) { … }
|
||||
|
||||
When the variable is the only condition, we add extra parentheses to indicate that it isn't a
|
||||
typo for `==`, which is a convention borrowed from C:
|
||||
while ( ( $foo = $foo->nextSibling ) ) { … }
|
||||
-->
|
||||
<exclude name="Generic.CodeAnalysis.AssignmentInCondition" />
|
||||
</rule>
|
||||
<file>.</file>
|
||||
<arg name="extensions" value="php" />
|
||||
|
|
|
@ -148,7 +148,6 @@ class CommentModifier {
|
|||
$transclusionNode = CommentUtils::getTranscludedFromElement( $target );
|
||||
if ( $transclusionNode ) {
|
||||
while (
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
( $nextSibling = $transclusionNode->nextSibling ) &&
|
||||
$nextSibling instanceof Element &&
|
||||
$nextSibling->getAttribute( 'about' ) === $transclusionNode->getAttribute( 'about' )
|
||||
|
@ -491,7 +490,6 @@ class CommentModifier {
|
|||
(
|
||||
// This would be easier to check in prepareWikitextReply(), but that would result
|
||||
// in an empty list item being added at the end if we don't need to add a signature.
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
|
||||
( $wtNode = $wrapperNode->lastChild ) &&
|
||||
$wtNode instanceof Element &&
|
||||
static::isWikitextNodeListItem( $wtNode )
|
||||
|
@ -564,7 +562,6 @@ class CommentModifier {
|
|||
// By request from the community, avoid this if possible after bullet indentation (T259864).
|
||||
if ( !(
|
||||
$replyIndentation === 'bullet' &&
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
|
||||
( $wtNode = $container->firstChild->lastChild ) &&
|
||||
$wtNode instanceof Element &&
|
||||
!static::isWikitextNodeListItem( $wtNode )
|
||||
|
@ -598,7 +595,6 @@ class CommentModifier {
|
|||
// By request from the community, avoid this if possible after bullet indentation (T259864).
|
||||
if ( !(
|
||||
$replyIndentation === 'bullet' &&
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
|
||||
( $wtNode = $container->firstChild->lastChild ) &&
|
||||
$wtNode instanceof Element &&
|
||||
!static::isWikitextNodeListItem( $wtNode )
|
||||
|
|
|
@ -800,7 +800,6 @@ class CommentParser {
|
|||
// which apparently are often turned into entities by buggy editing tools. To handle
|
||||
// this, we must piece together the text, so that our regexp can match those timestamps.
|
||||
if (
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
|
||||
( $previousSibling = $node->previousSibling ) &&
|
||||
$previousSibling instanceof Element &&
|
||||
$previousSibling->getAttribute( 'typeof' ) === 'mw:Entity'
|
||||
|
@ -909,7 +908,6 @@ class CommentParser {
|
|||
NodeFilter::SHOW_ELEMENT | NodeFilter::SHOW_TEXT,
|
||||
[ static::class, 'acceptOnlyNodesAllowingComments' ]
|
||||
);
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
while ( $node = $treeWalker->nextNode() ) {
|
||||
if ( $node instanceof Element && preg_match( '/^h([1-6])$/i', $node->tagName, $match ) ) {
|
||||
$headingNodeAndOffset = CommentUtils::getHeadlineNodeAndOffset( $node );
|
||||
|
@ -923,7 +921,6 @@ class CommentParser {
|
|||
$curComment->setRootNode( $this->rootNode );
|
||||
$result->addThreadItem( $curComment );
|
||||
$curCommentEnd = $node;
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
|
||||
} elseif ( $node instanceof Text && ( $match = $this->findTimestamp( $node, $timestampRegexps ) ) ) {
|
||||
$warnings = [];
|
||||
$foundSignature = $this->findSignature( $node, $curCommentEnd );
|
||||
|
@ -968,7 +965,6 @@ class CommentParser {
|
|||
if (
|
||||
$event === 'leave' &&
|
||||
$n instanceof Text && $n !== $node &&
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
|
||||
( $match2 = $this->findTimestamp( $n, $timestampRegexps ) )
|
||||
) {
|
||||
// If this skips over another potential signature, also skip it in the main TreeWalker loop
|
||||
|
@ -1262,7 +1258,6 @@ class CommentParser {
|
|||
// Phan doesn't realize that the conditions on $nextSibling can terminate the loop
|
||||
// @phan-suppress-next-line PhanInfiniteLoop
|
||||
$endNode &&
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
( $nextSibling = $endNode->nextSibling ) &&
|
||||
$nextSibling instanceof Element &&
|
||||
$nextSibling->getAttribute( 'about' ) === $endNode->getAttribute( 'about' )
|
||||
|
|
|
@ -215,7 +215,6 @@ class CommentUtils {
|
|||
*/
|
||||
public static function childIndexOf( Node $child ): int {
|
||||
$i = 0;
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
while ( ( $child = $child->previousSibling ) ) {
|
||||
$i++;
|
||||
}
|
||||
|
@ -302,7 +301,6 @@ class CommentUtils {
|
|||
|
||||
// 2.
|
||||
while (
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
( $previousSibling = $node->previousSibling ) &&
|
||||
$previousSibling instanceof Element &&
|
||||
$previousSibling->getAttribute( 'about' ) === $about
|
||||
|
@ -455,7 +453,6 @@ class CommentUtils {
|
|||
if ( $matches ) {
|
||||
// If these are all of the children (or the only child), go up one more level
|
||||
while (
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
( $parent = $siblings[ 0 ]->parentNode ) &&
|
||||
$parent !== $excludedAncestorNode &&
|
||||
static::compareRanges( $makeRange( [ $parent ] ), $item->getRange() ) === 'equal'
|
||||
|
|
|
@ -54,7 +54,6 @@ class ImmutableRange {
|
|||
return $b;
|
||||
}
|
||||
$ancestorsA[] = $parent;
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
} while ( $parent = $parent->parentNode );
|
||||
|
||||
$parent = $b;
|
||||
|
@ -64,7 +63,6 @@ class ImmutableRange {
|
|||
return $a;
|
||||
}
|
||||
$ancestorsB[] = $parent;
|
||||
// @phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
} while ( $parent = $parent->parentNode );
|
||||
|
||||
$node = null;
|
||||
|
|
Loading…
Reference in a new issue