moodlehq / moodle-cs

Moodle Coding Style
https://github.com/moodlehq/moodle-cs
GNU General Public License v3.0
18 stars 16 forks source link

Check TODO and @todo comments looking for extra info #91

Closed stronk7 closed 10 months ago

stronk7 commented 10 months ago

This will look for some extra information to exist in:

By default it will look for all TODOs having some 'MDL-[0-9]+' (regular expression), but it can be customised, in ruleset , phpcs.xml file or in CLI execution by setting the $commentRequiredRegex property or the moodleTodoCommentRegex configuration option to any alternative regular expression.

Setting it to empty string will disable the sniff at all effects, useful for non-core stuff like plugins.

Fixes #90

codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (95a21b7) 96.46% compared to head (644bdd2) 96.59%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #91 +/- ## ============================================ + Coverage 96.46% 96.59% +0.12% - Complexity 517 537 +20 ============================================ Files 22 23 +1 Lines 1471 1525 +54 ============================================ + Hits 1419 1473 +54 Misses 52 52 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

stronk7 commented 10 months ago

I've created these 2 issues (CiBoT and moodle-plugin-ci) to avoid this new sniff to be executed for plugins, it's only for core:

stronk7 commented 10 months ago

Ok, please don't merge this yet.

We need to change this Sniff commentRequiredRegex property to become a configuration option.

That way other tools can use --runtime-set (and others) in command line to get that aspect configured (without having to play with ruleset or phpcs.xml files).

Ciao :-)

stronk7 commented 10 months ago

Ok, I've added a new, 3rd commit, that adds the possibility of using a config setting to specify the desired regex to be used.

Add a new moodleTodoCommentRegex config option

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 ''

stronk7 commented 10 months ago

Thanks @paulholden and @kabalin !