Skip to content

Commit 1afe627

Browse files
Merge pull request #7 from puppetlabs/CAT-1688-Upgrade_rubocop
(CAT-1688) Upgrade rubocop to `~> 1.50.0`
2 parents 409c5c9 + 6cb1792 commit 1afe627

18 files changed

+47
-89
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
inherit_from: .rubocop_todo.yml
22

33
AllCops:
4+
NewCops: enable
45
Include:
56
- 'lib/**/*.rb'
67
- 'puppetfile-cli.rb'

.rubocop_todo.yml

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-10-27 07:36:27 UTC using RuboCop version 1.48.1.
3+
# on 2024-01-22 11:46:15 UTC using RuboCop version 1.50.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

99
# Offense count: 1
10+
Lint/MissingSuper:
11+
Exclude:
12+
- 'lib/puppetfile-resolver/puppetfile/parser/errors.rb'
13+
14+
# Offense count: 2
1015
# This cop supports unsafe autocorrection (--autocorrect-all).
11-
Lint/DuplicateRequire:
16+
Lint/NonAtomicFileOperation:
1217
Exclude:
13-
- 'lib/puppetfile-resolver/spec_searchers/git/gclone.rb'
18+
- 'lib/puppetfile-resolver/cache/persistent.rb'
1419

15-
# Offense count: 1
16-
Lint/MissingSuper:
20+
# Offense count: 3
21+
# This cop supports unsafe autocorrection (--autocorrect-all).
22+
Lint/OrAssignmentToConstant:
1723
Exclude:
18-
- 'lib/puppetfile-resolver/puppetfile/parser/errors.rb'
24+
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb'
25+
- 'lib/puppetfile-resolver/spec_searchers/forge_configuration.rb'
26+
- 'lib/puppetfile-resolver/version.rb'
1927

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

29-
# Offense count: 27
30-
# This cop supports safe autocorrection (--autocorrect).
31-
# Configuration parameters: EnforcedStyle.
32-
# SupportedStyles: separated, grouped
33-
Style/AccessorGrouping:
37+
# Offense count: 1
38+
Style/CombinableLoops:
3439
Exclude:
35-
- 'lib/puppetfile-resolver/models/module_dependency.rb'
36-
- 'lib/puppetfile-resolver/models/module_specification.rb'
3740
- 'lib/puppetfile-resolver/puppetfile/document.rb'
38-
- 'lib/puppetfile-resolver/puppetfile/git_module.rb'
39-
- 'lib/puppetfile-resolver/puppetfile/validation_errors.rb'
40-
- 'lib/puppetfile-resolver/resolver.rb'
41-
- 'lib/puppetfile-resolver/spec_searchers/configuration.rb'
4241

4342
# Offense count: 1
44-
# This cop supports safe autocorrection (--autocorrect).
45-
# Configuration parameters: AllowedMethods, AllowedPatterns.
46-
# AllowedMethods: ==, equal?, eql?
47-
Style/ClassEqualityComparison:
43+
# This cop supports unsafe autocorrection (--autocorrect-all).
44+
Style/ConcatArrayLiterals:
4845
Exclude:
4946
- 'lib/puppetfile-resolver/util.rb'
5047

51-
# Offense count: 1
52-
Style/CombinableLoops:
53-
Exclude:
54-
- 'lib/puppetfile-resolver/puppetfile/document.rb'
55-
5648
# Offense count: 1
5749
# Configuration parameters: AllowedMethods.
5850
# AllowedMethods: respond_to_missing?
@@ -62,21 +54,6 @@ Style/OptionalBooleanParameter:
6254

6355
# Offense count: 1
6456
# This cop supports safe autocorrection (--autocorrect).
65-
Style/RedundantAssignment:
57+
Style/RedundantFreeze:
6658
Exclude:
67-
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/local.rb'
68-
69-
# Offense count: 3
70-
# This cop supports safe autocorrection (--autocorrect).
71-
Style/RedundantRegexpEscape:
72-
Exclude:
73-
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb'
74-
75-
# Offense count: 7
76-
# This cop supports unsafe autocorrection (--autocorrect-all).
77-
# Configuration parameters: Mode.
78-
Style/StringConcatenation:
79-
Exclude:
80-
- 'lib/puppetfile-resolver/cache/persistent.rb'
81-
- 'lib/puppetfile-resolver/spec_searchers/git/github.rb'
82-
- 'lib/puppetfile-resolver/spec_searchers/git/gitlab.rb'
59+
- 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/forge.rb'

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ group :test do
88
gem 'rspec-collection_matchers', '~> 1.0'
99
gem 'rspec-its', '~> 1.0'
1010

11-
gem 'rubocop', '~> 1.48.1'
11+
gem 'rubocop', '~> 1.50.0'
1212
gem 'rubocop-rspec', '~> 2.19'
1313
gem 'rubocop-performance', '~> 1.16'
1414

lib/puppetfile-resolver/cache/persistent.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def persist(name, content_string)
4343
private
4444

4545
def to_cache_name(name)
46-
::Digest::SHA256.hexdigest(name) + '.txt'
46+
"#{::Digest::SHA256.hexdigest(name)}.txt"
4747
end
4848
end
4949
end

lib/puppetfile-resolver/models/module_dependency.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
module PuppetfileResolver
44
module Models
55
class ModuleDependency
6-
attr_accessor :name
7-
attr_accessor :owner
8-
attr_accessor :version_requirement
6+
attr_accessor :name, :owner, :version_requirement
97

108
def initialize(options = {})
119
# Munge the name

lib/puppetfile-resolver/models/module_specification.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
module PuppetfileResolver
88
module Models
99
class ModuleSpecification
10-
attr_accessor :name
11-
attr_accessor :owner
12-
attr_accessor :version
13-
attr_accessor :origin # Same as R10K module :type
14-
attr_accessor :resolver_flags
10+
attr_accessor :name, :owner, :version, :origin, :resolver_flags # origin attr same as R10K module :type
1511

1612
def initialize(options = {})
1713
require 'semantic_puppet'

lib/puppetfile-resolver/puppetfile/document.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
module PuppetfileResolver
66
module Puppetfile
77
class DocumentLocation
8-
attr_accessor :start_line # Base 0
9-
attr_accessor :start_char # Base 0
10-
attr_accessor :end_line # Base 0
11-
attr_accessor :end_char # Base 0
8+
attr_accessor :start_line, :start_char, :end_line, :end_char # Base 0 # Base 0 # Base 0 # Base 0
129
end
1310

1411
class Document
15-
attr_accessor :forge_uri
12+
attr_accessor :forge_uri, :content
1613
attr_reader :modules
17-
attr_accessor :content
1814

1915
def initialize(puppetfile_content)
2016
@content = puppetfile_content

lib/puppetfile-resolver/puppetfile/git_module.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
module PuppetfileResolver
66
module Puppetfile
77
class GitModule < BaseModule
8-
attr_accessor :remote
9-
attr_accessor :ref
10-
attr_accessor :commit
11-
attr_accessor :tag
8+
attr_accessor :remote, :ref, :commit, :tag
129

1310
def initialize(title)
1411
super

lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ def self.parse(puppetfile_contents)
6565
def self.post_process_flags!(document)
6666
flag_ranges = {}
6767
document.content.lines.each_with_index do |line, index|
68-
if (matches = line.match(%r{^\s*# resolver:disable ([A-Za-z\/,]+)(?:\s|$)}))
68+
if (matches = line.match(%r{^\s*# resolver:disable ([A-Za-z/,]+)(?:\s|$)}))
6969
flags_from_line(matches[1]).each do |flag|
7070
# Start a flag range if there isn't already one going
7171
next unless flag_ranges[flag].nil?
7272
flag_ranges[flag] = index
7373
end
74-
elsif (matches = line.match(%r{# resolver:disable ([A-Za-z\/,]+)(?:\s|$)}))
74+
elsif (matches = line.match(%r{# resolver:disable ([A-Za-z/,]+)(?:\s|$)}))
7575
flags_from_line(matches[1]).each do |flag|
7676
# Assert the flag if we're not already within a range
7777
next unless flag_ranges[flag].nil?
7878
assert_resolver_flag(document, flag, index, index)
7979
end
80-
elsif (matches = line.match(%r{^\s*# resolver:enable ([A-Za-z\/,]+)(?:\s|$)}))
80+
elsif (matches = line.match(%r{^\s*# resolver:enable ([A-Za-z/,]+)(?:\s|$)}))
8181
flags_from_line(matches[1]).each do |flag|
8282
# End a flag range if there isn't already one going
8383
next if flag_ranges[flag].nil?
@@ -122,8 +122,8 @@ def self.assert_resolver_flag(document, flag, from_line, to_line)
122122
next if mod.location.start_line.nil? || mod.location.end_line.nil?
123123

124124
# If the module doesn't span the range we're looking for (from_line --> to_line) ignore it
125-
next unless mod.location.start_line >= from_line && mod.location.start_line <= to_line ||
126-
mod.location.end_line >= from_line && mod.location.end_line <= to_line
125+
next unless (mod.location.start_line >= from_line && mod.location.start_line <= to_line) ||
126+
(mod.location.end_line >= from_line && mod.location.end_line <= to_line)
127127
mod.resolver_flags << flag unless mod.resolver_flags.include?(flag)
128128
end
129129
nil

lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/local.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ def self.implements?(_name, args)
1515
end
1616

1717
def self.to_document_module(title, _args)
18-
mod = ::PuppetfileResolver::Puppetfile::LocalModule.new(title)
19-
mod
18+
::PuppetfileResolver::Puppetfile::LocalModule.new(title)
2019
end
2120
end
2221
end

lib/puppetfile-resolver/puppetfile/validation_errors.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
module PuppetfileResolver
44
module Puppetfile
55
class DocumentValidationErrorBase
6-
attr_accessor :message
7-
attr_accessor :puppet_module
6+
attr_accessor :message, :puppet_module
87

98
def initialize(message, puppet_module)
109
@message = message
@@ -79,8 +78,7 @@ def puppetfile_modules
7978
# Resolution Validation Error classes for validating
8079
# a valid Puppetfile against a dependency resolution
8180
class DocumentResolutionErrorBase < DocumentValidationErrorBase
82-
attr_accessor :puppet_module
83-
attr_accessor :module_specification
81+
attr_accessor :puppet_module, :module_specification
8482

8583
def initialize(message, puppet_module, module_specification)
8684
super(message, puppet_module)

lib/puppetfile-resolver/resolver.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
module PuppetfileResolver
99
class Resolver
10-
attr_reader :puppetfile
11-
attr_reader :dependencies_to_resolve
10+
attr_reader :puppetfile, :dependencies_to_resolve
1211

1312
def initialize(puppetfile_document, puppet_version = nil)
1413
@puppetfile = puppetfile_document

lib/puppetfile-resolver/spec_searchers/configuration.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
module PuppetfileResolver
88
module SpecSearchers
99
class Configuration
10-
attr_reader :local
11-
attr_reader :forge
12-
attr_reader :git
10+
attr_reader :local, :forge, :git
1311

1412
def initialize
1513
@local = LocalConfiguration.new

lib/puppetfile-resolver/spec_searchers/git/gclone.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require 'puppetfile-resolver/util'
66
require 'puppetfile-resolver/spec_searchers/common'
77
require 'puppetfile-resolver/spec_searchers/git_configuration'
8-
require 'puppetfile-resolver/util'
98
require 'uri'
109

1110
module PuppetfileResolver

lib/puppetfile-resolver/spec_searchers/git/github.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def self.metadata(puppetfile_module, resolver_ui, config)
1919
end
2020
return nil if repo_url.nil?
2121

22-
metadata_url = 'https://raw.githubusercontent.com/' + repo_url + '/'
22+
metadata_url = "https://raw.githubusercontent.com/#{repo_url}/"
2323
if puppetfile_module.ref
24-
metadata_url += puppetfile_module.ref + '/'
24+
metadata_url += "#{puppetfile_module.ref}/"
2525
elsif puppetfile_module.tag
26-
metadata_url += puppetfile_module.tag + '/'
26+
metadata_url += "#{puppetfile_module.tag}/"
2727
else
2828
# Default to master. Should it raise?
2929
metadata_url += 'master/'

lib/puppetfile-resolver/spec_searchers/git/gitlab.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def self.metadata(puppetfile_module, resolver_ui, config)
2121

2222
# Example URL
2323
# https://gitlab.com/simp/pupmod-simp-crypto_policy/-/raw/0.1.4/metadata.json
24-
metadata_url = 'https://gitlab.com/' + repo_url + '/-/raw/'
24+
metadata_url = "https://gitlab.com/#{repo_url}/-/raw/"
2525
if puppetfile_module.ref
26-
metadata_url += puppetfile_module.ref + '/'
26+
metadata_url += "#{puppetfile_module.ref}/"
2727
elsif puppetfile_module.tag
28-
metadata_url += puppetfile_module.tag + '/'
28+
metadata_url += "#{puppetfile_module.tag}/"
2929
else
3030
# Default to master. Should it raise?
3131
metadata_url += 'master/'

lib/puppetfile-resolver/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.static_ca_cert_file
2929
def self.net_http_get(uri, proxy = nil)
3030
uri = URI.parse(uri) unless uri.is_a?(URI)
3131

32-
http_options = { :use_ssl => uri.class == URI::HTTPS }
32+
http_options = { :use_ssl => uri.instance_of?(URI::HTTPS) }
3333
# Because on Windows Ruby doesn't use the Windows certificate store which has up-to date
3434
# CA certs, we can't depend on someone setting the environment variable correctly. So use our
3535
# static CA PEM file if SSL_CERT_FILE is not set.

puppetfile-cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def self.parse(options)
7272
end
7373

7474
# Parse the Puppetfile into an object model
75-
content = File.open(options[:path], 'rb') { |f| f.read }
75+
content = File.binread(options[:path])
7676
require 'puppetfile-resolver/puppetfile/parser/r10k_eval'
77-
puppetfile = ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)
77+
puppetfile = PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)
7878

7979
# Make sure the Puppetfile is valid
8080
unless puppetfile.valid?

0 commit comments

Comments
 (0)