Page MenuHomePhabricator

PHPCS: The UnrecognizedAnnotation sniff should ignore code block
Open, Needs TriagePublic

Description

Example from Gerrit change 549215

/**
 * Escape and wrap a message value as literal string for LESS.
 *
 * This mostly lets CSSMin escape it and wrap it, but also escape single quotes
 * for compatibility with LESS's feature of variable interpolation into other strings.
 * This is relatively rare for most use of LESS, but for messages it is quite common.
 *
 * Example:
 *
 * @code
 *     @x: "foo's";
 *     .eg { content: 'Value is @{x}'; }
 * @endcode
 *
 * Produces output: `.eg { content: 'Value is foo's'; }`.
 * (Tested in less.php 1.8.1, and Less.js 2.7)
 *
 * @param string $msg
 * @return string wrapped LESS variable value
 */
private static function wrapAndEscapeMessage( $msg ) {
	return str_replace( "'", "\'", CSSMin::serializeStringValue( $msg ) );
}

but:

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 84 | ERROR | @x: is not a valid function annotation
    |       | (MediaWiki.Commenting.FunctionAnnotations.UnrecognizedAnnotation)
----------------------------------------------------------------------

Event Timeline

Krinkle renamed this task from PHPCS: The UnrecognizedAnnotation sniff should ignore within a code block to PHPCS: The UnrecognizedAnnotation sniff should ignore code block.Dec 18 2019, 11:06 PM

I am not sure if this should be fixed upstream as of now there are tow sniffs effected and disabled for the same comment:

MediaWiki.Commenting.DocComment.SpacingDocTag
MediaWiki.Commenting.FunctionAnnotations.UnrecognizedAnnotation

@Umherirrender @Krinkle if a fix is desired for the UnrecognizedAnnotation sniff (as opposed to just disabling it) its pretty easy. SpacingDocTag should be easy too; is this still desired / accepted as a rule change?

Yeah, it seems like a bug in both of those sniffs. They should not try to extract annotations or doc tags from inside a @code block.