Skip to content

Commit

Permalink
Enforce Regexp style with rubocop
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
robertcheramy committed Sep 10, 2024
1 parent e6b474f commit aabbd3d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Layout/LineLength:
Enabled: false

Lint/AmbiguousRegexpLiteral:
Enabled: false
Enabled: true
Exclude:
- lib/oxidized/model/*.rb

Lint/RaiseException:
Enabled: true
Expand Down Expand Up @@ -61,6 +63,10 @@ Style/HashTransformKeys:
Style/HashTransformValues:
Enabled: true

Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true

Style/RescueModifier:
Enabled: false

Expand Down
11 changes: 2 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/oxidized/model/aosw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
4 changes: 2 additions & 2 deletions lib/oxidized/model/garderos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion lib/oxidized/model/nodegrid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Nodegrid < Oxidized::Model
# ZPE Nodegrid (Tested with Nodegrid Gate/Bold/NSR)
# https://www.zpesystems.com/products/

prompt(%r{(?<!@)\[(.*?\s/)\]#})
prompt /(?<!@)\[(.*?\s\/)\]#/
comment '# '

cmd 'show system/about/' do |cfg|
Expand Down
2 changes: 1 addition & 1 deletion oxidized.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.summary = 'feeble attempt at rancid'
s.description = 'software to fetch configuration from network devices and store them'
s.rubyforge_project = s.name
s.files = %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
s.files = %x(git ls-files -z).split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }
s.executables = %w[oxidized]
s.require_path = 'lib'

Expand Down

0 comments on commit aabbd3d

Please sign in to comment.