Skip to content

Commit

Permalink
Correct safe offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasAud committed Jan 19, 2024
1 parent 4b0f24c commit aef63f1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 48 deletions.
38 changes: 0 additions & 38 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/DuplicateRequire:
Expand Down Expand Up @@ -60,14 +54,6 @@ Style/AccessorGrouping:
- 'lib/puppetfile-resolver/resolver.rb'
- 'lib/puppetfile-resolver/spec_searchers/configuration.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedMethods, AllowedPatterns.
# AllowedMethods: ==, equal?, eql?
Style/ClassEqualityComparison:
Exclude:
- 'lib/puppetfile-resolver/util.rb'

# Offense count: 1
Style/CombinableLoops:
Exclude:
Expand All @@ -92,30 +78,6 @@ Style/OptionalBooleanParameter:
Exclude:
- 'lib/puppetfile-resolver/cache/base.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantAssignment:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/local.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantConstantBase:
Exclude:
- 'puppetfile-cli.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantFreeze:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpEscape:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb'

# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Expand Down
10 changes: 5 additions & 5 deletions lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ def self.parse(puppetfile_contents)
def self.post_process_flags!(document)
flag_ranges = {}
document.content.lines.each_with_index do |line, index|
if (matches = line.match(%r{^\s*# resolver:disable ([A-Za-z\/,]+)(?:\s|$)}))
if (matches = line.match(%r{^\s*# resolver:disable ([A-Za-z/,]+)(?:\s|$)}))
flags_from_line(matches[1]).each do |flag|
# Start a flag range if there isn't already one going
next unless flag_ranges[flag].nil?
flag_ranges[flag] = index
end
elsif (matches = line.match(%r{# resolver:disable ([A-Za-z\/,]+)(?:\s|$)}))
elsif (matches = line.match(%r{# resolver:disable ([A-Za-z/,]+)(?:\s|$)}))
flags_from_line(matches[1]).each do |flag|
# Assert the flag if we're not already within a range
next unless flag_ranges[flag].nil?
assert_resolver_flag(document, flag, index, index)
end
elsif (matches = line.match(%r{^\s*# resolver:enable ([A-Za-z\/,]+)(?:\s|$)}))
elsif (matches = line.match(%r{^\s*# resolver:enable ([A-Za-z/,]+)(?:\s|$)}))
flags_from_line(matches[1]).each do |flag|
# End a flag range if there isn't already one going
next if flag_ranges[flag].nil?
Expand Down Expand Up @@ -122,8 +122,8 @@ def self.assert_resolver_flag(document, flag, from_line, to_line)
next if mod.location.start_line.nil? || mod.location.end_line.nil?

# If the module doesn't span the range we're looking for (from_line --> to_line) ignore it
next unless mod.location.start_line >= from_line && mod.location.start_line <= to_line ||
mod.location.end_line >= from_line && mod.location.end_line <= to_line
next unless (mod.location.start_line >= from_line && mod.location.start_line <= to_line) ||
(mod.location.end_line >= from_line && mod.location.end_line <= to_line)
mod.resolver_flags << flag unless mod.resolver_flags.include?(flag)
end
nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.valid_version?(value)
REGEX_PRE = '(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Prerelease
REGEX_BUILD = '(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Build
REGEX_FULL = REGEX_NUMERIC + REGEX_PRE + REGEX_BUILD.freeze
REGEX_FULL_RX = /\A#{REGEX_FULL}\Z/.freeze
REGEX_FULL_RX = /\A#{REGEX_FULL}\Z/

Check failure on line 33 in lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7 | puppet ~> 7.0 - windows-latest) / spec

Style/MutableConstant: Freeze mutable objects assigned to constants.

Check failure on line 33 in lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2 | puppet ~> 8.0 - ubuntu-latest) / spec

Style/MutableConstant: Freeze mutable objects assigned to constants.

Check failure on line 33 in lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7 | puppet ~> 7.0 - ubuntu-latest) / spec

Style/MutableConstant: Freeze mutable objects assigned to constants.

Check failure on line 33 in lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2 | puppet ~> 8.0 - windows-latest) / spec

Style/MutableConstant: Freeze mutable objects assigned to constants.

def self.valid_version_string?(value)
match = value.match(REGEX_FULL_RX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def self.implements?(_name, args)
end

def self.to_document_module(title, _args)
mod = ::PuppetfileResolver::Puppetfile::LocalModule.new(title)
mod
::PuppetfileResolver::Puppetfile::LocalModule.new(title)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppetfile-resolver/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.static_ca_cert_file
def self.net_http_get(uri, proxy = nil)
uri = URI.parse(uri) unless uri.is_a?(URI)

http_options = { :use_ssl => uri.class == URI::HTTPS }
http_options = { :use_ssl => uri.instance_of?(URI::HTTPS) }
# Because on Windows Ruby doesn't use the Windows certificate store which has up-to date
# CA certs, we can't depend on someone setting the environment variable correctly. So use our
# static CA PEM file if SSL_CERT_FILE is not set.
Expand Down
2 changes: 1 addition & 1 deletion puppetfile-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def self.parse(options)
# Parse the Puppetfile into an object model
content = File.open(options[:path], 'rb') { |f| f.read }
require 'puppetfile-resolver/puppetfile/parser/r10k_eval'
puppetfile = ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)
puppetfile = PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)

# Make sure the Puppetfile is valid
unless puppetfile.valid?
Expand Down

0 comments on commit aef63f1

Please sign in to comment.