diff --git a/.rubocop.yml b/.rubocop.yml index 85e3be868..ab4ac3978 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,8 @@ +require: rubocop-performance inherit_from: .rubocop_todo.yml AllCops: + TargetRubyVersion: 2.3 Exclude: # Ignore HTML related things - '**/*.erb' @@ -9,6 +11,7 @@ AllCops: - spec/fixtures/modules/**/* - spec/fixtures/ruby/**/* + # DISABLED - not useful Bundler/OrderedGems: Enabled: false @@ -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 @@ -119,7 +122,7 @@ Lint/ParenthesesAsGroupedExpression: Lint/RescueException: Enabled: false -Lint/StringConversionInInterpolation: +Lint/RedundantStringCoercion: Enabled: false Lint/UnusedBlockArgument: @@ -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: @@ -161,9 +164,6 @@ Style/AsciiComments: Style/Attr: Enabled: false -Style/BracesAroundHashParameters: - Enabled: false - Style/CaseEquality: Enabled: false @@ -198,7 +198,7 @@ Style/WhenThen: Style/WordArray: Enabled: false -Style/UnneededPercentQ: +Style/RedundantPercentQ: Enabled: false Layout/Tab: @@ -207,7 +207,7 @@ Layout/Tab: Layout/SpaceBeforeSemicolon: Enabled: false -Layout/TrailingBlankLines: +Layout/TrailingEmptyLines: Enabled: false Layout/SpaceInsideBlockBraces: @@ -292,10 +292,10 @@ Style/EachWithObject: Layout/EmptyLineBetweenDefs: Enabled: false -Layout/IndentArray: +Layout/FirstArrayElementIndentation: Enabled: false -Layout/IndentHash: +Layout/FirstHashElementIndentation: Enabled: false Layout/IndentationConsistency: @@ -313,7 +313,7 @@ Layout/EmptyLinesAroundAccessModifier: Style/EmptyLiteral: Enabled: false -Metrics/LineLength: +Layout/LineLength: Enabled: false Style/MethodCallWithoutArgsParentheses: @@ -430,6 +430,9 @@ Style/Not: Style/NumericLiterals: Enabled: false +Style/NumericPredicate: + Enabled: false + Style/OneLineConditional: Enabled: false @@ -526,7 +529,7 @@ Layout/EmptyLinesAroundBlockBody: Layout/EmptyLinesAroundClassBody: Enabled: false -Style/UnneededInterpolation: +Style/RedundantInterpolation: Enabled: false Style/SymbolProc: @@ -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 ] diff --git a/.travis.yml b/.travis.yml index db5b72e92..15ce749b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/Gemfile b/Gemfile index f95de9ef0..704560aa1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source ENV['GEM_SOURCE'] || "https://rubygems.org" gemspec @@ -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" diff --git a/Rakefile b/Rakefile index e72db0c78..0f68b5e9e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppet_litmus/rake_tasks' @@ -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" @@ -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? diff --git a/lib/puppet-strings.rb b/lib/puppet-strings.rb index 529574104..29ead460e 100644 --- a/lib/puppet-strings.rb +++ b/lib/puppet-strings.rb @@ -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. diff --git a/lib/puppet-strings/describe.rb b/lib/puppet-strings/describe.rb index fb7c4a0b6..982851730 100644 --- a/lib/puppet-strings/describe.rb +++ b/lib/puppet-strings/describe.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'puppet-strings/json' diff --git a/lib/puppet-strings/json.rb b/lib/puppet-strings/json.rb index ec8cfd022..9d04aabc9 100644 --- a/lib/puppet-strings/json.rb +++ b/lib/puppet-strings/json.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' # The module for JSON related functionality. diff --git a/lib/puppet-strings/markdown.rb b/lib/puppet-strings/markdown.rb index ef8bfd763..b9e988954 100644 --- a/lib/puppet-strings/markdown.rb +++ b/lib/puppet-strings/markdown.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/json' # module for parsing Yard Registries and generating markdown @@ -15,15 +17,15 @@ module PuppetStrings::Markdown # @return [String] markdown doc def self.generate final = "# Reference\n\n" - final << "\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 += "\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 diff --git a/lib/puppet-strings/markdown/base.rb b/lib/puppet-strings/markdown/base.rb index 539ee1d58..d83b1035b 100644 --- a/lib/puppet-strings/markdown/base.rb +++ b/lib/puppet-strings/markdown/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings' require 'puppet-strings/json' require 'puppet-strings/yard' @@ -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) diff --git a/lib/puppet-strings/markdown/data_type.rb b/lib/puppet-strings/markdown/data_type.rb index 74e7624bf..c4363bba4 100644 --- a/lib/puppet-strings/markdown/data_type.rb +++ b/lib/puppet-strings/markdown/data_type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/markdown/base' module PuppetStrings::Markdown diff --git a/lib/puppet-strings/markdown/data_types.rb b/lib/puppet-strings/markdown/data_types.rb index 7a0fe317e..0fb1bd02c 100644 --- a/lib/puppet-strings/markdown/data_types.rb +++ b/lib/puppet-strings/markdown/data_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'data_type' module PuppetStrings::Markdown @@ -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 diff --git a/lib/puppet-strings/markdown/defined_type.rb b/lib/puppet-strings/markdown/defined_type.rb index 86e5c14f8..37ff07f65 100644 --- a/lib/puppet-strings/markdown/defined_type.rb +++ b/lib/puppet-strings/markdown/defined_type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/markdown/base' module PuppetStrings::Markdown diff --git a/lib/puppet-strings/markdown/defined_types.rb b/lib/puppet-strings/markdown/defined_types.rb index c10517f60..a4c281a1c 100644 --- a/lib/puppet-strings/markdown/defined_types.rb +++ b/lib/puppet-strings/markdown/defined_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'defined_type' module PuppetStrings::Markdown @@ -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 diff --git a/lib/puppet-strings/markdown/function.rb b/lib/puppet-strings/markdown/function.rb index 9da691627..e2449925f 100644 --- a/lib/puppet-strings/markdown/function.rb +++ b/lib/puppet-strings/markdown/function.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/markdown/base' module PuppetStrings::Markdown @@ -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 diff --git a/lib/puppet-strings/markdown/functions.rb b/lib/puppet-strings/markdown/functions.rb index f1cfb2680..c111478c5 100644 --- a/lib/puppet-strings/markdown/functions.rb +++ b/lib/puppet-strings/markdown/functions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'function' module PuppetStrings::Markdown @@ -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 diff --git a/lib/puppet-strings/markdown/puppet_class.rb b/lib/puppet-strings/markdown/puppet_class.rb index 8bf02be4d..4eda6c57e 100644 --- a/lib/puppet-strings/markdown/puppet_class.rb +++ b/lib/puppet-strings/markdown/puppet_class.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/markdown/base' module PuppetStrings::Markdown diff --git a/lib/puppet-strings/markdown/puppet_classes.rb b/lib/puppet-strings/markdown/puppet_classes.rb index 625e7e270..f22dd5789 100644 --- a/lib/puppet-strings/markdown/puppet_classes.rb +++ b/lib/puppet-strings/markdown/puppet_classes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'puppet_class' module PuppetStrings::Markdown @@ -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 diff --git a/lib/puppet-strings/markdown/puppet_plan.rb b/lib/puppet-strings/markdown/puppet_plan.rb index e4e62e3b1..56601dacf 100644 --- a/lib/puppet-strings/markdown/puppet_plan.rb +++ b/lib/puppet-strings/markdown/puppet_plan.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/markdown/base' module PuppetStrings::Markdown diff --git a/lib/puppet-strings/markdown/puppet_plans.rb b/lib/puppet-strings/markdown/puppet_plans.rb index fc0bd4568..7586eab01 100644 --- a/lib/puppet-strings/markdown/puppet_plans.rb +++ b/lib/puppet-strings/markdown/puppet_plans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'puppet_plan' module PuppetStrings::Markdown @@ -19,7 +21,7 @@ def self.contains_private? def self.render final = in_plans.length > 0 ? "## Plans\n\n" : "" in_plans.each do |plan| - final << plan.render unless plan.private? + final += plan.render unless plan.private? end final end diff --git a/lib/puppet-strings/markdown/puppet_task.rb b/lib/puppet-strings/markdown/puppet_task.rb index 60bd3c5b0..d00e5bdb0 100644 --- a/lib/puppet-strings/markdown/puppet_task.rb +++ b/lib/puppet-strings/markdown/puppet_task.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/markdown/base' module PuppetStrings::Markdown diff --git a/lib/puppet-strings/markdown/puppet_tasks.rb b/lib/puppet-strings/markdown/puppet_tasks.rb index c5e417ce4..9d394f3fc 100644 --- a/lib/puppet-strings/markdown/puppet_tasks.rb +++ b/lib/puppet-strings/markdown/puppet_tasks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'puppet_task' module PuppetStrings::Markdown @@ -16,7 +18,7 @@ def self.contains_private? def self.render final = in_tasks.length > 0 ? "## Tasks\n\n" : "" in_tasks.each do |task| - final << task.render unless task.private? + final += task.render unless task.private? end final end diff --git a/lib/puppet-strings/markdown/resource_type.rb b/lib/puppet-strings/markdown/resource_type.rb index 7455c8d5d..f1b4393b3 100644 --- a/lib/puppet-strings/markdown/resource_type.rb +++ b/lib/puppet-strings/markdown/resource_type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/markdown/base' module PuppetStrings::Markdown diff --git a/lib/puppet-strings/markdown/resource_types.rb b/lib/puppet-strings/markdown/resource_types.rb index 3f48765d2..01abe1c65 100644 --- a/lib/puppet-strings/markdown/resource_types.rb +++ b/lib/puppet-strings/markdown/resource_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'resource_type' module PuppetStrings::Markdown @@ -19,7 +21,7 @@ def self.contains_private? def self.render final = in_rtypes.length > 0 ? "## Resource types\n\n" : "" in_rtypes.each do |type| - final << type.render unless type.private? + final += type.render unless type.private? end final end diff --git a/lib/puppet-strings/markdown/table_of_contents.rb b/lib/puppet-strings/markdown/table_of_contents.rb index 54aaa5bca..89883ecae 100644 --- a/lib/puppet-strings/markdown/table_of_contents.rb +++ b/lib/puppet-strings/markdown/table_of_contents.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PuppetStrings::Markdown module TableOfContents def self.render @@ -16,7 +18,7 @@ def self.render priv = r.contains_private? template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb") - final << ERB.new(File.read(template), nil, '-').result(binding) + final += ERB.new(File.read(template), nil, '-').result(binding) end final end diff --git a/lib/puppet-strings/monkey_patches/display_object_command.rb b/lib/puppet-strings/monkey_patches/display_object_command.rb index 3c6fca68d..f82d52bc9 100644 --- a/lib/puppet-strings/monkey_patches/display_object_command.rb +++ b/lib/puppet-strings/monkey_patches/display_object_command.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Monkey patch URL decoding in object displays. Usually :: is interpreted as a # namespace, but this is disabled in our base object, and so instead gets # URL-encoded. diff --git a/lib/puppet-strings/tasks.rb b/lib/puppet-strings/tasks.rb index 255ff6017..901c67f9e 100644 --- a/lib/puppet-strings/tasks.rb +++ b/lib/puppet-strings/tasks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rake' require 'rake/tasklib' diff --git a/lib/puppet-strings/tasks/generate.rb b/lib/puppet-strings/tasks/generate.rb index 228fd82e5..d5e98c15f 100644 --- a/lib/puppet-strings/tasks/generate.rb +++ b/lib/puppet-strings/tasks/generate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings' # Implements the strings:generate task. diff --git a/lib/puppet-strings/tasks/gh_pages.rb b/lib/puppet-strings/tasks/gh_pages.rb index 5fee8f220..857c84fc0 100644 --- a/lib/puppet-strings/tasks/gh_pages.rb +++ b/lib/puppet-strings/tasks/gh_pages.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/tasks' namespace :strings do @@ -5,6 +7,7 @@ task :checkout do if Dir.exist?('doc') fail "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git') + Dir.chdir('doc') do system 'git checkout gh-pages' system 'git pull --rebase origin gh-pages' diff --git a/lib/puppet-strings/version.rb b/lib/puppet-strings/version.rb index 7429bea02..aea3cde21 100644 --- a/lib/puppet-strings/version.rb +++ b/lib/puppet-strings/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PuppetStrings - VERSION = '2.5.0'.freeze + VERSION = '2.5.0' end diff --git a/lib/puppet-strings/yard.rb b/lib/puppet-strings/yard.rb index f7e4c4038..0d6111737 100644 --- a/lib/puppet-strings/yard.rb +++ b/lib/puppet-strings/yard.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yard' # Module for YARD related functionality. @@ -102,6 +104,7 @@ def stats_for_puppet_tasks def stats_for_puppet_plans return unless PuppetStrings.puppet_5? + output 'Puppet Plans', *type_statistics_all(:puppet_plan) end diff --git a/lib/puppet-strings/yard/code_objects.rb b/lib/puppet-strings/yard/code_objects.rb index f4f6f92b9..9f77bbc52 100644 --- a/lib/puppet-strings/yard/code_objects.rb +++ b/lib/puppet-strings/yard/code_objects.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # The module for custom YARD code objects. module PuppetStrings::Yard::CodeObjects require 'puppet-strings/yard/code_objects/class' diff --git a/lib/puppet-strings/yard/code_objects/base.rb b/lib/puppet-strings/yard/code_objects/base.rb index ba9840ebc..c6e23cec7 100644 --- a/lib/puppet-strings/yard/code_objects/base.rb +++ b/lib/puppet-strings/yard/code_objects/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Implements the base code object. class PuppetStrings::Yard::CodeObjects::Base < YARD::CodeObjects::NamespaceObject # Allocates a new code object. diff --git a/lib/puppet-strings/yard/code_objects/class.rb b/lib/puppet-strings/yard/code_objects/class.rb index 4a65c4b30..2a3c9b1c7 100644 --- a/lib/puppet-strings/yard/code_objects/class.rb +++ b/lib/puppet-strings/yard/code_objects/class.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' # Implements the group for Puppet classes. @@ -52,8 +54,8 @@ def to_hash hash[:inherits] = statement.parent_class if statement.parent_class hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten] - hash[:defaults] = defaults unless defaults.empty? - hash[:source] = source unless source && source.empty? + hash[:defaults] = defaults unless defaults.nil? || defaults.empty? + hash[:source] = source unless source.nil? || source.empty? hash end end diff --git a/lib/puppet-strings/yard/code_objects/data_type.rb b/lib/puppet-strings/yard/code_objects/data_type.rb index c7d2fa88b..264c004b3 100644 --- a/lib/puppet-strings/yard/code_objects/data_type.rb +++ b/lib/puppet-strings/yard/code_objects/data_type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' require 'puppet-strings/yard/util' @@ -86,8 +88,8 @@ def to_hash hash[:file] = file hash[:line] = line hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) - hash[:defaults] = defaults unless defaults.empty? - hash[:source] = source unless source && source.empty? + hash[:defaults] = defaults unless defaults.nil? || defaults.empty? + hash[:source] = source unless source.nil? || source.empty? hash[:functions] = functions.map do |func| { name: func.name, diff --git a/lib/puppet-strings/yard/code_objects/data_type_alias.rb b/lib/puppet-strings/yard/code_objects/data_type_alias.rb index 324145628..24b2d9145 100644 --- a/lib/puppet-strings/yard/code_objects/data_type_alias.rb +++ b/lib/puppet-strings/yard/code_objects/data_type_alias.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' require 'puppet-strings/yard/util' diff --git a/lib/puppet-strings/yard/code_objects/defined_type.rb b/lib/puppet-strings/yard/code_objects/defined_type.rb index 7a0c3df50..a77e8100c 100644 --- a/lib/puppet-strings/yard/code_objects/defined_type.rb +++ b/lib/puppet-strings/yard/code_objects/defined_type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' # Implements the group for Puppet defined types. @@ -51,8 +53,8 @@ def to_hash hash[:line] = line hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten] - hash[:defaults] = defaults unless defaults.empty? - hash[:source] = source unless source && source.empty? + hash[:defaults] = defaults unless defaults.nil? || defaults.empty? + hash[:source] = source unless source.nil? || source.empty? hash end end diff --git a/lib/puppet-strings/yard/code_objects/function.rb b/lib/puppet-strings/yard/code_objects/function.rb index 121702151..d31574bae 100644 --- a/lib/puppet-strings/yard/code_objects/function.rb +++ b/lib/puppet-strings/yard/code_objects/function.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' # Implements the group for Puppet functions. @@ -61,11 +63,12 @@ def function_type # @return [String] Returns the Puppet signature of the function. def signature return '' if self.has_tag? :overload + tags = self.tags(:param) args = @parameters.map do |parameter| name, default = parameter tag = tags.find { |t| t.name == name } if tags - type = tag && tag.types ? "#{tag.type} " : 'Any ' + type = tag&.types ? "#{tag.type} " : 'Any ' prefix = "#{name[0]}" if name.start_with?('*', '&') name = name[1..-1] if prefix default = " = #{default}" if default @@ -96,8 +99,8 @@ def to_hash hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten] - hash[:defaults] = defaults unless defaults.empty? - hash[:source] = source unless source && source.empty? + hash[:defaults] = defaults unless defaults.nil? || defaults.empty? + hash[:source] = source unless source.nil? || source.empty? hash end end diff --git a/lib/puppet-strings/yard/code_objects/group.rb b/lib/puppet-strings/yard/code_objects/group.rb index f3becacfa..c4f69924e 100644 --- a/lib/puppet-strings/yard/code_objects/group.rb +++ b/lib/puppet-strings/yard/code_objects/group.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/base' # Implements the base class for "groups". @@ -10,6 +12,7 @@ class PuppetStrings::Yard::CodeObjects::Group < PuppetStrings::Yard::CodeObjects def self.instance(key) instance = P(:root, key) return instance unless instance.is_a?(YARD::CodeObjects::Proxy) + instance = self.new(:root, key) instance.visibility = :hidden P(:root).children << instance diff --git a/lib/puppet-strings/yard/code_objects/plan.rb b/lib/puppet-strings/yard/code_objects/plan.rb index 670f641ed..0eb483c3b 100644 --- a/lib/puppet-strings/yard/code_objects/plan.rb +++ b/lib/puppet-strings/yard/code_objects/plan.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' class PuppetStrings::Yard::CodeObjects::Plans < PuppetStrings::Yard::CodeObjects::Group @@ -49,8 +51,8 @@ def to_hash hash[:line] = line hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten] - hash[:defaults] = defaults unless defaults.empty? - hash[:source] = source unless source && source.empty? + hash[:defaults] = defaults unless defaults.nil? || defaults.empty? + hash[:source] = source unless source.nil? || source.empty? hash end end diff --git a/lib/puppet-strings/yard/code_objects/provider.rb b/lib/puppet-strings/yard/code_objects/provider.rb index beab62385..d312ef122 100644 --- a/lib/puppet-strings/yard/code_objects/provider.rb +++ b/lib/puppet-strings/yard/code_objects/provider.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' # Implements the group for Puppet providers. @@ -42,6 +44,7 @@ def type # @return [void] def add_confine(key, value) return unless key && value + @confines ||= {} @confines[key] = value end @@ -51,6 +54,7 @@ def add_confine(key, value) # @return [void] def add_feature(feature) return unless feature + @features ||= [] @features << feature end @@ -60,6 +64,7 @@ def add_feature(feature) # @return [void] def add_default(constraints) return unless constraints + @defaults ||= [] @defaults << constraints end @@ -70,6 +75,7 @@ def add_default(constraints) # @return [void] def add_command(key, value) return unless key && value + @commands ||= {} @commands[key] = value end diff --git a/lib/puppet-strings/yard/code_objects/task.rb b/lib/puppet-strings/yard/code_objects/task.rb index b3c37bcc5..7d0f50069 100644 --- a/lib/puppet-strings/yard/code_objects/task.rb +++ b/lib/puppet-strings/yard/code_objects/task.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' # Implements the group for Puppet tasks. diff --git a/lib/puppet-strings/yard/code_objects/type.rb b/lib/puppet-strings/yard/code_objects/type.rb index 532106bb8..41300e512 100644 --- a/lib/puppet-strings/yard/code_objects/type.rb +++ b/lib/puppet-strings/yard/code_objects/type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects/group' require 'puppet-strings/yard/util' @@ -167,6 +169,7 @@ def parameters def providers providers = YARD::Registry.all("puppet_providers_#{name}".intern) return providers if providers.empty? + providers.first.children end diff --git a/lib/puppet-strings/yard/handlers.rb b/lib/puppet-strings/yard/handlers.rb index 705dcd48e..988eb24eb 100644 --- a/lib/puppet-strings/yard/handlers.rb +++ b/lib/puppet-strings/yard/handlers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # The module for custom YARD handlers. module PuppetStrings::Yard::Handlers # The module for custom Ruby YARD handlers. diff --git a/lib/puppet-strings/yard/handlers/helpers.rb b/lib/puppet-strings/yard/handlers/helpers.rb index 38ddfa737..2968571d4 100644 --- a/lib/puppet-strings/yard/handlers/helpers.rb +++ b/lib/puppet-strings/yard/handlers/helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PuppetStrings::Yard::Handlers::Helpers # Logs a warning if a summary tag has more than 140 characters def self.validate_summary_tag(object) diff --git a/lib/puppet-strings/yard/handlers/json/base.rb b/lib/puppet-strings/yard/handlers/json/base.rb index ff8151e3f..13eece9ae 100644 --- a/lib/puppet-strings/yard/handlers/json/base.rb +++ b/lib/puppet-strings/yard/handlers/json/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PuppetStrings::Yard::Handlers::JSON::Base < YARD::Handlers::Base def self.handles?(statement) handlers.any? {|handler| statement.is_a?(handler)} diff --git a/lib/puppet-strings/yard/handlers/json/task_handler.rb b/lib/puppet-strings/yard/handlers/json/task_handler.rb index f0b081480..ee9fad4ef 100644 --- a/lib/puppet-strings/yard/handlers/json/task_handler.rb +++ b/lib/puppet-strings/yard/handlers/json/task_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/json/base' require 'puppet-strings/yard/parsers' require 'puppet-strings/yard/parsers/json/parser' diff --git a/lib/puppet-strings/yard/handlers/puppet/base.rb b/lib/puppet-strings/yard/handlers/puppet/base.rb index df81ab9d8..5ad2062a4 100644 --- a/lib/puppet-strings/yard/handlers/puppet/base.rb +++ b/lib/puppet-strings/yard/handlers/puppet/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Implements the base handler for Puppet language handlers. class PuppetStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base # Determine sif the handler handles the given statement. @@ -17,6 +19,7 @@ def set_parameter_types(object) tags = object.tags(:param) 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' end diff --git a/lib/puppet-strings/yard/handlers/puppet/class_handler.rb b/lib/puppet-strings/yard/handlers/puppet/class_handler.rb index b13772fc7..fc1c784d3 100644 --- a/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +++ b/lib/puppet-strings/yard/handlers/puppet/class_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/puppet/base' require 'puppet-strings/yard/parsers' diff --git a/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb b/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb index 39eb9a6ad..3561e147b 100644 --- a/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +++ b/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/puppet/base' require 'puppet-strings/yard/parsers' diff --git a/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb b/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb index b2a32bd82..9bd9b1c94 100644 --- a/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +++ b/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/puppet/base' require 'puppet-strings/yard/parsers' diff --git a/lib/puppet-strings/yard/handlers/puppet/function_handler.rb b/lib/puppet-strings/yard/handlers/puppet/function_handler.rb index fe3c94481..e3cddebc2 100644 --- a/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +++ b/lib/puppet-strings/yard/handlers/puppet/function_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/puppet/base' require 'puppet-strings/yard/parsers' diff --git a/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb b/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb index 54d241ed2..246ccce39 100644 --- a/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +++ b/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/puppet/base' require 'puppet-strings/yard/parsers' diff --git a/lib/puppet-strings/yard/handlers/ruby/base.rb b/lib/puppet-strings/yard/handlers/ruby/base.rb index fdac0aee6..39da8232e 100644 --- a/lib/puppet-strings/yard/handlers/ruby/base.rb +++ b/lib/puppet-strings/yard/handlers/ruby/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ripper' # Implements the base handler for Ruby language handlers. @@ -12,6 +14,7 @@ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base # @return [String] Returns a string representation of the node or nil if a string representation was not possible. def node_as_string(node) return nil unless node + case node.type when :symbol, :symbol_literal node.source[1..-1] @@ -42,8 +45,10 @@ def node_as_string(node) def get_name(statementobject, statementtype) parameters = statementobject.parameters(false) raise YARD::Parser::UndocumentableError, "Expected at least one parameter to #{statementtype} at #{statementobject.file}:#{statementobject.line}." if parameters.empty? + name = node_as_string(parameters.first) raise YARD::Parser::UndocumentableError, "Expected a symbol or string literal for first parameter but found '#{parameters.first.type}' at #{statement.file}:#{statement.line}." unless name + name end end diff --git a/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb b/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb index 8f458ab9f..54f85e33e 100644 --- a/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/ruby/base' require 'puppet-strings/yard/code_objects' @@ -10,8 +12,10 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard process do return unless statement.count > 1 + ruby_module_name = statement[0].source return unless ruby_module_name == 'Puppet::DataTypes' || ruby_module_name == 'DataTypes' # rubocop:disable Style/MultipleComparison This reads better + object = get_datatype_yard_object(get_name(statement, 'Puppet::DataTypes.create_type')) # Extract the interface definition type_interface = extract_data_type_interface @@ -65,8 +69,10 @@ def extract_data_type_interface next false unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) && node.method_name && node.method_name.source == 'interface' + parameters = node.parameters(false) next false unless parameters.count >= 1 + interface_string = node_as_string(parameters[0]) next false unless interface_string @@ -97,8 +103,10 @@ def extract_data_type_interface # @return [YARD::Parser::Ruby::AstNode, nil] def find_ruby_ast_node(ast_node, recurse = false, &block) raise ArgumentError, 'find_ruby_ast_node requires a block' unless block_given? + is_found = yield ast_node return ast_node if is_found + if ast_node.respond_to?(:children) ast_node.children.each do |child_node| child_found = find_ruby_ast_node(child_node, recurse, &block) @@ -128,7 +136,7 @@ def find_ruby_ast_node(ast_node, recurse = false, &block) # Anything else is ignored class LazyLiteralEvaluator def initialize - @literal_visitor ||= ::Puppet::Pops::Visitor.new(self, "literal", 0, 0) + @literal_visitor = ::Puppet::Pops::Visitor.new(self, "literal", 0, 0) end def literal(ast) @@ -136,72 +144,72 @@ def literal(ast) end # ----- The following methods are different/additions from the original Literal_evaluator - def literal_Object(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_Object(o) # Ignore any other object types end - def literal_AccessExpression(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_AccessExpression(o) # Extract the raw text of the Access Expression ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(o).extract_text end - def literal_QualifiedReference(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_QualifiedReference(o) # Extract the raw text of the Qualified Reference ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(o).extract_text end # ----- The following methods are the same as the original Literal_evaluator - def literal_Factory(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_Factory(o) literal(o.model) end - def literal_Program(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_Program(o) literal(o.body) end - def literal_LiteralString(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralString(o) o.value end - def literal_QualifiedName(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_QualifiedName(o) o.value end - def literal_LiteralNumber(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralNumber(o) o.value end - def literal_UnaryMinusExpression(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_UnaryMinusExpression(o) -1 * literal(o.expr) end - def literal_LiteralBoolean(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralBoolean(o) o.value end - def literal_LiteralUndef(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralUndef(o) nil end - def literal_LiteralDefault(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralDefault(o) :default end - def literal_LiteralRegularExpression(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralRegularExpression(o) o.value end - def literal_ConcatenatedString(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_ConcatenatedString(o) # use double quoted string value if there is no interpolation throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Model::LiteralString) o.segments[0].value end - def literal_LiteralList(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralList(o) o.values.map { |v| literal(v) } end - def literal_LiteralHash(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def literal_LiteralHash(o) o.entries.reduce({}) do |result, entry| result[literal(entry.key)] = literal(entry.value) result @@ -275,8 +283,10 @@ def validate_param_tags!(object, actual_params_hash) # Find param tags with a type that is different from the actual definition object.tags(:param).reject { |tag| tag.types.nil? }.each do |tag| next if actual_params_hash[tag.name].nil? + actual_data_type = actual_params_hash[tag.name][:types] next if actual_data_type.nil? + log.warn "The @param tag for '#{tag.name}' has a different type definition than the actual attribute near #{object.file}:#{object.line}." if tag.types != actual_data_type end @@ -290,6 +300,7 @@ def validate_param_tags!(object, actual_params_hash) # Set the type in the param tag object.tags(:param).each do |tag| next if actual_params_hash[tag.name].nil? + tag.types = actual_params_hash[tag.name][:types] end end @@ -311,10 +322,13 @@ def validate_methods!(object, actual_functions_hash) # Functions with the wrong return type object.meths.each do |meth| next unless actual_func_names.include?(meth.name.to_s) + return_tag = meth.docstring.tag(:return) next if return_tag.nil? + actual_return_types = [actual_functions_hash[meth.name.to_s][:return_type]] next if return_tag.types == actual_return_types + log.warn "The @return tag for '#{meth.name}' has a different type definition than the actual function near #{object.file}:#{object.line}. Expected #{actual_return_types}" return_tag.types = actual_return_types end @@ -329,6 +343,7 @@ def validate_methods!(object, actual_functions_hash) # Add the return type for the methods if missing object.meths.each do |meth| next unless meth.docstring.tag(:return).nil? + meth.docstring.add_tag(YARD::Tags::Tag.new(:return, '', actual_functions_hash[meth.name.to_s][:return_type])) end @@ -336,6 +351,7 @@ def validate_methods!(object, actual_functions_hash) object.meths.each do |meth| validate_function_method!(object, meth, actual_functions_hash[meth.name.to_s]) next unless meth.docstring.tag(:return).nil? + meth.docstring.add_tag(YARD::Tags::Tag.new(:return, '', actual_functions_hash[meth.name.to_s][:return_type])) end diff --git a/lib/puppet-strings/yard/handlers/ruby/function_handler.rb b/lib/puppet-strings/yard/handlers/ruby/function_handler.rb index fffe831ee..07b4fd37b 100644 --- a/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/function_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/ruby/base' require 'puppet-strings/yard/code_objects' @@ -29,6 +31,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard # newline, YARD ignores the namespace and uses `newfunction` as the source of the # first statement. return unless statement.count > 1 + module_name = statement[0].source return unless module_name == 'Puppet::Functions' || module_name == 'Puppet::Parser::Functions' || module_name == 'newfunction' @@ -219,8 +222,7 @@ def add_method_overload(object, node) # Populate the required parameters params = parameters.unnamed_required_params - if params - params.each do |parameter| + params&.each do |parameter| add_param_tag( overload_tag, param_tags, @@ -229,12 +231,10 @@ def add_method_overload(object, node) parameter.line ) end - end # Populate the optional parameters params = parameters.unnamed_optional_params - if params - params.each do |parameter| + params&.each do |parameter| add_param_tag( overload_tag, param_tags, @@ -246,7 +246,6 @@ def add_method_overload(object, node) true ) end - end # Populate the splat parameter param = parameters.splat_param @@ -301,7 +300,7 @@ def add_param_tag(object, tags, name, file, line, type = nil, default = nil, opt name = '&' + name end - type ||= tag && tag.types ? tag.type : 'Any' + type ||= tag&.types ? tag.type : 'Any' type = optional ? "Optional[#{type}]" : type object.parameters << [name, to_puppet_literal(default)] @@ -328,6 +327,7 @@ def validate_overload(overload, file, line) # Validate that tags have matching parameters overload.tags(:param).each do |tag| next if overload.parameters.find { |p| tag.name == p[0] } + log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{file}:#{line}." end end @@ -338,9 +338,11 @@ def get_3x_docstring(name) parameters[1].each do |kvp| next unless kvp.count == 2 next unless node_as_string(kvp[0]) == 'doc' + docstring = node_as_string(kvp[1]) log.error "Failed to parse docstring for 3.x Puppet function '#{name}' near #{statement.file}:#{statement.line}." and return nil unless docstring + return PuppetStrings::Yard::Util.scrub_string(docstring) end end diff --git a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb index 8723c33e7..c12b159f1 100644 --- a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/ruby/base' require 'puppet-strings/yard/code_objects' @@ -20,6 +22,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard # Extract the type name type_call_parameters = type_call.parameters(false) return unless type_call_parameters.count >= 1 + type_name = node_as_string(type_call_parameters.first) raise YARD::Parser::UndocumentableError, "Could not determine the resource type name for the provider defined at #{statement.file}:#{statement.line}." unless type_name @@ -47,8 +50,10 @@ def register_provider_docstring(object) if child.type == :assign ivar = child.jump(:ivar) next unless ivar != child && ivar.source == '@doc' + docstring = node_as_string(child[1]) log.error "Failed to parse docstring for Puppet provider '#{object.name}' (resource type '#{object.type_name}') near #{child.file}:#{child.line}." and return nil unless docstring + register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil) return nil elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode) @@ -60,6 +65,7 @@ def register_provider_docstring(object) docstring = node_as_string(child.parameters[0]) log.error "Failed to parse docstring for Puppet provider '#{object.name}' (resource type '#{object.type_name}') near #{child.file}:#{child.line}." and return nil unless docstring + register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil) return nil end @@ -71,6 +77,7 @@ def populate_provider_data(object) # Traverse the block looking for confines/defaults/commands block = statement.block return unless block && block.count >= 2 + block[1].children.each do |node| next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) && node.method_name @@ -80,8 +87,10 @@ def populate_provider_data(object) if method_name == 'confine' # Add a confine to the object next unless parameters.count >= 1 + parameters[0].each do |kvp| next unless kvp.count == 2 + object.add_confine(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source) end elsif method_name == 'has_feature' || method_name == 'has_features' @@ -92,9 +101,11 @@ def populate_provider_data(object) elsif method_name == 'defaultfor' # Add a default to the object next unless parameters.count >= 1 + # Some defaultfor statements contain multiple constraints. parameters.each do |kvps| next unless kvps.count >= 1 + defaultfor = [] kvps.each do |kvp| defaultfor << [node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source] @@ -104,8 +115,10 @@ def populate_provider_data(object) elsif method_name == 'commands' # Add the commands to the object next unless parameters.count >= 1 + parameters[0].each do |kvp| next unless kvp.count == 2 + object.add_command(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source) end end diff --git a/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb b/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb index 735e28f45..19f50b209 100644 --- a/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/ruby/base' require 'puppet-strings/yard/code_objects' @@ -6,7 +8,7 @@ # Implements the handler for Puppet resource types written in Ruby. class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::Handlers::Ruby::Base # The default docstring when ensurable is used without given a docstring. - DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze + DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.' namespace_only handles method_call(:register_type) @@ -14,6 +16,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H process do # Only accept calls to Puppet::ResourceApi return unless statement.count > 1 + module_name = statement[0].source return unless ['Puppet::ResourceApi'].include? module_name diff --git a/lib/puppet-strings/yard/handlers/ruby/type_base.rb b/lib/puppet-strings/yard/handlers/ruby/type_base.rb index 6851da918..09da6e86f 100644 --- a/lib/puppet-strings/yard/handlers/ruby/type_base.rb +++ b/lib/puppet-strings/yard/handlers/ruby/type_base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/ruby/base' class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handlers::Ruby::Base @@ -22,8 +24,10 @@ def find_docstring(node, kind) if child.type == :assign ivar = child.jump(:ivar) next unless ivar != child && ivar.source == '@doc' + docstring = node_as_string(child[1]) log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring + return PuppetStrings::Yard::Util.scrub_string(docstring) elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode) # Look for a call to a dispatch method with a block @@ -33,6 +37,7 @@ def find_docstring(node, kind) docstring = node_as_string(child.parameters[0]) log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring + return PuppetStrings::Yard::Util.scrub_string(docstring) end end @@ -69,6 +74,7 @@ def set_values(node, object) if method_name == 'newvalue' next unless parameters.count >= 1 + object.add(node_as_string(parameters[0]) || parameters[0].source) elsif method_name == 'newvalues' parameters.each do |p| @@ -76,9 +82,11 @@ def set_values(node, object) end elsif method_name == 'aliasvalue' next unless parameters.count >= 2 + object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source) elsif method_name == 'defaultto' next unless parameters.count >= 1 + object.default = node_as_string(parameters[0]) || parameters[0].source elsif method_name == 'isnamevar' object.isnamevar = true @@ -103,6 +111,7 @@ def set_values(node, object) parameters[1].each do |kvp| next unless kvp.count == 2 next unless node_as_string(kvp[0]) == 'parent' + if kvp[1].source == 'Puppet::Parameter::Boolean' object.add('true') unless object.values.include? 'true' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1 object.add('false') unless object.values.include? 'false' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1 @@ -117,19 +126,18 @@ def set_values(node, object) def set_default_namevar(object) return unless object.properties || object.parameters + default = nil - if object.properties - object.properties.each do |property| + object.properties&.each do |property| return nil if property.isnamevar + default = property if property.name == 'name' end - end - if object.parameters - object.parameters.each do |parameter| + object.parameters&.each do |parameter| return nil if parameter.isnamevar + default ||= parameter if parameter.name == 'name' end - end default.isnamevar = true if default end end diff --git a/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb b/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb index 28aae1bb6..889c380ea 100644 --- a/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/ruby/type_base' require 'puppet-strings/yard/code_objects' @@ -6,7 +8,7 @@ # Implements the handler for Puppet resource type newparam/newproperty calls written in Ruby. class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase # The default docstring when ensurable is used without given a docstring. - DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze + DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.' namespace_only handles method_call(:newparam) @@ -31,9 +33,10 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya # propertyname: "content" return unless (statement.count > 1) && (statement[0].children.count > 2) + module_name = statement[0].children[0].source method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source - return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type' + return unless ['Type', 'Puppet::Type'].include?(module_name) && method1_name == 'type' typename = get_name(statement[0], 'Puppet::Type.type') method2_name = caller_method diff --git a/lib/puppet-strings/yard/handlers/ruby/type_handler.rb b/lib/puppet-strings/yard/handlers/ruby/type_handler.rb index 4f0d7673a..084dfbc25 100644 --- a/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/type_handler.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/handlers/helpers' require 'puppet-strings/yard/handlers/ruby/type_base' require 'puppet-strings/yard/code_objects' @@ -6,7 +8,7 @@ # Implements the handler for Puppet resource types written in Ruby. class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase # The default docstring when ensurable is used without given a docstring. - DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze + DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.' namespace_only handles method_call(:newtype) @@ -14,6 +16,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha process do # Only accept calls to Puppet::Type return unless statement.count > 1 + module_name = statement[0].source return unless module_name == 'Puppet::Type' || module_name == 'Type' @@ -40,6 +43,7 @@ def populate_type_data(object) # Traverse the block looking for properties/parameters/features block = statement.block return unless block && block.count >= 2 + block[1].children.each do |node| next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) && node.method_name @@ -50,24 +54,31 @@ def populate_type_data(object) if method_name == 'newproperty' # Add a property to the object next unless parameters.count >= 1 + name = node_as_string(parameters[0]) next unless name + object.add_property(create_property(name, node)) elsif method_name == 'newparam' # Add a parameter to the object next unless parameters.count >= 1 + name = node_as_string(parameters[0]) next unless name + object.add_parameter(create_parameter(name, node)) elsif method_name == 'newcheck' # Add a check to the object next unless parameters.count >= 1 + name = node_as_string(parameters[0]) next unless name + object.add_check(create_check(name, node)) elsif method_name == 'feature' # Add a feature to the object next unless parameters.count >= 2 + name = node_as_string(parameters[0]) next unless name diff --git a/lib/puppet-strings/yard/parsers.rb b/lib/puppet-strings/yard/parsers.rb index 6353f0240..47b37dedf 100644 --- a/lib/puppet-strings/yard/parsers.rb +++ b/lib/puppet-strings/yard/parsers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # The module for custom YARD parsers. module PuppetStrings::Yard::Parsers # The module for custom YARD parsers for JSON. diff --git a/lib/puppet-strings/yard/parsers/json/parser.rb b/lib/puppet-strings/yard/parsers/json/parser.rb index 9a0c99385..c9199dcfa 100644 --- a/lib/puppet-strings/yard/parsers/json/parser.rb +++ b/lib/puppet-strings/yard/parsers/json/parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/parsers/json/task_statement' class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base diff --git a/lib/puppet-strings/yard/parsers/json/task_statement.rb b/lib/puppet-strings/yard/parsers/json/task_statement.rb index 5445e8591..9cead548f 100644 --- a/lib/puppet-strings/yard/parsers/json/task_statement.rb +++ b/lib/puppet-strings/yard/parsers/json/task_statement.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PuppetStrings::Yard::Parsers::JSON # Represents the Puppet Task statement. class TaskStatement diff --git a/lib/puppet-strings/yard/parsers/puppet/parser.rb b/lib/puppet-strings/yard/parsers/puppet/parser.rb index 13a20cf16..bb5335ee2 100644 --- a/lib/puppet-strings/yard/parsers/puppet/parser.rb +++ b/lib/puppet-strings/yard/parsers/puppet/parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet' require 'puppet/pops' require 'puppet-strings/yard/parsers/puppet/statement' @@ -26,8 +28,8 @@ def parse return end @statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact - rescue ::Puppet::ParseError => ex - log.error "Failed to parse #{@file}: #{ex.message}" + rescue ::Puppet::ParseError => e + log.error "Failed to parse #{@file}: #{e.message}" @statements = [] end @statements.freeze @@ -42,47 +44,47 @@ def enumerator private - def transform_Program(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_Program(o) # Cache the lines of the source text; we'll use this to locate comments @lines = o.source_text.lines.to_a o.definitions.map { |d| @visitor.visit(d) } end - def transform_Factory(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_Factory(o) @visitor.visit(o.current) end - def transform_HostClassDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_HostClassDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::ClassStatement.new(o, @file) statement.extract_docstring(@lines) statement end - def transform_ResourceTypeDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_ResourceTypeDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::DefinedTypeStatement.new(o, @file) statement.extract_docstring(@lines) statement end - def transform_FunctionDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_FunctionDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::FunctionStatement.new(o, @file) statement.extract_docstring(@lines) statement end - def transform_PlanDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_PlanDefinition(o) statement = PuppetStrings::Yard::Parsers::Puppet::PlanStatement.new(o, @file) statement.extract_docstring(@lines) statement end - def transform_TypeAlias(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_TypeAlias(o) statement = PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement.new(o, @file) statement.extract_docstring(@lines) statement end - def transform_Object(o) # rubocop:disable Naming/UncommunicativeMethodParamName + def transform_Object(o) # Ignore anything else (will be compacted out of the resulting array) end end diff --git a/lib/puppet-strings/yard/parsers/puppet/statement.rb b/lib/puppet-strings/yard/parsers/puppet/statement.rb index e5233229c..01d8a16ca 100644 --- a/lib/puppet-strings/yard/parsers/puppet/statement.rb +++ b/lib/puppet-strings/yard/parsers/puppet/statement.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet' require 'puppet/pops' @@ -32,11 +34,13 @@ def extract_docstring(lines) comment = [] (0..@line-2).reverse_each do |index| break unless index <= lines.count + line = lines[index].strip count = line.size line.gsub!(COMMENT_REGEX, '') # Break out if nothing was removed (wasn't a comment line) break unless line.size < count + comment << line end @comments_range = (@line - comment.size - 1..@line - 1) diff --git a/lib/puppet-strings/yard/tags.rb b/lib/puppet-strings/yard/tags.rb index b3b3a329d..89d3fb653 100644 --- a/lib/puppet-strings/yard/tags.rb +++ b/lib/puppet-strings/yard/tags.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # The module for custom YARD tags. module PuppetStrings::Yard::Tags require 'puppet-strings/yard/tags/factory' diff --git a/lib/puppet-strings/yard/tags/enum_tag.rb b/lib/puppet-strings/yard/tags/enum_tag.rb index 433cf2150..2ce82c75b 100644 --- a/lib/puppet-strings/yard/tags/enum_tag.rb +++ b/lib/puppet-strings/yard/tags/enum_tag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yard/tags/option_tag' # Implements an enum tag for describing enumerated value data types diff --git a/lib/puppet-strings/yard/tags/factory.rb b/lib/puppet-strings/yard/tags/factory.rb index 518726ad2..b2d5a6c23 100644 --- a/lib/puppet-strings/yard/tags/factory.rb +++ b/lib/puppet-strings/yard/tags/factory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yard/tags/default_factory' require 'puppet-strings/yard/tags/enum_tag' diff --git a/lib/puppet-strings/yard/tags/overload_tag.rb b/lib/puppet-strings/yard/tags/overload_tag.rb index 3c5f7e6f3..3b358cbca 100644 --- a/lib/puppet-strings/yard/tags/overload_tag.rb +++ b/lib/puppet-strings/yard/tags/overload_tag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Implements an overload tag for Puppet functions # # This differs from Yard's overload tag in that the signatures are formatted according to Puppet language rules. @@ -22,7 +24,7 @@ def signature args = @parameters.map do |parameter| name, default = parameter tag = tags.find { |t| t.name == name } if tags - type = tag && tag.types ? "#{tag.type} " : 'Any ' + type = tag&.types ? "#{tag.type} " : 'Any ' prefix = "#{name[0]}" if name.start_with?('*', '&') name = name[1..-1] if prefix default = " = #{default}" if default @@ -75,6 +77,7 @@ def object=(value) # @return Returns what the method call on the object would return. def method_missing(method_name, *args, &block) return object.send(method_name, *args, &block) if object.respond_to? method_name + super end diff --git a/lib/puppet-strings/yard/tags/parameter_directive.rb b/lib/puppet-strings/yard/tags/parameter_directive.rb index 9cf68f9b6..d84b537c9 100644 --- a/lib/puppet-strings/yard/tags/parameter_directive.rb +++ b/lib/puppet-strings/yard/tags/parameter_directive.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects' # Implements a parameter directive (e.g. #@!puppet.type.param) for documenting Puppet resource types. @@ -5,14 +7,13 @@ class PuppetStrings::Yard::Tags::ParameterDirective < YARD::Tags::Directive # Called to invoke the directive. # @return [void] def call - return unless object && object.respond_to?(:add_parameter) + return unless object&.respond_to?(:add_parameter) + # Add a parameter to the resource parameter = PuppetStrings::Yard::CodeObjects::Type::Parameter.new(tag.name, tag.text) - if tag.types - tag.types.each do |value| + tag.types&.each do |value| parameter.add(value) end - end object.add_parameter parameter end diff --git a/lib/puppet-strings/yard/tags/property_directive.rb b/lib/puppet-strings/yard/tags/property_directive.rb index a1c1e00be..db2c41296 100644 --- a/lib/puppet-strings/yard/tags/property_directive.rb +++ b/lib/puppet-strings/yard/tags/property_directive.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet-strings/yard/code_objects' # Implements a parameter directive (e.g. #@!puppet.type.property) for documenting Puppet resource types. @@ -5,14 +7,13 @@ class PuppetStrings::Yard::Tags::PropertyDirective < YARD::Tags::Directive # Called to invoke the directive. # @return [void] def call - return unless object && object.respond_to?(:add_property) + return unless object&.respond_to?(:add_property) + # Add a property to the resource property = PuppetStrings::Yard::CodeObjects::Type::Property.new(tag.name, tag.text) - if tag.types - tag.types.each do |value| + tag.types&.each do |value| property.add(value) end - end object.add_property property end diff --git a/lib/puppet-strings/yard/tags/summary_tag.rb b/lib/puppet-strings/yard/tags/summary_tag.rb index 63df5dacd..44e9dd541 100644 --- a/lib/puppet-strings/yard/tags/summary_tag.rb +++ b/lib/puppet-strings/yard/tags/summary_tag.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Implements a summary tag for general purpose short descriptions class PuppetStrings::Yard::Tags::SummaryTag < YARD::Tags::Tag diff --git a/lib/puppet-strings/yard/util.rb b/lib/puppet-strings/yard/util.rb index b25ce97d4..c2a5a82bd 100644 --- a/lib/puppet-strings/yard/util.rb +++ b/lib/puppet-strings/yard/util.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/util' # The module for various puppet-strings utility helpers. @@ -24,8 +26,9 @@ def self.scrub_string(str) # @return [String] HTML document with links converted def self.github_to_yard_links(data) data.scan(/href\=\"\#(.+)\"/).each do |bad_link| - data.gsub!("=\"##{bad_link.first}\"", "=\"#label-#{bad_link.first.capitalize.gsub('-', '+')}\"") + data = data.gsub("=\"##{bad_link.first}\"", "=\"#label-#{bad_link.first.capitalize.gsub('-', '+')}\"") end + data end diff --git a/lib/puppet/application/strings.rb b/lib/puppet/application/strings.rb index 5a4f06df5..39aaaabbf 100644 --- a/lib/puppet/application/strings.rb +++ b/lib/puppet/application/strings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/application/face_base' # Implements the 'puppet strings' application. diff --git a/lib/puppet/face/strings.rb b/lib/puppet/face/strings.rb index d612795bb..001a46899 100644 --- a/lib/puppet/face/strings.rb +++ b/lib/puppet/face/strings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/face' # Implements the 'puppet strings' interface. @@ -57,6 +59,7 @@ environment = Puppet.lookup(:current_environment) environment.modules.each do |mod| next unless modules.empty? || modules.include?(mod.name) + db = File.join(mod.path, '.yardoc') patterns = PuppetStrings::DEFAULT_SEARCH_PATTERNS.map do |p| File.join(mod.path, p) @@ -145,7 +148,7 @@ def check_required_features raise RuntimeError, "The 'yard' gem must be installed in order to use this face." unless Puppet.features.yard? raise RuntimeError, "The 'rgen' gem must be installed in order to use this face." unless Puppet.features.rgen? - raise RuntimeError, 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION =~ /^1\.8/ + raise RuntimeError, 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION.match?(/^1\.8/) end # Builds the options to PuppetStrings.generate. diff --git a/lib/puppet/feature/rgen.rb b/lib/puppet/feature/rgen.rb index 0ab92634d..d932a9f28 100644 --- a/lib/puppet/feature/rgen.rb +++ b/lib/puppet/feature/rgen.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/util/feature' Puppet.features.add(:rgen, :libs => ['rgen/metamodel_builder', 'rgen/ecore/ecore']) diff --git a/lib/puppet/feature/yard.rb b/lib/puppet/feature/yard.rb index aab7f6cd3..5b709f380 100644 --- a/lib/puppet/feature/yard.rb +++ b/lib/puppet/feature/yard.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/util/feature' Puppet.features.add(:yard, :libs => ['yard']) diff --git a/puppet-strings.gemspec b/puppet-strings.gemspec index 64f548faf..f6191c837 100644 --- a/puppet-strings.gemspec +++ b/puppet-strings.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'puppet-strings/version' @@ -11,7 +13,7 @@ Gem::Specification.new do |s| s.email = 'info@puppet.com' s.homepage = 'https://github.com/puppetlabs/puppet-strings' s.description = s.summary - s.required_ruby_version = '>= 2.1.0' + s.required_ruby_version = '>= 2.3.0' s.extra_rdoc_files = [ 'CHANGELOG.md', @@ -24,5 +26,5 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'yard', '~> 0.9.5' s.add_runtime_dependency 'rgen' - s.requirements << 'puppet, >= 4.0.0' + s.requirements << 'puppet, >= 5.0.0' end diff --git a/spec/acceptance/emit_json_options_spec.rb b/spec/acceptance/emit_json_options_spec.rb index c51b646db..12a3e4587 100644 --- a/spec/acceptance/emit_json_options_spec.rb +++ b/spec/acceptance/emit_json_options_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'Emitting JSON' do @@ -17,7 +19,7 @@ "puppet_functions" => [ "name" => "function3x", "file" => "#{@test_module_path}/lib/puppet/parser/functions/function3x.rb", - "line" => 1, + "line" => 3, "type" => "ruby3x", "signatures" => [ { diff --git a/spec/acceptance/generate_markdown_spec.rb b/spec/acceptance/generate_markdown_spec.rb index ac4c749db..71a488c50 100644 --- a/spec/acceptance/generate_markdown_spec.rb +++ b/spec/acceptance/generate_markdown_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'Generating Markdown' do diff --git a/spec/acceptance/running_strings_generate_spec.rb b/spec/acceptance/running_strings_generate_spec.rb index 317cdb028..c78ac5428 100644 --- a/spec/acceptance/running_strings_generate_spec.rb +++ b/spec/acceptance/running_strings_generate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' include PuppetLitmus # rubocop:disable Style/MixinUsage This is fine diff --git a/spec/fixtures/acceptance/modules/test/lib/puppet/datatypes/acceptancedatatype.rb b/spec/fixtures/acceptance/modules/test/lib/puppet/datatypes/acceptancedatatype.rb index d959d38e9..6702fd059 100644 --- a/spec/fixtures/acceptance/modules/test/lib/puppet/datatypes/acceptancedatatype.rb +++ b/spec/fixtures/acceptance/modules/test/lib/puppet/datatypes/acceptancedatatype.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # An example Acceptance Puppet Data Type in Ruby. # # @param param1 A variant parameter called param1. diff --git a/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb b/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb index 58254966e..1ece284cf 100644 --- a/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +++ b/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # function 4x # # This is a function which is used to test puppet strings diff --git a/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb b/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb index 12713cbb7..1f3ed0a72 100644 --- a/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +++ b/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + Puppet::Parser::Functions.newfunction(:function3x, :doc => "This is the function documentation for `function3x`") do |args| end diff --git a/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb b/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb index 7f354e16e..99be74e65 100644 --- a/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +++ b/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Puppet::Type.type(:database).provide :linux do confine 'osfamily' => 'linux' defaultfor 'osfamily' => 'linux' diff --git a/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb b/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb index ff9e8efb6..c1b1f63f5 100644 --- a/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +++ b/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @!puppet.type.param [value1, value2, value3] my_param Documentation for a dynamic parameter. # @!puppet.type.property [foo, bar, baz] my_prop Documentation for a dynamic property. Puppet::Type.newtype(:database) do diff --git a/spec/markdownlint_style.rb b/spec/markdownlint_style.rb index c7fbdfe03..54cf1cce8 100644 --- a/spec/markdownlint_style.rb +++ b/spec/markdownlint_style.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + all # Update line length to 120 chars. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fdb8f2ee9..2e6598dc0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if ENV['COVERAGE'] == 'yes' require 'simplecov' require 'simplecov-console' @@ -58,6 +60,7 @@ def mdl_available def lint_markdown(content) return [] unless mdl_available + require 'mdl' # Load default mdl ruleset @@ -74,6 +77,7 @@ def lint_markdown(content) ruleset.rules.each do |id, rule| error_lines = rule.check.call(doc) next if error_lines.nil? or error_lines.empty? + # record the error error_lines.each do |line| line += doc.offset # Correct line numbers for any yaml front matter diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 2f350f1b7..1f1702269 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def sut_module_path(module_regex) modules = JSON.parse(run_shell('puppet module list --render-as json').stdout) test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex } diff --git a/spec/unit/puppet-strings/describe_spec.rb b/spec/unit/puppet-strings/describe_spec.rb index ccc88a366..bd3b90894 100644 --- a/spec/unit/puppet-strings/describe_spec.rb +++ b/spec/unit/puppet-strings/describe_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/describe' require 'tempfile' diff --git a/spec/unit/puppet-strings/json_spec.rb b/spec/unit/puppet-strings/json_spec.rb index 2cfcbb66a..51b94ffca 100644 --- a/spec/unit/puppet-strings/json_spec.rb +++ b/spec/unit/puppet-strings/json_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/json' require 'tempfile' diff --git a/spec/unit/puppet-strings/markdown/base_spec.rb b/spec/unit/puppet-strings/markdown/base_spec.rb index ad818e59b..b9723e762 100644 --- a/spec/unit/puppet-strings/markdown/base_spec.rb +++ b/spec/unit/puppet-strings/markdown/base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PuppetStrings::Markdown::Base do diff --git a/spec/unit/puppet-strings/markdown_spec.rb b/spec/unit/puppet-strings/markdown_spec.rb index 4c71ec1db..c7c2b7be3 100644 --- a/spec/unit/puppet-strings/markdown_spec.rb +++ b/spec/unit/puppet-strings/markdown_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/markdown' require 'puppet-strings/markdown/table_of_contents' diff --git a/spec/unit/puppet-strings/yard/code_objects/task_spec.rb b/spec/unit/puppet-strings/yard/code_objects/task_spec.rb index 478700215..d4c7cf861 100644 --- a/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +++ b/spec/unit/puppet-strings/yard/code_objects/task_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard/code_objects/task' require 'puppet-strings/yard/parsers/json/task_statement' diff --git a/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb index fc2734175..d1af655d7 100644 --- a/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb index ab5d58a9e..9d00adc2a 100644 --- a/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb index 07da863f1..8bf55ee2d 100644 --- a/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb index 804dc5518..265c9db82 100644 --- a/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb index db2d62404..d8539e772 100644 --- a/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb index 853f33d56..146cf84f3 100644 --- a/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb index 6ddc48429..b54425f74 100644 --- a/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb index 7213684f3..cc1edd9bd 100644 --- a/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb index a3ff08b30..3bcde409f 100644 --- a/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb index e32dea2f6..dd7a8a6a0 100644 --- a/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb b/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb index e2bc336d1..d764231a1 100644 --- a/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +++ b/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb b/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb index 4fee3dbd4..bbcc1606c 100644 --- a/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +++ b/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PuppetStrings::Yard::Parsers::JSON::TaskStatement do diff --git a/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb b/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb index 1e83314f9..eefc0da4c 100644 --- a/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +++ b/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard' diff --git a/spec/unit/puppet-strings/yard/util_spec.rb b/spec/unit/puppet-strings/yard/util_spec.rb index 80a0c5496..148f9c0f6 100644 --- a/spec/unit/puppet-strings/yard/util_spec.rb +++ b/spec/unit/puppet-strings/yard/util_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet-strings/yard'