Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CONT-811) Add Ruby 3.2 support and Remove support for Ruby 2.5 #113

Merged
merged 56 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bbbbd6e
(CONT-811) Correct initial cops
GSPatton Mar 28, 2023
03ec6ff
(CONT-811) Correct Gemspec/RequireMFA
GSPatton Mar 28, 2023
61c10fe
(CONT-811) Correct Layout/IndentationConsistency
GSPatton Mar 28, 2023
bdf1d46
(CONT-811) Correct Layout/LineContinuationSpacing
GSPatton Mar 28, 2023
cf3edb9
(CONT-811) Correct Performance/StringIdentifierArgument
GSPatton Mar 28, 2023
9f3d8c4
(CONT-811) Correct Performance/StringInclude
GSPatton Mar 28, 2023
1399d01
(CONT-811) Correct RSpec/BeEq
GSPatton Mar 28, 2023
02757e9
(CONT-811) Correct RSpec/ExcessiveDocstringSpacing
GSPatton Mar 28, 2023
184ca8a
(CONT-811) Correct Security/IoMethods
GSPatton Mar 28, 2023
377b350
(CONT-811) disabling Style/ClassAndModuleChildren issues
GSPatton Mar 28, 2023
ac37821
(CONT-811) Correcting Style/EnvHome
GSPatton Mar 28, 2023
fbb2e5f
(CONT-811) Correct Style/FetchEnvVar
GSPatton Mar 28, 2023
24ae532
(CONT-811) Correct Style/RedundantConstantBase
GSPatton Mar 28, 2023
e5b7577
(CONT-811) Correcting Style/RedundantStringEscape
GSPatton Mar 28, 2023
e7912bf
(CONT-811) Correct Style/SafeNavigation
GSPatton Mar 28, 2023
9adc842
(CONT-811) Correct Style/TernaryParentheses
GSPatton Mar 28, 2023
2a292f6
(CONT-811) Updating rubocop and associated gems versions
GSPatton Mar 28, 2023
c8d98ef
(CONT-811) Adding ruby 3.2 to workflow test matrices
GSPatton Mar 29, 2023
1c19e5e
(CONT-811) Enabling all cops. Removing all unconfigured cops. Includi…
GSPatton Mar 29, 2023
2111c6d
(CONT-811) Adding rubocop_todo
GSPatton Mar 29, 2023
8de3c98
(CONT-811) Dropping Ruby 2.5 from tests as Puppet 6 will not be suppo…
GSPatton Mar 29, 2023
8a90792
(CONT-811) Raising minimum required ruby version in gemspec
GSPatton Mar 29, 2023
d39a1d0
(CONT-811) Correct Layout/EmptyLineAfterGuardClause
GSPatton Mar 29, 2023
5fe25d1
(CONT-811) Correct Layout/HashAlignment
GSPatton Mar 29, 2023
efd1526
(CONT-811) Correct Lint/ConstantDefinitionInBlock
GSPatton Mar 30, 2023
823b654
(CONT-811) Correct Lint/NonDeterministicRequireOrder
GSPatton Apr 3, 2023
8925d84
(CONT-811) Correct Lint/RedundantRequireStatement
GSPatton Apr 3, 2023
d96c164
(CONT-811) Correct Performance/BindCall
GSPatton Apr 3, 2023
65f6bfd
(CONT-811) Correct Performance/DeletePrefix
GSPatton Apr 3, 2023
13de8bb
(CONT-811) Correct RSpec/ContextMethod
GSPatton Apr 3, 2023
d23da53
(CONT-811) Correct RSpec/EmptyLineAfterExample
GSPatton Apr 3, 2023
b660434
(CONT-811) Correct RSpec/EmptyLineAfterExampleGroup
GSPatton Apr 3, 2023
034715a
(CONT-811) Correct RSpec/ImplicitSubject
GSPatton Apr 3, 2023
92c35b9
(CONT-811) Correct NamedSubject
GSPatton Apr 3, 2023
5e11a79
(CONT-811) Correct RSpec/MultipleSubjects
GSPatton Apr 3, 2023
5e59789
(CONT-811) Correct RSpec/PredicateMatcher
GSPatton Apr 3, 2023
085adb6
(CONT-811) Correct Style/AccessorGrouping
GSPatton Apr 3, 2023
95ef207
(CONT-811) Correct Style/CaseLikeIf
GSPatton Apr 3, 2023
23be6dd
(CONT-811) Correct Style/Encoding
GSPatton Apr 3, 2023
4a541e6
(CONT-811) Correct Style/ExpandPathArguments
GSPatton Apr 3, 2023
27d02ae
(CONT-811) Correct Style/ExplicitBlockArgument
GSPatton Apr 3, 2023
06e66c5
(CONT-811) Correct Style/HashAsLastArrayItem
GSPatton Apr 3, 2023
662d0ab
(CONT-811) Correct Style/IfUnlessModifier
GSPatton Apr 3, 2023
42b2805
(CONT-811) Correct Style/NumericPredicate
GSPatton Apr 3, 2023
69f3071
(CONT-811) Correct Style/RedundantArgument
GSPatton Apr 3, 2023
826d33a
(CONT-811) Correct Style/RedundantRegexpEscape
GSPatton Apr 3, 2023
2b071f0
(CONT-811) Correct Style/RescueStandardError
GSPatton Apr 3, 2023
47f4258
(CONT-811) Correct Style/SlicingWithRange
GSPatton Apr 3, 2023
fc8dae6
(CONT-811) Correct Style/SoleNestedConditional
GSPatton Apr 3, 2023
3c74505
(CONT-811) Correct Style/StderrPuts
GSPatton Apr 3, 2023
96e4122
(CONT-811) Correct Style/TrailingCommaInHashLiteral
GSPatton Apr 3, 2023
fec1244
(CONT-811) Correct Style/UnpackFirst
GSPatton Apr 3, 2023
a3a0a10
(CONT-811) Adding rubocop_todo as this module is under rewrite
GSPatton Apr 3, 2023
b5209a6
(CONT-811) Removing addition of rubygems_mfa requirement in gemspec -…
GSPatton Apr 3, 2023
28559cf
(CONT-811) removing redundant check for HOME env variable as this is …
GSPatton Apr 3, 2023
95d7dff
(CONT-811) Regenerated rubocop_todo to account for removal of Gemspec…
GSPatton Apr 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
fail-fast: false
matrix:
ruby_version:
- '2.5'
- '2.7'
- '3.2'
name: "spec (ruby ${{ matrix.ruby_version }})"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
secrets: "inherit"
Expand All @@ -26,8 +26,8 @@ jobs:
fail-fast: false
matrix:
ruby_version:
- '2.5'
- '2.7'
- '3.2'
name: "acceptance (ruby ${{ matrix.ruby_version }})"
needs: "spec"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
fail-fast: false
matrix:
ruby_version:
- '2.5'
- '2.7'
- '3.2'
name: "spec (ruby ${{ matrix.ruby_version }})"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
secrets: "inherit"
Expand All @@ -25,8 +25,8 @@ jobs:
fail-fast: false
matrix:
ruby_version:
- '2.5'
- '2.7'
- '3.2'
name: "acceptance (ruby ${{ matrix.ruby_version }})"
needs: "spec"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main"
Expand Down
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
inherit_from: rubocop_baseline.yml
inherit_from:
- rubocop_baseline.yml
- .rubocop_todo.yml
161 changes: 161 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-04-04 08:44:46 UTC using RuboCop version 1.48.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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'puppet-lint.gemspec'

# Offense count: 4
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
Lint/DuplicateBranch:
Exclude:
- 'lib/puppet-lint/lexer/string_slurper.rb'
- 'lib/puppet-lint/lexer/token.rb'

# Offense count: 9
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:
Exclude:
- 'lib/puppet-lint.rb'
- 'lib/puppet-lint/lexer.rb'
- 'lib/puppet-lint/lexer/string_slurper.rb'
- 'lib/puppet-lint/lexer/token.rb'
- 'lib/puppet-lint/report/codeclimate.rb'
- 'lib/puppet-lint/report/github.rb'
- 'lib/puppet-lint/tasks/puppet-lint.rb'
- 'spec/unit/puppet-lint/puppet-lint_spec.rb'

# Offense count: 58
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 142

# Offense count: 34
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 104

# Offense count: 2
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 5

# Offense count: 7
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 387

# Offense count: 33
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 33

# Offense count: 80
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 108

# Offense count: 26
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 31

# Offense count: 182
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Enabled: false

# Offense count: 2
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'lib/puppet-lint/monkeypatches.rb'

# Offense count: 7
# Configuration parameters: MinSize.
Performance/CollectionLiteralInLoop:
Exclude:
- 'lib/puppet-lint/bin.rb'
- 'lib/puppet-lint/data.rb'
- 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb'
- 'lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb'

# Offense count: 406
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 41
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Enabled: false

# Offense count: 50
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 148

# Offense count: 8
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Exclude:
- 'spec/unit/puppet-lint/bin_spec.rb'
- 'spec/unit/puppet-lint/checks_spec.rb'
- 'spec/unit/puppet-lint/configuration_spec.rb'
- 'spec/unit/puppet-lint/data_spec.rb'
- 'spec/unit/puppet-lint/lexer/string_slurper_spec.rb'
- 'spec/unit/puppet-lint/lexer/token_spec.rb'
- 'spec/unit/puppet-lint/lexer_spec.rb'
- 'spec/unit/puppet-lint/puppet-lint_spec.rb'

# Offense count: 138
RSpec/MultipleExpectations:
Max: 137

# Offense count: 3
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 13

# Offense count: 52
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 5

# Offense count: 8
RSpec/RepeatedExampleGroupDescription:
Exclude:
- 'spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb'
- 'spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb'
- 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb'

# Offense count: 106
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 9
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'lib/puppet-lint/bin.rb'
- 'lib/puppet-lint/plugins.rb'
- 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb'
- 'spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb'
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ group :development do
end

group :rubocop do
gem 'rubocop', '~> 1.6.1', require: false
gem 'rubocop-rspec', '~> 2.0.1', require: false
gem 'rubocop-performance', '~> 1.9.1', require: false
gem 'rubocop', '~> 1.48.1', require: false
gem 'rubocop-rspec', '~> 2.19', require: false
gem 'rubocop-performance', '~> 1.16', require: false
end
8 changes: 5 additions & 3 deletions lib/puppet-lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def file=(path)

# Check if the input is an SE Linux policy package file (which also use
# the .pp extension), which all have the first 4 bytes 0xf97cff8f.
@code = '' if @code[0..3].unpack('V').first == 0xf97cff8f
@code = '' if @code[0..3].unpack1('V') == 0xf97cff8f
end

# Internal: Retrieve the format string to be used when writing problems to
Expand Down Expand Up @@ -155,8 +155,10 @@ def get_context(message)
def print_context(message)
return if message[:check] == 'documentation'
return if message[:kind] == :fixed

line = message[:context]
return unless line

offset = line.index(%r{\S}) || 1
puts "\n #{line.strip}"
printf("%#{message[:column] + 2 - offset}s\n\n", '^')
Expand Down Expand Up @@ -188,7 +190,7 @@ def report(problems)
print_github_annotation(message) if configuration.github_actions
end
end
$stderr.puts 'Try running `puppet parser validate <file>`' if problems.any? { |p| p[:check] == :syntax }
warn 'Try running `puppet parser validate <file>`' if problems.any? { |p| p[:check] == :syntax }
json
end

Expand Down Expand Up @@ -251,7 +253,7 @@ def print_problems
def self.new_check(name, &block)
class_name = name.to_s.split('_').map(&:capitalize).join
klass = PuppetLint.const_set("Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
klass.const_set('NAME', name)
klass.const_set(:NAME, name)
klass.class_exec(&block)
PuppetLint.configuration.add_check(name, klass)
PuppetLint::Data.ignore_overrides[name] ||= {}
Expand Down
18 changes: 7 additions & 11 deletions lib/puppet-lint/bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run

begin
path = @args[0]
full_path = File.expand_path(path, ENV['PWD'])
full_path = File.expand_path(path, ENV.fetch('PWD', nil))
full_base_path = if File.directory?(full_path)
full_path
else
Expand Down Expand Up @@ -79,19 +79,17 @@ def run

path.each do |f|
next if ignore_paths.any? { |p| File.fnmatch(p, f) }

l = PuppetLint.new
l.file = f
l.run
all_problems << l.print_problems

if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings)
return_val = 1
end
return_val = 1 if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings)

next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax }
File.open(f, 'wb') do |fd|
fd.write(l.manifest)
end

File.binwrite(f, l.manifest)
end

if PuppetLint.configuration.sarif
Expand All @@ -105,9 +103,7 @@ def run
puts JSON.pretty_generate(all_problems)
end

if PuppetLint.configuration.codeclimate_report_file
PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file)
end
PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) if PuppetLint.configuration.codeclimate_report_file

return_val
rescue PuppetLint::NoCodeError
Expand Down Expand Up @@ -148,7 +144,7 @@ def report_sarif(problems, base_path, base_path_uri)
'ruleIndex' => rule_index,
'message' => { 'text' => message[:message] },
'locations' => [{ 'physicalLocation' => { 'artifactLocation' => { 'uri' => relative_path, 'uriBaseId' => 'ROOTPATH' },
'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }],
'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }]
}
results << result
end
Expand Down
12 changes: 4 additions & 8 deletions lib/puppet-lint/checkplugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ def manifest_lines
# Returns a Hash of default problem information.
def default_info
@default_info ||= {
check: self.class.const_get('NAME'),
check: self.class.const_get(:NAME),
fullpath: fullpath,
path: path,
filename: filename,
filename: filename
}
end

Expand All @@ -202,14 +202,10 @@ def notify(kind, problem)
problem[:kind] = kind
problem.merge!(default_info) { |_key, v1, _v2| v1 }

unless [:warning, :error, :fixed].include?(kind)
raise ArgumentError, 'unknown value passed for kind'
end
raise ArgumentError, 'unknown value passed for kind' unless [:warning, :error, :fixed].include?(kind)

[:message, :line, :column, :check].each do |attr|
unless problem.key?(attr)
raise ArgumentError, "problem hash must contain #{attr.inspect}"
end
raise ArgumentError, "problem hash must contain #{attr.inspect}" unless problem.key?(attr)
end

@problems << problem
Expand Down
16 changes: 7 additions & 9 deletions lib/puppet-lint/checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load_data(path, content)
column: e.column,
fullpath: PuppetLint::Data.fullpath,
path: PuppetLint::Data.path,
filename: PuppetLint::Data.filename,
filename: PuppetLint::Data.filename
}
PuppetLint::Data.tokens = []
end
Expand Down Expand Up @@ -76,15 +76,15 @@ def run(fileinfo, data)
kind: :error,
check: :syntax,
message: 'Syntax error',
fullpath: File.expand_path(fileinfo, ENV['PWD']),
fullpath: File.expand_path(fileinfo, ENV.fetch('PWD', nil)),
filename: File.basename(fileinfo),
path: fileinfo,
line: e.token.line,
column: e.token.column,
column: e.token.column
}

@problems
rescue => e
rescue StandardError => e
$stdout.puts <<-END.gsub(%r{^ {6}}, '')
Whoops! It looks like puppet-lint has encountered an error that it doesn't
know how to handle. Please open an issue at https://github.com/puppetlabs/puppet-lint
Expand Down Expand Up @@ -120,17 +120,15 @@ def run(fileinfo, data)
#
# Returns an Array of String check names.
def enabled_checks
@enabled_checks ||= begin
PuppetLint.configuration.checks.select do |check|
PuppetLint.configuration.send("#{check}_enabled?")
end
@enabled_checks ||= PuppetLint.configuration.checks.select do |check|
PuppetLint.configuration.send("#{check}_enabled?")
end
end

# Internal: Render the fixed manifest.
#
# Returns the manifest as a String.
def manifest
PuppetLint::Data.tokens.map(&:to_manifest).join('')
PuppetLint::Data.tokens.map(&:to_manifest).join
end
end
Loading