2012-12-07 12 views

risposta

26

Provare a eseguire il seguente comando e vedere se produce ciò che si vuole:

phpcs /path/to/code --standard=Squiz --sniffs=Squiz.Commenting.FunctionComment,Squiz.Commenting.FunctionCommentThrowTag,Squiz.Commenting.ClassComment,Squiz.Commenting.FileComment,Squiz.Commenting.VariableComment

Se è così, è possibile creare il proprio standard che comprende solo quelli annusa, e quant'altro si desidera controllare . A tale scopo, crea un file ruleset.xml e utilizzalo come standard.

Ad esempio, è possibile creare un file chiamato mystandard.xml e includere il seguente contenuto:

<?xml version="1.0"?> 
<ruleset name="MyStandard"> 
    <description>My custom coding standard.</description> 
    <rule ref="Squiz.Commenting.FunctionComment" /> 
    <rule ref="Squiz.Commenting.FunctionCommentThrowTag" /> 
    <rule ref="Squiz.Commenting.ClassComment" /> 
    <rule ref="Squiz.Commenting.FileComment" /> 
    <rule ref="Squiz.Commenting.VariableComment" /> 
</ruleset> 

Quindi è possibile eseguire questo comando:

phpcs /path/to/code --standard=/path/to/mystandard.xml 

Ci sono altre cose che si possono fare in un file ruleset.xml. Vedere la documentazione qui: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml

+1

Questa risposta è del 2012. È ancora corretta. Ma vorrei aggiungere che oggi puoi anche usare l'annusamento Generic.Commenting.DocComment. Questi sniff si comportano in modo leggermente diverso, quindi scegli quello che è meglio per il tuo stile. – mkasberg

5

Nel 2017 si dispone ora di più per mangiare:

  • uno dei migliore annusa per controllare docblocks è TypeHintDeclarationSniff from SlevomatCodingStandard, funziona alla grande con PHP 7, PHP 7.1, rilasciare documenti inutilizzati, ecc .
  • inoltre è possibile fare uso di un altro strumento - PHP-CS-Fixer, lì si può trovare più fissatori, che vi aiuterà con docblock, basta cercare "doc"
Problemi correlati