Skip to content

Commit

Permalink
Merge pull request #113 from puppetlabs/CONT-811-add_ruby_3
Browse files Browse the repository at this point in the history
(CONT-811) Add Ruby 3.2 support
  • Loading branch information
jordanbreen28 authored Apr 6, 2023
2 parents 7f160d7 + 95d7dff commit 15e48b7
Show file tree
Hide file tree
Showing 65 changed files with 604 additions and 891 deletions.
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

0 comments on commit 15e48b7

Please sign in to comment.