slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.39k stars 173 forks source link

Idea: Require trailing comma in multi-line annotations #352

Open alcaeus opened 6 years ago

alcaeus commented 6 years ago

This sniff would compare to SlevomatCodingStandard.Arrays.TrailingArrayCommaSniff and require a trailing comma on each line of a multi-line annotation. The idea is to reduce the diff size when adding a new property or item in a list. Caveat: I'm not sure if it's possible to properly check coding standards in docblocks - my parser knowledge ends well before that.

/**
 * @ODM\Document(
 *     collection="user",
 *     repositoryClass=UserRepository::class,
 *     indexes={
 *         @ODM\Index(keys={"canonicalUsername"="asc"}, unique=true),
 *         @ODM\Index(keys={"affiliateHash"="asc"}, unique=true),
 *     },
 * )
 */
kukulich commented 6 years ago

if it's possible to properly check coding standards in docblocks

It's possible but it's difficult. We'll see :)

Majkl578 commented 6 years ago

I like the idea, but this is Doctrine-specific. Although Doctrine Annotations are widespread enough so it should imho be fine here. My suggestion: Wait for Annotations 2.0, there will be proper grammar & grammar-based parser, maybe also AST. Should be fully backward compatible. :)