The intent of this issue is to create a sniff that will highlight the incorrect use of 'id' in docblocks. The correct text is 'ID'.

Also this sniff should flag 'ids'. The correct text in this case is 'IDs'.

CommentFileSizeAuthor
#1 1821634-1-sniff-id.patch44.47 KBlars toomre

Comments

lars toomre’s picture

Status: Active » Needs review
StatusFileSize
new44.47 KB

Attached is an untested work-in-progress patch that creates a new sniff PhraseCommentSniff.php and an a bad.docblock file.

It addresses this issue, the incorrect use of 'e.g.' and 'i.e.', 'Page callback:' phrase use and form constructor/validate/submit docblocks.

As this is my first time developing any thing for PHP_CodeSniffer, I would enjoy receiving feedback on my approach.

I also could use some help with methods getHookCode(), getFormDefinitionFunctionName() and getFormFunctions(). Thanks in advance.

douggreen’s picture

This is pretty trivial using the regex rules. Why the sniff? Something like this would likely work, a couple dozen lines of code instead of 1000???

  $rules['comment_menu_callback'] = array(
    '#type' => 'regex',
    '#source' => 'comment',
    '#value' => '^\s*Menu callback',
    '#warning' => 'Menu callback should be changed to page callback.',
    '#severity' => 'minor',
  );
  $rules['comment_page_callback'] = array(
    '#type' => 'regex',
    '#source' => 'comment',
    '#value' => 'Page callback',
    '#not' => '^Page callback',
    '#warning' => 'The docblock should begin with the words Page callback, not include them mid-sentence.',
    '#severity' => 'minor',
  );

I hope this example helps. Why try this in a sniff? Coder does a bunch of lexical analysis (that phase done before parsing), so that what you get is just the stream of text you want (comment, quote, php, etc). If we really wanted to detect stuff in a docblock verses a comment, that would be very easy to add to what we already have.

klausi’s picture

Component: Code Sniffer » Coder Sniffer
Issue summary: View changes
Status: Needs review » Closed (won't fix)

Coder 7.x is frozen now and will not receive updates. Coder 8.x-2.x can be used to check code for any Drupal version, Coder 8.x-2.x also supports the phpcbf command to automatically fix conding standard errors. Please check if this issue is still relevant and reopen against that version if necessary.