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

Modules::RequireFilenameMatchesPackage rule is not enforced #25

Open
dseynhae opened this issue Jun 30, 2021 · 0 comments
Open

Modules::RequireFilenameMatchesPackage rule is not enforced #25

dseynhae opened this issue Jun 30, 2021 · 0 comments

Comments

@dseynhae
Copy link

I want to make sure that my module or script name matches the file name. A typo is too easy to sneak in, and sometimes I actually use a template, and forget to update the package name.

PerlCritic quickly identifies those mistakes through the [Modules::RequireFilenameMatchesPackage] rule.

However, a couple of mistakes snuck in, and were never flagged!

This is because:

  • PerlCritic will not enforce the rule if it thinks it is not dealing with a Module file
    • a Program file identified through --program-extensions
    • a Module streamed into STDIN
  • A quick scan of perlcritic/server/src/Output.ts reveals that the Perl source file is not passed as a FILE argument, but as a string piped to STDIN; So PerlCritic has no information to enforce the rule!

This can quickly be verified with an experiment, take any Perl file, where the package name does not match the file name:

perlcritic <file>
perlcritic --program-extensions .pl <file>
cat file | perlcritic

The first check will flag the name mismatch.
The second and last check will not flag the problem!

The fix is to present perlcritic with a file, rather than a string:

  • With the same name is the original file.
  • With the same content as the current string.
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

No branches or pull requests

1 participant