From d85ab79bb1cf8ecc464cc7d61af0fa05e585af48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Mon, 12 Aug 2024 12:51:27 +0200 Subject: [PATCH 1/2] git subrepo pull (merge) external/os-autoinst-common subrepo: subdir: "external/os-autoinst-common" merged: "1d112bbfb" upstream: origin: "git@github.com:os-autoinst/os-autoinst-common.git" branch: "master" commit: "c9346faed" git-subrepo: version: "0.4.6" origin: "git@github.com:ingydotnet/git-subrepo" commit: "110b9eb" --- external/os-autoinst-common/.gitrepo | 2 +- .../lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm | 4 +++- external/os-autoinst-common/tools/perlcritic | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/external/os-autoinst-common/.gitrepo b/external/os-autoinst-common/.gitrepo index c2e8b5c8502..40ba88a8d5d 100644 --- a/external/os-autoinst-common/.gitrepo +++ b/external/os-autoinst-common/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = git@github.com:os-autoinst/os-autoinst-common.git branch = master - commit = 9a505a76f9835862211cdf59e07e2a3865320f49 + commit = c9346faed0e4a2516ccbb2c6253804ac8cf5066d parent = 549ee3ba37e2e65335466e39899ac4321028a01a method = merge cmdver = 0.4.6 diff --git a/external/os-autoinst-common/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm b/external/os-autoinst-common/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm index 8290eab50a3..1f27af44e62 100644 --- a/external/os-autoinst-common/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm +++ b/external/os-autoinst-common/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm @@ -23,7 +23,9 @@ sub violates ($self, $elem, $document) { # skip anything that's not a hash key return () unless is_hash_key($elem); - my $k = $elem->literal; + # only some PPI::Token::Quote::* classes implement literal + my $k = $elem->can('literal') ? $elem->literal : $elem->string; + # skip anything that has a special symbol in the content return () unless $k =~ m/^\w+$/; diff --git a/external/os-autoinst-common/tools/perlcritic b/external/os-autoinst-common/tools/perlcritic index 80b85b4785f..07350a95f75 100755 --- a/external/os-autoinst-common/tools/perlcritic +++ b/external/os-autoinst-common/tools/perlcritic @@ -5,6 +5,7 @@ # perlcritic with auto-injection of custom perlcritic rules. use strict; use warnings; +use v5.10; use experimental 'signatures'; use FindBin '$Bin'; @@ -16,5 +17,8 @@ sub extra_include_paths (@extra_paths) { } $ENV{PERL5LIB} = join(':', (extra_include_paths('lib/perlcritic'), $ENV{PERL5LIB} // '')); - +unless (@ARGV) { + say "Usage: $0 files-or-directories"; + exit; +} exec 'perlcritic', @ARGV; From 5aaa344280a6ea66507b3a43be694cf37f809c02 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 2/2] 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 e6dd3ae5b4e..0addc1f493b 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 9738f2e9736..0d6ad6fb7ff 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 126816103b9..00000000000 --- 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 00000000000..cf46f548eb4 --- /dev/null +++ b/tools/perlcritic @@ -0,0 +1 @@ +../external/os-autoinst-common/tools/perlcritic \ No newline at end of file