Merge "parser: Code quality tweaks"

This commit is contained in:
jenkins-bot 2020-08-20 20:01:03 +00:00 committed by Gerrit Code Review
commit e1eb983d51
2 changed files with 31 additions and 26 deletions

View file

@ -753,20 +753,20 @@ class CommentParser {
// Everything from the last comment up to here is the next comment
$startNode = $this->nextInterestingLeafNode( $curComment->getRange()->endContainer );
$offset = $lastSigNode === $node ?
$lastSigNodeOffset = $lastSigNode === $node ?
$match[0][1] + strlen( $match[0][0] ) - $match['offset'] :
CommentUtils::childIndexOf( $lastSigNode ) + 1;
$range = new ImmutableRange(
$startNode->parentNode,
CommentUtils::childIndexOf( $startNode ),
$lastSigNode === $node ? $node : $lastSigNode->parentNode,
$offset
$lastSigNodeOffset
);
$sigRange = new ImmutableRange(
$firstSigNode->parentNode,
CommentUtils::childIndexOf( $firstSigNode ),
$lastSigNode === $node ? $node : $lastSigNode->parentNode,
$offset
$lastSigNodeOffset
);
$startLevel = CommentUtils::getIndentLevel( $startNode, $this->rootNode ) + 1;
@ -774,6 +774,16 @@ class CommentParser {
if ( $startLevel !== $endLevel ) {
$warnings[] = 'Comment starts and ends with different indentation';
}
// Should this use the indent level of $startNode or $node?
$level = min( $startLevel, $endLevel );
$dateTime = $dfParser( $match );
if ( isset( $dateTime->discussionToolsWarning ) ) {
$warnings[] = $dateTime->discussionToolsWarning;
}
// ISO 8601 date. Almost DateTimeInterface::RFC3339_EXTENDED, but ending with 'Z' instead
// of '+00:00', like Date#toISOString in JavaScript.
$dateTimeStr = $dateTime->format( 'Y-m-d\TH:i:s.v\Z' );
// Avoid generating multiple comments when there is more than one signature on a single "line".
// Often this is done when someone edits their comment later and wants to add a note about that.
@ -799,24 +809,16 @@ class CommentParser {
$curComment->getRange()->setEnd( $range->endContainer, $range->endOffset )
);
$curComment->addSignatureRange( $sigRange );
$curComment->setLevel( min( min( $startLevel, $endLevel ), $curComment->getLevel() ) );
$curComment->setLevel( min( $level, $curComment->getLevel() ) );
continue;
}
$dateTime = $dfParser( $match );
if ( isset( $dateTime->discussionToolsWarning ) ) {
$warnings[] = $dateTime->discussionToolsWarning;
}
$curComment = new CommentItem(
// Should this use the indent level of $startNode or $node?
min( $startLevel, $endLevel ),
$level,
$range,
[ $sigRange ],
// ISO 8601 date. Almost DateTimeInterface::RFC3339_EXTENDED, but ending with 'Z' instead
// of '+00:00', like Date#toISOString in JavaScript.
$dateTime->format( 'Y-m-d\TH:i:s.v\Z' ),
$dateTimeStr,
$author
);
$curComment->setRootNode( $this->rootNode );

View file

@ -719,7 +719,8 @@ Parser.prototype.buildThreadItems = function () {
threadItems = [],
treeWalker,
node, range, fakeHeading, curComment,
foundSignature, firstSigNode, lastSigNode, sigRange, author, startNode, match, offset, startLevel, endLevel, dateTime, warnings;
foundSignature, firstSigNode, lastSigNode, sigRange, author, startNode,
match, lastSigNodeOffset, startLevel, endLevel, level, dateTime, warnings;
treeWalker = this.rootNode.ownerDocument.createTreeWalker(
this.rootNode,
@ -767,20 +768,20 @@ Parser.prototype.buildThreadItems = function () {
// Everything from the last comment up to here is the next comment
startNode = this.nextInterestingLeafNode( curComment.range.endContainer );
offset = lastSigNode === node ?
lastSigNodeOffset = lastSigNode === node ?
match.index + match[ 0 ].length - match.offset :
utils.childIndexOf( lastSigNode ) + 1;
range = {
startContainer: startNode.parentNode,
startOffset: utils.childIndexOf( startNode ),
endContainer: lastSigNode === node ? node : lastSigNode.parentNode,
endOffset: offset
endOffset: lastSigNodeOffset
};
sigRange = {
startContainer: firstSigNode.parentNode,
startOffset: utils.childIndexOf( firstSigNode ),
endContainer: lastSigNode === node ? node : lastSigNode.parentNode,
endOffset: offset
endOffset: lastSigNodeOffset
};
startLevel = utils.getIndentLevel( startNode, this.rootNode ) + 1;
@ -788,6 +789,13 @@ Parser.prototype.buildThreadItems = function () {
if ( startLevel !== endLevel ) {
warnings.push( 'Comment starts and ends with different indentation' );
}
// Should this use the indent level of `startNode` or `node`?
level = Math.min( startLevel, endLevel );
dateTime = dfParser( match );
if ( dateTime.discussionToolsWarning ) {
warnings.push( dateTime.discussionToolsWarning );
}
// Avoid generating multiple comments when there is more than one signature on a single "line".
// Often this is done when someone edits their comment later and wants to add a note about that.
@ -804,18 +812,13 @@ Parser.prototype.buildThreadItems = function () {
curComment.range.endContainer = range.endContainer;
curComment.range.endOffset = range.endOffset;
curComment.signatureRanges.push( sigRange );
curComment.level = Math.min( Math.min( startLevel, endLevel ), curComment.level );
curComment.level = Math.min( level, curComment.level );
continue;
}
dateTime = dfParser( match );
if ( dateTime.discussionToolsWarning ) {
warnings.push( dateTime.discussionToolsWarning );
}
curComment = new CommentItem(
// Should this use the indent level of `startNode` or `node`?
Math.min( startLevel, endLevel ),
level,
range,
[ sigRange ],
dateTime,