From b4714a708af3fdf436995358ec95417af9685573 Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Tue, 8 Apr 2025 09:38:33 +0100 Subject: [PATCH 1/3] (CAT-2281) Remove puppet 7 infrastructure Puppet 7 is EOL. Therefore, we can remove the test infrastructure for it. This commit aims to clear up any testing/config infrastructure related to Puppet 7 and, by extension, Ruby 2.7. --- .github/workflows/ci.yml | 6 ------ .github/workflows/nightly.yml | 6 ------ .rubocop.yml | 2 +- README.md | 4 ++-- puppet-strings.gemspec | 4 ++-- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 576a75fe..42f3e975 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,8 @@ jobs: fail-fast: false matrix: ruby_version: - - "2.7" - "3.2" include: - - ruby-version: '2.7' - puppet_gem_version: '~> 7.0' - ruby_version: '3.2' puppet_gem_version: '~> 8.0' runs_on: @@ -42,11 +39,8 @@ jobs: strategy: matrix: ruby_version: - - "2.7" - "3.2" include: - - ruby-version: '2.7' - puppet_gem_version: '~> 7.0' - ruby_version: '3.2' puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8' runs_on: diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index f8aae476..304e9722 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -11,11 +11,8 @@ jobs: fail-fast: false matrix: ruby_version: - - "2.7" - "3.2" include: - - ruby-version: '2.7' - puppet_gem_version: '~> 7.0' - ruby_version: '3.2' puppet_gem_version: '~> 8.0' runs_on: @@ -34,11 +31,8 @@ jobs: strategy: matrix: ruby_version: - - "2.7" - "3.2" include: - - ruby-version: '2.7' - puppet_gem_version: '~> 7.0' - ruby_version: '3.2' puppet_gem_version: 'https://github.com/puppetlabs/puppet' # puppet8' runs_on: diff --git a/.rubocop.yml b/.rubocop.yml index 3e374020..08f3b6f3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,7 @@ AllCops: - vendor/bundle/**/* NewCops: enable SuggestExtensions: false - TargetRubyVersion: '2.7' + TargetRubyVersion: '3.1' # Disabled Style/ClassAndModuleChildren: diff --git a/README.md b/README.md index 87efc885..a8143b52 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Strings processes code and YARD-style code comments to create documentation in H ### Requirements -* Ruby 2.7.0 or newer -* Puppet 7.0.0 or newer +* Ruby 3.1.0 or newer +* Puppet 8.0.0 or newer ### Install Puppet Strings diff --git a/puppet-strings.gemspec b/puppet-strings.gemspec index f72c4fba..eef11eab 100644 --- a/puppet-strings.gemspec +++ b/puppet-strings.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.summary = 'Puppet documentation via YARD' s.email = 'info@puppet.com' s.homepage = 'https://github.com/puppetlabs/puppet-strings' - s.required_ruby_version = '>= 2.7.0' + s.required_ruby_version = '>= 3.1.0' s.extra_rdoc_files = [ 'CHANGELOG.md', @@ -22,7 +22,7 @@ Gem::Specification.new do |s| ] s.files = Dir['CHANGELOG.md', 'README.md', 'LICENSE', 'lib/**/*', 'exe/**/*'] - s.add_runtime_dependency 'puppet', '>= 7.0.0' + s.add_runtime_dependency 'puppet', '>= 8.0.0' s.add_runtime_dependency 'rgen', '~> 0.9' s.add_runtime_dependency 'yard', '~> 0.9' end From 22a2744ab01b223888cc488a14cce9c8e9a28d98 Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Wed, 9 Apr 2025 11:38:03 +0100 Subject: [PATCH 2/3] Rubocop safe corrections --- lib/puppet-strings/markdown/base.rb | 2 +- lib/puppet-strings/yard/code_objects/function.rb | 2 +- lib/puppet-strings/yard/handlers/ruby/base.rb | 2 +- lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb | 2 +- lib/puppet-strings/yard/parsers/puppet/statement.rb | 2 +- lib/puppet-strings/yard/tags/overload_tag.rb | 4 ++-- spec/unit/puppet-strings/json_spec.rb | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/puppet-strings/markdown/base.rb b/lib/puppet-strings/markdown/base.rb index 5e5e49b1..7e1fae38 100644 --- a/lib/puppet-strings/markdown/base.rb +++ b/lib/puppet-strings/markdown/base.rb @@ -181,7 +181,7 @@ def defaults def toc_info { name: name.to_s, - link: link, + link:, desc: summary || @registry[:docstring][:text][0..140].tr("\n", ' '), private: private? } diff --git a/lib/puppet-strings/yard/code_objects/function.rb b/lib/puppet-strings/yard/code_objects/function.rb index 03916a08..f7162d38 100644 --- a/lib/puppet-strings/yard/code_objects/function.rb +++ b/lib/puppet-strings/yard/code_objects/function.rb @@ -94,7 +94,7 @@ def to_hash hash[:signatures] << { signature: o.signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(o.docstring, %i[param option enum return example]) } end else - hash[:signatures] << { signature: signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) } + hash[:signatures] << { signature:, docstring: PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) } end hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) diff --git a/lib/puppet-strings/yard/handlers/ruby/base.rb b/lib/puppet-strings/yard/handlers/ruby/base.rb index 81c3c9bf..a93a72d9 100644 --- a/lib/puppet-strings/yard/handlers/ruby/base.rb +++ b/lib/puppet-strings/yard/handlers/ruby/base.rb @@ -6,7 +6,7 @@ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base # A regular expression for detecting the start of a Ruby heredoc. # Note: the first character of the heredoc start may have been cut off by YARD. - HEREDOC_START = /^ Date: Wed, 9 Apr 2025 11:55:53 +0100 Subject: [PATCH 3/3] bumping rubocop, safe autocorrection and new todo --- .rubocop_todo.yml | 28 ++++++++++++------- Gemfile | 2 +- .../yard/handlers/puppet/base.rb | 2 +- .../yard/handlers/ruby/provider_handler.rb | 2 +- .../yard/handlers/ruby/type_base.rb | 2 +- .../yard/parsers/puppet/statement.rb | 2 +- .../yard/templates/default/tags/setup.rb | 8 +----- lib/puppet-strings/yard/util.rb | 2 +- puppet-strings.gemspec | 6 ++-- 9 files changed, 28 insertions(+), 26 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d927f4ef..d3ec3074 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-01-22 15:21:03 UTC using RuboCop version 1.50.2. +# on 2025-04-09 10:54:46 UTC using RuboCop version 1.70.0. # 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 @@ -14,7 +14,7 @@ Gemspec/RequireMFA: Exclude: - 'puppet-strings.gemspec' -# Offense count: 45 +# Offense count: 44 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 95 @@ -25,17 +25,12 @@ Metrics/AbcSize: Metrics/BlockLength: Max: 44 -# Offense count: 1 -# Configuration parameters: CountBlocks. -Metrics/BlockNesting: - Max: 4 - # Offense count: 5 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: Max: 283 -# Offense count: 34 +# Offense count: 33 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 36 @@ -68,6 +63,7 @@ Naming/AccessorMethodName: # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS Naming/FileName: Exclude: + - 'Rakefile.rb' - 'lib/puppet-strings.rb' # Offense count: 1 @@ -85,12 +81,14 @@ Naming/MethodParameterName: - 'lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb' - 'lib/puppet-strings/yard/parsers/puppet/parser.rb' -# Offense count: 2 +# Offense count: 4 # Configuration parameters: MinSize. Performance/CollectionLiteralInLoop: Exclude: + - 'lib/puppet-strings/yard/handlers/puppet/base.rb' - 'lib/puppet-strings/yard/handlers/ruby/provider_handler.rb' - 'lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb' + - 'lib/puppet-strings/yard/util.rb' # Offense count: 1 RSpec/BeforeAfterAll: @@ -123,7 +121,7 @@ RSpec/DescribeClass: - 'spec/acceptance/generate_markdown_spec.rb' - 'spec/acceptance/running_strings_generate_spec.rb' -# Offense count: 48 +# Offense count: 51 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 66 @@ -159,6 +157,7 @@ Style/ClassVars: - 'lib/puppet-strings/yard/templates/default/layout/html/setup.rb' # Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). Style/CombinableLoops: Exclude: - 'lib/puppet-strings/markdown.rb' @@ -187,3 +186,12 @@ Style/OptionalBooleanParameter: - 'lib/puppet-strings/yard/code_objects/type.rb' - 'lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb' - 'lib/puppet-strings/yard/handlers/ruby/function_handler.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/puppet-strings/yard/handlers/puppet/function_handler.rb' + - 'lib/puppet-strings/yard/handlers/ruby/function_handler.rb' diff --git a/Gemfile b/Gemfile index 5755615e..00823ad9 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,7 @@ group :development do gem 'rspec', '~> 3.1' gem 'rspec-its', '~> 1.0' - gem 'rubocop', '~> 1.64.0', require: false + gem 'rubocop', '~> 1.70.0', require: false gem 'rubocop-performance', '~> 1.16', require: false gem 'rubocop-rspec', '~> 3.0', require: false diff --git a/lib/puppet-strings/yard/handlers/puppet/base.rb b/lib/puppet-strings/yard/handlers/puppet/base.rb index ffa0b0cc..16093351 100644 --- a/lib/puppet-strings/yard/handlers/puppet/base.rb +++ b/lib/puppet-strings/yard/handlers/puppet/base.rb @@ -21,7 +21,7 @@ def set_parameter_types(object) tags.each do |tag| next if statement.parameters.find { |p| tag.name == p.name } - log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{statement.file}:#{statement.line}." unless tag.name == 'name' || tag.name == 'title' + log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{statement.file}:#{statement.line}." unless %w[name title].include?(tag.name) end # Assign the types for the parameter diff --git a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb index 9ce6213a..c1173c5f 100644 --- a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb @@ -61,7 +61,7 @@ def register_provider_docstring(object) # Look for a call to a dispatch method with a block next unless child.method_name && - (child.method_name.source == 'desc' || child.method_name.source == 'doc=') && + ['desc', 'doc='].include?(child.method_name.source) && child.parameters(false).count == 1 docstring = node_as_string(child.parameters[0]) diff --git a/lib/puppet-strings/yard/handlers/ruby/type_base.rb b/lib/puppet-strings/yard/handlers/ruby/type_base.rb index 9e1fba87..5fbee56a 100644 --- a/lib/puppet-strings/yard/handlers/ruby/type_base.rb +++ b/lib/puppet-strings/yard/handlers/ruby/type_base.rb @@ -34,7 +34,7 @@ def find_docstring(node, kind) elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode) # Look for a call to a dispatch method with a block next unless child.method_name && - (child.method_name.source == 'desc' || child.method_name.source == 'doc=') && + ['desc', 'doc='].include?(child.method_name.source) && child.parameters(false).count == 1 docstring = node_as_string(child.parameters[0]) diff --git a/lib/puppet-strings/yard/parsers/puppet/statement.rb b/lib/puppet-strings/yard/parsers/puppet/statement.rb index 5955f77d..20ad8e62 100644 --- a/lib/puppet-strings/yard/parsers/puppet/statement.rb +++ b/lib/puppet-strings/yard/parsers/puppet/statement.rb @@ -170,7 +170,7 @@ def initialize(object, file) case type_expr when Puppet::Pops::Model::AccessExpression # TODO: I don't like rebuilding the source from the AST, but AccessExpressions don't expose the original source - @alias_of = +"#{PuppetStrings::Yard::Util.ast_to_text(type_expr.left_expr)}[" # alias_of should be mutable so we add a + to the string. + @alias_of = "#{PuppetStrings::Yard::Util.ast_to_text(type_expr.left_expr)}[" # alias_of should be mutable so we add a + to the string. @alias_of << type_expr.keys.map { |key| PuppetStrings::Yard::Util.ast_to_text(key) }.join(', ') @alias_of << ']' else diff --git a/lib/puppet-strings/yard/templates/default/tags/setup.rb b/lib/puppet-strings/yard/templates/default/tags/setup.rb index d6af2d2f..8b8a835b 100644 --- a/lib/puppet-strings/yard/templates/default/tags/setup.rb +++ b/lib/puppet-strings/yard/templates/default/tags/setup.rb @@ -4,13 +4,7 @@ # @return [Array] Returns the parameter tags if the object should have parameters. def param tag(:param) if - object.type == :method || - object.type == :puppet_class || - object.type == :puppet_data_type || - object.type == :puppet_defined_type || - object.type == :puppet_function || - object.type == :puppet_task || - object.type == :puppet_plan + %i[method puppet_class puppet_data_type puppet_defined_type puppet_function puppet_task puppet_plan].include?(object.type) end # Renders the overload section. diff --git a/lib/puppet-strings/yard/util.rb b/lib/puppet-strings/yard/util.rb index 8025b150..e0369f56 100644 --- a/lib/puppet-strings/yard/util.rb +++ b/lib/puppet-strings/yard/util.rb @@ -40,7 +40,7 @@ def self.tags_to_hashes(tags) tag = { tag_name: t.tag_name } # grab nested information for @option and @enum tags - if tag[:tag_name] == 'option' || tag[:tag_name] == 'enum' + if %w[option enum].include?(tag[:tag_name]) tag[:opt_name] = t.pair.name tag[:opt_text] = t.pair.text tag[:opt_types] = t.pair.types if t.pair.types diff --git a/puppet-strings.gemspec b/puppet-strings.gemspec index eef11eab..7a6dfb95 100644 --- a/puppet-strings.gemspec +++ b/puppet-strings.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| ] s.files = Dir['CHANGELOG.md', 'README.md', 'LICENSE', 'lib/**/*', 'exe/**/*'] - s.add_runtime_dependency 'puppet', '>= 8.0.0' - s.add_runtime_dependency 'rgen', '~> 0.9' - s.add_runtime_dependency 'yard', '~> 0.9' + s.add_dependency 'puppet', '>= 8.0.0' + s.add_dependency 'rgen', '~> 0.9' + s.add_dependency 'yard', '~> 0.9' end