Skip to content

Commit

Permalink
Merge pull request #7 from puppetlabs/CAT-1688-Upgrade_rubocop
Browse files Browse the repository at this point in the history
(CAT-1688) Upgrade rubocop to `~> 1.50.0`
  • Loading branch information
jordanbreen28 authored Jan 23, 2024
2 parents 409c5c9 + 6cb1792 commit 1afe627
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 89 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
Include:
- 'lib/**/*.rb'
- 'puppetfile-cli.rb'
Expand Down
63 changes: 20 additions & 43 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-27 07:36:27 UTC using RuboCop version 1.48.1.
# on 2024-01-22 11:46:15 UTC using RuboCop version 1.50.2.
# 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/MissingSuper:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/parser/errors.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/DuplicateRequire:
Lint/NonAtomicFileOperation:
Exclude:
- 'lib/puppetfile-resolver/spec_searchers/git/gclone.rb'
- 'lib/puppetfile-resolver/cache/persistent.rb'

# Offense count: 1
Lint/MissingSuper:
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/OrAssignmentToConstant:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/parser/errors.rb'
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb'
- 'lib/puppetfile-resolver/spec_searchers/forge_configuration.rb'
- 'lib/puppetfile-resolver/version.rb'

# Offense count: 2
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
Expand All @@ -26,33 +34,17 @@ Naming/FileName:
- 'lib/puppetfile-resolver.rb'
- 'puppetfile-cli.rb'

# Offense count: 27
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: separated, grouped
Style/AccessorGrouping:
# Offense count: 1
Style/CombinableLoops:
Exclude:
- 'lib/puppetfile-resolver/models/module_dependency.rb'
- 'lib/puppetfile-resolver/models/module_specification.rb'
- 'lib/puppetfile-resolver/puppetfile/document.rb'
- 'lib/puppetfile-resolver/puppetfile/git_module.rb'
- 'lib/puppetfile-resolver/puppetfile/validation_errors.rb'
- '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:
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ConcatArrayLiterals:
Exclude:
- 'lib/puppetfile-resolver/util.rb'

# Offense count: 1
Style/CombinableLoops:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/document.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Expand All @@ -62,21 +54,6 @@ Style/OptionalBooleanParameter:

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantAssignment:
Style/RedundantFreeze:
Exclude:
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/local.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.
Style/StringConcatenation:
Exclude:
- 'lib/puppetfile-resolver/cache/persistent.rb'
- 'lib/puppetfile-resolver/spec_searchers/git/github.rb'
- 'lib/puppetfile-resolver/spec_searchers/git/gitlab.rb'
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ group :test do
gem 'rspec-collection_matchers', '~> 1.0'
gem 'rspec-its', '~> 1.0'

gem 'rubocop', '~> 1.48.1'
gem 'rubocop', '~> 1.50.0'
gem 'rubocop-rspec', '~> 2.19'
gem 'rubocop-performance', '~> 1.16'

Expand Down
2 changes: 1 addition & 1 deletion lib/puppetfile-resolver/cache/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def persist(name, content_string)
private

def to_cache_name(name)
::Digest::SHA256.hexdigest(name) + '.txt'
"#{::Digest::SHA256.hexdigest(name)}.txt"
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/puppetfile-resolver/models/module_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
module PuppetfileResolver
module Models
class ModuleDependency
attr_accessor :name
attr_accessor :owner
attr_accessor :version_requirement
attr_accessor :name, :owner, :version_requirement

def initialize(options = {})
# Munge the name
Expand Down
6 changes: 1 addition & 5 deletions lib/puppetfile-resolver/models/module_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
module PuppetfileResolver
module Models
class ModuleSpecification
attr_accessor :name
attr_accessor :owner
attr_accessor :version
attr_accessor :origin # Same as R10K module :type
attr_accessor :resolver_flags
attr_accessor :name, :owner, :version, :origin, :resolver_flags # origin attr same as R10K module :type

def initialize(options = {})
require 'semantic_puppet'
Expand Down
8 changes: 2 additions & 6 deletions lib/puppetfile-resolver/puppetfile/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
module PuppetfileResolver
module Puppetfile
class DocumentLocation
attr_accessor :start_line # Base 0
attr_accessor :start_char # Base 0
attr_accessor :end_line # Base 0
attr_accessor :end_char # Base 0
attr_accessor :start_line, :start_char, :end_line, :end_char # Base 0 # Base 0 # Base 0 # Base 0
end

class Document
attr_accessor :forge_uri
attr_accessor :forge_uri, :content
attr_reader :modules
attr_accessor :content

def initialize(puppetfile_content)
@content = puppetfile_content
Expand Down
5 changes: 1 addition & 4 deletions lib/puppetfile-resolver/puppetfile/git_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
module PuppetfileResolver
module Puppetfile
class GitModule < BaseModule
attr_accessor :remote
attr_accessor :ref
attr_accessor :commit
attr_accessor :tag
attr_accessor :remote, :ref, :commit, :tag

def initialize(title)
super
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 @@ -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
6 changes: 2 additions & 4 deletions lib/puppetfile-resolver/puppetfile/validation_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
module PuppetfileResolver
module Puppetfile
class DocumentValidationErrorBase
attr_accessor :message
attr_accessor :puppet_module
attr_accessor :message, :puppet_module

def initialize(message, puppet_module)
@message = message
Expand Down Expand Up @@ -79,8 +78,7 @@ def puppetfile_modules
# Resolution Validation Error classes for validating
# a valid Puppetfile against a dependency resolution
class DocumentResolutionErrorBase < DocumentValidationErrorBase
attr_accessor :puppet_module
attr_accessor :module_specification
attr_accessor :puppet_module, :module_specification

def initialize(message, puppet_module, module_specification)
super(message, puppet_module)
Expand Down
3 changes: 1 addition & 2 deletions lib/puppetfile-resolver/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

module PuppetfileResolver
class Resolver
attr_reader :puppetfile
attr_reader :dependencies_to_resolve
attr_reader :puppetfile, :dependencies_to_resolve

def initialize(puppetfile_document, puppet_version = nil)
@puppetfile = puppetfile_document
Expand Down
4 changes: 1 addition & 3 deletions lib/puppetfile-resolver/spec_searchers/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
module PuppetfileResolver
module SpecSearchers
class Configuration
attr_reader :local
attr_reader :forge
attr_reader :git
attr_reader :local, :forge, :git

def initialize
@local = LocalConfiguration.new
Expand Down
1 change: 0 additions & 1 deletion lib/puppetfile-resolver/spec_searchers/git/gclone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require 'puppetfile-resolver/util'
require 'puppetfile-resolver/spec_searchers/common'
require 'puppetfile-resolver/spec_searchers/git_configuration'
require 'puppetfile-resolver/util'
require 'uri'

module PuppetfileResolver
Expand Down
6 changes: 3 additions & 3 deletions lib/puppetfile-resolver/spec_searchers/git/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def self.metadata(puppetfile_module, resolver_ui, config)
end
return nil if repo_url.nil?

metadata_url = 'https://raw.githubusercontent.com/' + repo_url + '/'
metadata_url = "https://raw.githubusercontent.com/#{repo_url}/"
if puppetfile_module.ref
metadata_url += puppetfile_module.ref + '/'
metadata_url += "#{puppetfile_module.ref}/"
elsif puppetfile_module.tag
metadata_url += puppetfile_module.tag + '/'
metadata_url += "#{puppetfile_module.tag}/"
else
# Default to master. Should it raise?
metadata_url += 'master/'
Expand Down
6 changes: 3 additions & 3 deletions lib/puppetfile-resolver/spec_searchers/git/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def self.metadata(puppetfile_module, resolver_ui, config)

# Example URL
# https://gitlab.com/simp/pupmod-simp-crypto_policy/-/raw/0.1.4/metadata.json
metadata_url = 'https://gitlab.com/' + repo_url + '/-/raw/'
metadata_url = "https://gitlab.com/#{repo_url}/-/raw/"
if puppetfile_module.ref
metadata_url += puppetfile_module.ref + '/'
metadata_url += "#{puppetfile_module.ref}/"
elsif puppetfile_module.tag
metadata_url += puppetfile_module.tag + '/'
metadata_url += "#{puppetfile_module.tag}/"
else
# Default to master. Should it raise?
metadata_url += 'master/'
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
4 changes: 2 additions & 2 deletions puppetfile-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def self.parse(options)
end

# Parse the Puppetfile into an object model
content = File.open(options[:path], 'rb') { |f| f.read }
content = File.binread(options[:path])
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 1afe627

Please sign in to comment.