From aabbd3d4ffcf55919add8afd78de795b98949e88 Mon Sep 17 00:00:00 2001 From: Robert Cheramy Date: Tue, 10 Sep 2024 09:54:32 +0200 Subject: [PATCH 1/2] Enforce Regexp style with rubocop - Closes: #3261 - Activates Rubocop Lint/AmbiguousRegexpLiteral, with exception of the models. - The models keep their DSL-Syntax and we accept the ambiguity between regexp and two divisions there - ruby chooses the regexp. For this, we disable warnings in minitest (rake test). Corrects modesls without DSL-Syntax for the prompt. - Most of the regexp in oxidized follow the style slashes with inner slashes allowed. Activate rubocop Style/RegexpLiteral with these options and correct the few regexp not following this style. --- .rubocop.yml | 8 +++++++- .rubocop_todo.yml | 11 ++--------- Rakefile | 5 +++-- lib/oxidized/model/aosw.rb | 2 +- lib/oxidized/model/garderos.rb | 4 ++-- lib/oxidized/model/nodegrid.rb | 2 +- oxidized.gemspec | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f03080f29..9c0222e45 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,7 +20,9 @@ Layout/LineLength: Enabled: false Lint/AmbiguousRegexpLiteral: - Enabled: false + Enabled: true + Exclude: + - lib/oxidized/model/*.rb Lint/RaiseException: Enabled: true @@ -61,6 +63,10 @@ Style/HashTransformKeys: Style/HashTransformValues: Enabled: true +Style/RegexpLiteral: + EnforcedStyle: slashes + AllowInnerSlashes: true + Style/RescueModifier: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d4dbd9882..2407e1d1a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-07-05 13:13:46 UTC using RuboCop version 1.64.1. +# on 2024-09-10 07:42:30 UTC using RuboCop version 1.65.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -72,19 +72,12 @@ Style/OpenStructUse: - 'lib/oxidized/node.rb' - 'spec/hook/githubrepo_spec.rb' -# Offense count: 48 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Enabled: false - # Offense count: 31 # This cop supports unsafe autocorrection (--autocorrect-all). Style/SlicingWithRange: Enabled: false -# Offense count: 83 +# Offense count: 84 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Mode. Style/StringConcatenation: diff --git a/Rakefile b/Rakefile index a69fd858b..b79320593 100644 --- a/Rakefile +++ b/Rakefile @@ -27,7 +27,8 @@ task :test do Rake::TestTask.new do |t| t.libs << 'spec' t.test_files = FileList['spec/**/*_spec.rb'] - t.warning = true + # Don't display ambiguity warning between regexp and division in models + t.warning = false t.verbose = true end end @@ -75,7 +76,7 @@ task :chmod do extra/update-ca-certificates.runit ] dirs = [] - %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }.each do |file| + %x(git ls-files -z).split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }.each do |file| dirs.push(File.dirname(file)) xbit.include?(file) ? File.chmod(0o0755, file) : File.chmod(0o0644, file) end diff --git a/lib/oxidized/model/aosw.rb b/lib/oxidized/model/aosw.rb index 2ed0b853a..5aba15fd5 100644 --- a/lib/oxidized/model/aosw.rb +++ b/lib/oxidized/model/aosw.rb @@ -13,7 +13,7 @@ class AOSW < Oxidized::Model comment '# ' # see /spec/model/aosw_spec.rb for prompt examples - prompt(/^\(?[\w\:.@-]+\)? ?[*^]?(\[[\w\/]+\] ?)?[#>] ?$/) + prompt /^\(?[\w\:.@-]+\)? ?[*^]?(\[[\w\/]+\] ?)?[#>] ?$/ # Ignore cariage returns - also for the prompt expect "\r" do |data, re| diff --git a/lib/oxidized/model/garderos.rb b/lib/oxidized/model/garderos.rb index dd46999dd..10996f015 100644 --- a/lib/oxidized/model/garderos.rb +++ b/lib/oxidized/model/garderos.rb @@ -6,11 +6,11 @@ class Garderos < Oxidized::Model # remove all ANSI escape codes, as GRS uses them :-( # the prompt does not need to match escape codes, as they have been removed - expect %r{\e\[\d*m\r?} do |data, re| + expect /\e\[\d*m\r?/ do |data, re| data.gsub re, '' end - prompt %r{[\w-]+# } + prompt /[\w-]+# / comment '# ' cmd :all do |cfg| diff --git a/lib/oxidized/model/nodegrid.rb b/lib/oxidized/model/nodegrid.rb index 771fc9de3..d78233180 100644 --- a/lib/oxidized/model/nodegrid.rb +++ b/lib/oxidized/model/nodegrid.rb @@ -4,7 +4,7 @@ class Nodegrid < Oxidized::Model # ZPE Nodegrid (Tested with Nodegrid Gate/Bold/NSR) # https://www.zpesystems.com/products/ - prompt(%r{(? Date: Tue, 10 Sep 2024 10:01:57 +0200 Subject: [PATCH 2/2] Comment why Lint/AmbiguousRegexpLiteral is not activated on the models --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 9c0222e45..7931529b7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,6 +19,8 @@ Style/FrozenStringLiteralComment: Layout/LineLength: Enabled: false +# We do not enforce the cop in the models as it would not work with the +# DSL style of the models Lint/AmbiguousRegexpLiteral: Enabled: true Exclude: