logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Perl::Critic::Policy::Miscellanea::TextDomainUnused - check for Locale::TextDomain imported but unused

Description

       This policy is part of the "Perl::Critic::Pulp" add-on.  It reports when you have "Locale::TextDomain"
       like

           use Locale::TextDomain ('MyMessageDomain');

       but then don't use any of its functions or variables

           __ __x __n __nx __xn
           __p __px __np __npx
           N__ N__n N__p N__np
           %__ $__

       "Locale::TextDomain" is not needed when not used, but it's also not actively harmful so this policy is
       only low severity and under the "cosmetic" theme (see "POLICY THEMES" in Perl::Critic).

       The check is good if you've got "Locale::TextDomain" as boilerplate code in most of your program, but in
       some modules it's unused.  You can remove it entirely from non-interactive modules, or comment it out
       from modules which might have messages but don't yet.  The best thing picked up is when your boilerplate
       has got into a programmatic module which shouldn't say anything at the user level.

       The saving from removing unused "Locale::TextDomain" is modest, just some imports and a hash entry
       holding the "textdomain" for the package.

       It's easy to imagine a general kind of "module imported but unused" policy check, but in practice its
       hard for perlcritic to know the automatic imports of every module, and quite a few modules have side-
       effects, so this TextDomainUnused policy just starts with one case of an unused include.

   InterpolatedVariables
       The variables "%__" and "$__" are recognised in double-quote interpolated strings just by looking for a
       "$__" somewhere in the string, eg.

           print "*** $__{'A Message'} ***\n";  # ok

       It's not hard to trick the recognition with escapes, or a hash slice style, but in general taking any
       "$__" to be a TextDomain use is close enough.  (Perhaps in the future PPI will do a full parse of
       interpolated expressions.)

Home Page

Name

       Perl::Critic::Policy::Miscellanea::TextDomainUnused - check for Locale::TextDomain imported but unused

See Also

       Perl::Critic::Pulp, Perl::Critic, Locale::TextDomain,
       Perl::Critic::Policy::Miscellanea::TextDomainPlaceholders

See Also