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

(MAINT) Drop Ruby 2.1.x and Puppet 4.x compatibility #253

Merged
merged 12 commits into from
Sep 23, 2020
Merged
52 changes: 37 additions & 15 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require: rubocop-performance
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.3
Exclude:
# Ignore HTML related things
- '**/*.erb'
Expand All @@ -9,6 +11,7 @@ AllCops:
- spec/fixtures/modules/**/*
- spec/fixtures/ruby/**/*


# DISABLED - not useful
Bundler/OrderedGems:
Enabled: false
Expand All @@ -34,7 +37,7 @@ Lint/EnsureReturn:
Enabled: false

# MAYBE useful - errors when rescue {} happens.
Lint/HandleExceptions:
Lint/SuppressedException:
Enabled: false

# MAYBE useful - but too many instances
Expand Down Expand Up @@ -119,7 +122,7 @@ Lint/ParenthesesAsGroupedExpression:
Lint/RescueException:
Enabled: false

Lint/StringConversionInInterpolation:
Lint/RedundantStringCoercion:
Enabled: false

Lint/UnusedBlockArgument:
Expand All @@ -143,13 +146,13 @@ Naming/AccessorMethodName:
Style/Alias:
Enabled: false

Layout/AlignArray:
Layout/ArrayAlignment:
Enabled: false

Layout/AlignHash:
Layout/HashAlignment:
Enabled: false

Layout/AlignParameters:
Layout/ParameterAlignment:
Enabled: false

Metrics/BlockNesting:
Expand All @@ -161,9 +164,6 @@ Style/AsciiComments:
Style/Attr:
Enabled: false

Style/BracesAroundHashParameters:
Enabled: false

Style/CaseEquality:
Enabled: false

Expand Down Expand Up @@ -198,7 +198,7 @@ Style/WhenThen:
Style/WordArray:
Enabled: false

Style/UnneededPercentQ:
Style/RedundantPercentQ:
Enabled: false

Layout/Tab:
Expand All @@ -207,7 +207,7 @@ Layout/Tab:
Layout/SpaceBeforeSemicolon:
Enabled: false

Layout/TrailingBlankLines:
Layout/TrailingEmptyLines:
Enabled: false

Layout/SpaceInsideBlockBraces:
Expand Down Expand Up @@ -292,10 +292,10 @@ Style/EachWithObject:
Layout/EmptyLineBetweenDefs:
Enabled: false

Layout/IndentArray:
Layout/FirstArrayElementIndentation:
Enabled: false

Layout/IndentHash:
Layout/FirstHashElementIndentation:
Enabled: false

Layout/IndentationConsistency:
Expand All @@ -313,7 +313,7 @@ Layout/EmptyLinesAroundAccessModifier:
Style/EmptyLiteral:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Enabled: false

Style/MethodCallWithoutArgsParentheses:
Expand Down Expand Up @@ -430,6 +430,9 @@ Style/Not:
Style/NumericLiterals:
Enabled: false

Style/NumericPredicate:
Enabled: false

Style/OneLineConditional:
Enabled: false

Expand Down Expand Up @@ -526,7 +529,7 @@ Layout/EmptyLinesAroundBlockBody:
Layout/EmptyLinesAroundClassBody:
Enabled: false

Style/UnneededInterpolation:
Style/RedundantInterpolation:
Enabled: false

Style/SymbolProc:
Expand Down Expand Up @@ -575,5 +578,24 @@ Naming/VariableNumber:
Layout/EndOfLine:
EnforcedStyle: lf

Layout/IndentHeredoc: # Not appicable on Ruby 2.1
Layout/HeredocIndentation: # Not appicable on Ruby 2.1
Enabled: false

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

Style/HashEachMethods:
Enabled: true

Style/HashTransformKeys:
Enabled: false # requires Ruby 2.5

Style/HashTransformValues:
Enabled: false # requires Ruby 2.4

Naming/MethodParameterName:
Enabled: true
AllowedNames: [ o ]
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ script: 'SPEC_OPTS="--format documentation" COVERAGE="yes" bundle exec rake $CHE
jobs:
fast_finish: true
include:
- rvm: 2.1.9
env: PUPPET_GEM_VERSION="~> 4" CHECK=spec
- rvm: 2.4.1
env: PUPPET_GEM_VERSION="~> 4" CHECK=spec
- rvm: 2.4.1
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 4" CHECK=rubocop
- rvm: 2.4
env: PUPPET_GEM_VERSION="~> 5" CHECK=spec
- rvm: 2.5
env: PUPPET_GEM_VERSION="~> 6" CHECK=spec
- rvm: 2.7
env: PUPPET_GEM_VERSION="~> 6" CHECK=spec
- rvm: 2.1.9
env: PUPPET_GEM_VERSION="~> 4" CHECK=rubocop
- bundler_args: ""
rvm: 2.5
before_script:
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source ENV['GEM_SOURCE'] || "https://rubygems.org"

gemspec
Expand Down Expand Up @@ -37,8 +39,9 @@ group :development do
gem 'pry-byebug'
end

gem 'rubocop', '~> 0.81.0' # last release that supports Ruby 2.3.0
gem 'rubocop-rspec'
gem 'rubocop', '~> 0.57.2'
gem 'rubocop-performance'

# Evaluate Gemfile.local if it exists
if File.exists? "#{__FILE__}.local"
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

if Bundler.rubygems.find_name('puppet_litmus').any?
require 'puppet_litmus/rake_tasks'

Expand Down Expand Up @@ -54,7 +56,7 @@ PuppetLint.configuration.ignore_paths = %w(acceptance/**/*.pp spec/**/*.pp pkg/*
desc 'Validate Ruby source files and ERB templates.'
task :validate do
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
sh "ruby -c #{ruby_file}" unless /spec\/fixtures/.match?(ruby_file)
end
Dir['lib/puppet-strings/yard/templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
Expand Down Expand Up @@ -93,10 +95,12 @@ namespace :litmus do
`gem build puppet-strings.gemspec --quiet`
result = $CHILD_STATUS
raise "Unable to build the puppet-strings gem. Returned exit code #{result.exitstatus}" unless result.exitstatus.zero?

puts 'Built'
# Find the gem build artifact
gem_tar = Dir.glob('puppet-strings-*.gem').max_by { |f| File.mtime(f) }
raise "Unable to find package in 'puppet-strings-*.gem'" if gem_tar.nil?

gem_tar = File.expand_path(gem_tar)

target_string = if args[:target_node_name].nil?
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-strings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# The root module for Puppet Strings.
module PuppetStrings
# The glob patterns used to search for files to document.
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-strings/describe.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'
require 'puppet-strings/json'

Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-strings/json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'

# The module for JSON related functionality.
Expand Down
20 changes: 11 additions & 9 deletions lib/puppet-strings/markdown.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet-strings/json'

# module for parsing Yard Registries and generating markdown
Expand All @@ -15,15 +17,15 @@ module PuppetStrings::Markdown
# @return [String] markdown doc
def self.generate
final = "# Reference\n\n"
final << "<!-- DO NOT EDIT: This document was generated by Puppet Strings -->\n\n"
final << PuppetStrings::Markdown::TableOfContents.render
final << PuppetStrings::Markdown::PuppetClasses.render
final << PuppetStrings::Markdown::DefinedTypes.render
final << PuppetStrings::Markdown::ResourceTypes.render
final << PuppetStrings::Markdown::Functions.render
final << PuppetStrings::Markdown::DataTypes.render
final << PuppetStrings::Markdown::PuppetTasks.render
final << PuppetStrings::Markdown::PuppetPlans.render
final += "<!-- DO NOT EDIT: This document was generated by Puppet Strings -->\n\n"
final += PuppetStrings::Markdown::TableOfContents.render
final += PuppetStrings::Markdown::PuppetClasses.render
final += PuppetStrings::Markdown::DefinedTypes.render
final += PuppetStrings::Markdown::ResourceTypes.render
final += PuppetStrings::Markdown::Functions.render
final += PuppetStrings::Markdown::DataTypes.render
final += PuppetStrings::Markdown::PuppetTasks.render
final += PuppetStrings::Markdown::PuppetPlans.render

final
end
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet-strings/markdown/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet-strings'
require 'puppet-strings/json'
require 'puppet-strings/yard'
Expand Down Expand Up @@ -68,7 +70,7 @@ def initialize(registry, component_type)

# @return [String] top-level name
def name
@registry[:name].to_s unless @registry[:name].nil?
@registry[:name]&.to_s
end

# @return [String] 'Overview' text (untagged text)
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-strings/markdown/data_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet-strings/markdown/base'

module PuppetStrings::Markdown
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet-strings/markdown/data_types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'data_type'

module PuppetStrings::Markdown
Expand All @@ -22,7 +24,7 @@ def self.contains_private?
def self.render
final = in_dtypes.length > 0 ? "## Data types\n\n" : ""
in_dtypes.each do |type|
final << type.render unless type.private?
final += type.render unless type.private?
end
final
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-strings/markdown/defined_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet-strings/markdown/base'

module PuppetStrings::Markdown
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet-strings/markdown/defined_types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'defined_type'

module PuppetStrings::Markdown
Expand All @@ -19,7 +21,7 @@ def self.contains_private?
def self.render
final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
in_dtypes.each do |type|
final << type.render unless type.private?
final += type.render unless type.private?
end
final
end
Expand Down
16 changes: 9 additions & 7 deletions lib/puppet-strings/markdown/function.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet-strings/markdown/base'

module PuppetStrings::Markdown
Expand All @@ -19,23 +21,23 @@ def render

def type
t = @registry[:type]
if t =~ /ruby4x/
if /ruby4x/.match?(t)
"Ruby 4.x API"
elsif t =~ /ruby3/
elsif /ruby3/.match?(t)
"Ruby 3.x API"
elsif t =~ /ruby/
elsif /ruby/.match?(t)
"Ruby"
else
"Puppet Language"
end
end

def error_type(r) # rubocop:disable Naming/UncommunicativeMethodParamName
"`#{r.split(' ')[0]}`"
def error_type(type)
"`#{type.split(' ')[0]}`"
end

def error_text(r) # rubocop:disable Naming/UncommunicativeMethodParamName
"#{r.split(' ').drop(1).join(' ')}"
def error_text(text)
"#{text.split(' ').drop(1).join(' ')}"
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/puppet-strings/markdown/functions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'function'

module PuppetStrings::Markdown
Expand All @@ -19,7 +21,7 @@ def self.contains_private?
def self.render
final = in_functions.length > 0 ? "## Functions\n\n" : ""
in_functions.each do |func|
final << func.render unless func.private?
final += func.render unless func.private?
end
final
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-strings/markdown/puppet_class.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet-strings/markdown/base'

module PuppetStrings::Markdown
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet-strings/markdown/puppet_classes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'puppet_class'

module PuppetStrings::Markdown
Expand All @@ -19,7 +21,7 @@ def self.contains_private?
def self.render
final = in_classes.length > 0 ? "## Classes\n\n" : ""
in_classes.each do |klass|
final << klass.render unless klass.private?
final += klass.render unless klass.private?
end
final
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-strings/markdown/puppet_plan.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet-strings/markdown/base'

module PuppetStrings::Markdown
Expand Down
Loading