Skip to content

Make code meet perlcritic severity level 4. - #3126

Merged
Alex-Jordan merged 1 commit into
openwebwork:developfrom
drgrice1:perlcritic-workflow
Aug 12, 2026
Merged

Alex-Jordan merged 1 commit into
openwebwork:developfrom
drgrice1:perlcritic-workflow

Conversation

@drgrice1

Copy link
Copy Markdown
Member

This adds a GitHub workflow that checks that Perl files in the lib directory satisfy perlcritic with the .perlcriticrc file included in this pull request.

I have been working toward this for years now (since December of 2022 according to the date on this commit). Originally there were are large number of changes to files. At this point, there are not so many, so I think it is time for this to go in.

Note there are some things that can't be helped (particularly with safe mode code). So those are disabled with ## no critic annotations. Almost every method in the lib/WeBWorK/DB.pm file breaks the Subroutines::RequireArgUnpacking rule, and so that is disabled for the entire file.

Note that if no critic annotations are added to the code, they should be specific and disable only the rule or rules that are to be ignored, and those rules should usually be enabled again later in the file after the rule breaking code. Other than the annotations already added in this pull request, this is generally something that should be avoided.

@drgrice1
drgrice1 force-pushed the perlcritic-workflow branch 2 times, most recently from 69e3983 to 8b30a4b Compare August 10, 2026 22:10
This adds a GitHub workflow that checks that Perl files in the `lib`
directory satisfy perlcritic with the `.perlcriticrc` file included in
this pull request.

I have been working toward this for years now (since December of 2022
according to the date on this commit).  Originally there were are large
number of changes to files.  At this point, there are not so many, so I
think it is time for this to go in.

Note there are some things that can't be helped (particularly with safe
mode code).  So those are disabled with `## no critic` annotations.
Almost every method in the `lib/WeBWorK/DB.pm` file breaks the
`Subroutines::RequireArgUnpacking` rule, and so that is disabled for the
entire file.

Note that if `no critic` annotations are added to the code, they should
be specific and disable only the rule or rules that are to be ignored,
and those rules should usually be enabled again later in the file after
the rule breaking code. Other than the annotations already added in this
pull request, this is generally something that should be avoided.
@drgrice1
drgrice1 force-pushed the perlcritic-workflow branch from 8b30a4b to 92be955 Compare August 10, 2026 22:10

@somiaj somiaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, all files pass perlcritic ./lib.

I notice the work flow isn't testing perl (.pm and .pl) files in ./bin and only files in ./lib. Should the perl files in ./bin be tested as well?

@drgrice1

Copy link
Copy Markdown
Member Author

Yes, it is intentionally only testing files in ./lib. That is because many of the scripts in the ./bin directory still need a lot of work. You can test it. Just run perlcritic ./bin. You will see lots of issues on some files. Eventually, we will fix those and add those to be checked.

@Alex-Jordan
Alex-Jordan merged commit f87fb17 into openwebwork:develop Aug 12, 2026
2 checks passed
@drgrice1
drgrice1 deleted the perlcritic-workflow branch August 12, 2026 10:56
drgrice1 added a commit to drgrice1/webwork2 that referenced this pull request Aug 13, 2026
…itGrade.pm`.

This was missed in openwebwork#3126.  The `WeBWorK::Debug` package no longer
exports the `debug` method by default, and it must be explicitly
imported where needed.

This was also missing in the `lib/WeBWorK/File/SetDef.pm` file.

I have checked all cases, and these are the only ones.
drgrice1 added a commit to drgrice1/webwork2 that referenced this pull request Oct 14, 2026
I change the name of the method that writes the tags of a
`WeBWorK::Utils::Tags` object to its problem file from `write` to
`write_to_file` in openwebwork#3126.  However, I didn't change the method name in
place where this method was called in the `WeBWorK::Utils::ListingDB`
package. As a result writing tags fails.

Note that the method name `write` does not pass the
`Subroutines::ProhibitBuiltinHomonyms` policy.  However, it only fails
the policy with the caveat explicitly stated in their documentation
which states "It is reasonable to declare an object method with the same
name as a Perl built-in function, since they are easily distinguished
from each other. However, at this time, Perl::Critic cannot tell whether
a subroutine is static or an object method." This is one of my
annoyances with that rule.  It is generally a good rule, but it can't be
implemented well.  So the fix implemented here is to rename the method
back to `write`, since it is a perfectly good object method name, and
add `## no critic (Subroutines::ProhibitBuiltinHomonyms)` to the line.
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.

3 participants