Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sniff for FIXME comments as errors to TodoSniff. #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CodeSniffer/Standards/Generic/Sniffs/Commenting/TodoSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addWarning($error, $stackPtr, $type, $data);
}

if (preg_match('|[^a-z]+fixme[^a-z]+(.*)|i', $content, $matches) !== 0) {
// Clear whitespace and some common characters not required at
// the end of a to-do message to make the warning more informative.
$type = 'FixmeCommentFound';
$todoMessage = trim($matches[1]);
$todoMessage = trim($todoMessage, '[]().');
$error = 'Comment refers to a FIXME task';
$data = array($todoMessage);
if ($todoMessage !== '') {
$type = 'FixmeTaskFound';
$error .= ' "%s"';
}

$phpcsFile->addError($error, $stackPtr, $type, $data);
}

}//end process()


Expand Down
22 changes: 22 additions & 0 deletions CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,26 @@ Debug::bam('test');
// To do this, use a function!
// notodo! NOTODO! NOtodo!
//TODO.

/**
* FIXME: really need to fix this before I commit.
*
*/

// FIXME: this is broken, don't forget to fix it
error_log('test');

// FIXME remove this.
Debug::bam('test');

// fixme - fix this.

// Extract info from the array.
// FIXME: this is just a stub, fill in later

// Extract info from the array (fixme: finish later)
// To do this, use a function!
// nofixme! NOFIXME! NOfixme!
//FIXME.

?>
21 changes: 21 additions & 0 deletions CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,25 @@ alert('test');
// To do this, use a function!
// notodo! NOTODO! NOtodo!
//TODO.

/**
* FIXME: Write this comment
*
*/

// FIXME: remove this.
alert('test');

// FIXME remove this.
alert('test');

// fixme - remove this.

// Extract info from the array.
// FIXME: can this be done faster?

// Extract info from the array (fixme: make it faster)
// To do this, use a function!
// nofixme! NOFIXME! NOfixme!
//FIXME.
?>
28 changes: 27 additions & 1 deletion CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,33 @@ class Generic_Tests_Commenting_TodoUnitTest extends AbstractSniffUnitTest
*/
public function getErrorList($testFile='TodoUnitTest.inc')
{
return array();
switch ($testFile) {
case 'TodoUnitTest.inc':
return array(
24 => 1,
28 => 1,
31 => 1,
34 => 1,
37 => 1,
39 => 1,
42 => 1,
);
break;
case 'TodoUnitTest.js':
return array(
24 => 1,
28 => 1,
31 => 1,
34 => 1,
37 => 1,
39 => 1,
42 => 1,
);
break;
default:
return array();
break;
}//end switch

}//end getErrorList()

Expand Down