From fd0d63d5c768563138e80dfe647dbf32234c3c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Fri, 9 Aug 2024 22:16:02 +0200 Subject: [PATCH] Use perlcritic wrapper and plugins from common repo Issue: https://progress.opensuse.org/issues/155188 --- .perlcriticrc | 48 +++++++++++++++++-- Makefile | 2 +- .../Perl/Critic/Policy/HashKeyQuotes.pm | 32 ------------- tools/perlcritic | 1 + 4 files changed, 46 insertions(+), 37 deletions(-) delete mode 100644 lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm create mode 120000 tools/perlcritic diff --git a/.perlcriticrc b/.perlcriticrc index e6dd3ae5b4e2..0addc1f493b2 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -1,9 +1,49 @@ -theme = freenode +theme = community + openqa severity = 4 +include = strict ValuesAndExpressions::ProhibitInterpolationOfLiterals -# TODO: Remove once Perl::Critic::Freenode 0.028 is widely available -[Freenode::DiscouragedModules] +verbose = ::warning file=%f,line=%l,col=%c,title=%m - severity %s::[%p] %e\n + +# == Perlcritic Policies +# -- Test::Most brings in strict & warnings +[TestingAndDebugging::RequireUseStrict] +equivalent_modules = Test::Most + +[TestingAndDebugging::RequireUseWarnings] +equivalent_modules = Test::Most + +# -- Avoid double quotes unless there's interpolation or a single quote. +[ValuesAndExpressions::ProhibitInterpolationOfLiterals] +allow_if_string_contains_single_quote = 1 severity = 3 -[Perl::Critic::Policy::HashKeyQuotes] +# -- Prohibit deep nesting +[ControlStructures::ProhibitDeepNests] +severity = 4 +add_themes = community +max_nests = 4 + +# == Community Policies +# -- Test::Most brings in strict & warnings +[Freenode::StrictWarnings] +extra_importers = Test::Most + +# -- Test::Most brings in strict & warnings +[Community::StrictWarnings] +extra_importers = Test::Most + +[Community::DiscouragedModules] +severity = 3 + +# Test modules have no package declaration +[Community::PackageMatchesFilename] +severity = 1 + +# == Custom Policies +# -- Useless quotes on hashes +[HashKeyQuotes] severity = 5 + +# -- Superfluous use strict/warning. +[RedundantStrictWarning] +equivalent_modules = Test::Most diff --git a/Makefile b/Makefile index 9738f2e9736e..0d6ad6fb7ffb 100644 --- a/Makefile +++ b/Makefile @@ -290,7 +290,7 @@ endif .PHONY: test-critic test-critic: - PERL5LIB=lib/perlcritic:$$PERL5LIB perlcritic lib + perlcritic lib .PHONY: test-tidy-compile test-tidy-compile: diff --git a/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm b/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm deleted file mode 100644 index 126816103b95..000000000000 --- a/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm +++ /dev/null @@ -1,32 +0,0 @@ -package Perl::Critic::Policy::HashKeyQuotes; - - -use Mojo::Base 'Perl::Critic::Policy'; - -use Perl::Critic::Utils qw( :severities :classification :ppi ); - -our $VERSION = '0.0.1'; - -sub default_severity { return $SEVERITY_HIGH } -sub default_themes { return qw(openqa) } -sub applies_to { return qw(PPI::Token::Quote::Single PPI::Token::Quote::Double) } - -# check that hashes are not overly using quotes -# (os-autoinst coding style) - -sub violates { - my ($self, $elem) = @_; - - #we only want the check hash keys - return if !is_hash_key($elem); - - my $c = $elem->content; - # special characters - return if $c =~ m/[- \/<>.=_:\\\$]/; - - my $desc = q{Hash key with quotes}; - my $expl = q{Avoid useless quotes}; - return $self->violation($desc, $expl, $elem); -} - -1; diff --git a/tools/perlcritic b/tools/perlcritic new file mode 120000 index 000000000000..cf46f548eb44 --- /dev/null +++ b/tools/perlcritic @@ -0,0 +1 @@ +../external/os-autoinst-common/tools/perlcritic \ No newline at end of file