Skip to content

Commit

Permalink
Add a new moodleTodoCommentRegex config option
Browse files Browse the repository at this point in the history
While everything continues working the same and the
Sniff property (`commentRequiredRegex`) still is available
and defaulting to `MDL-[0-9]+`, now we can, also, from command
line, decide which regular expression to use.

That will make things easier from other tools, not having
to modify the ruleset phpcs.xml files. Instead just run:

vendor/bin/phpcs --runtime-set moodleTodoCommentRegex 'CONTRIB-[0-9]+'

or any other valid regular expression (https, github urls...)

In order to disable the Sniff, you can pass to it an empty string
(apart from excluding it completely if desired, of course)

vendor/bin/phpcs --runtime-set moodleTodoCommentRegex ''
  • Loading branch information
stronk7 committed Jan 18, 2024
1 parent 2b3e35e commit 46e2b0a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions moodle/Sniffs/Commenting/TodoCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

// phpcs:disable moodle.NamingConventions

use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

Expand Down Expand Up @@ -71,6 +72,11 @@ public function register(): array {
* @return void
*/
public function process(File $phpcsFile, $stackPtr): void {
// If specified, get the regular expression from the config.
if (($regex = Config::getConfigData('moodleTodoCommentRegex')) !== null) {
$this->commentRequiredRegex = $regex;
}

// If the regular expression is empty, then we don't want to do anything.
if (empty($this->commentRequiredRegex)) {
return;
Expand Down

0 comments on commit 46e2b0a

Please sign in to comment.