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

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

Merged
merged 2 commits into from
Jan 19, 2024

Conversation

stronk7
Copy link
Member

@stronk7 stronk7 commented Jan 17, 2024

This will look for some extra information to exist in:

  • Inline TODO comments: // TODO blah, blah.
  • PHPDoc @todo comments: /** @todo blah, blah. */

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

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@             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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stronk7
Copy link
Member Author

stronk7 commented Jan 17, 2024

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 stronk7 force-pushed the todo_commenting_sniff branch 2 times, most recently from d6d7064 to 2b3e35e Compare January 17, 2024 16:24
Copy link
Member

@kabalin kabalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I agree to keep MDL default as nomal use case. Thanks for prompt solution for this issue Eloy!

@stronk7
Copy link
Member Author

stronk7 commented Jan 18, 2024

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
Copy link
Member Author

stronk7 commented Jan 18, 2024

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 stronk7 force-pushed the todo_commenting_sniff branch 2 times, most recently from 88f25b1 to 633ed49 Compare January 18, 2024 16:23
This will look for some extra information to exist in:

- Inline TODO comments: // TODO blah, blah.
- PHPDoc @todo comments: /** @todo blah, blah. */

By default it will look for all TODOs having some 'MDL-[0-9]+'
(regular expression), but it can be customised, in phpcs.xml
file or in CLI execution by setting the "commentRequiredRegex"
property 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 moodlehq#90
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 ''
Copy link
Member

@paulholden paulholden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @stronk7 super!

@stronk7 stronk7 merged commit 2fd5234 into moodlehq:main Jan 19, 2024
8 checks passed
@stronk7
Copy link
Member Author

stronk7 commented Jan 19, 2024

Thanks @paulholden and @kabalin !

@stronk7 stronk7 deleted the todo_commenting_sniff branch January 19, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verify that all the "todo" comments have an MDL issue associated
3 participants