diff --git a/.fixtures.yml b/.fixtures.yml index d59a99b44..bb49d80ef 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,4 +3,5 @@ fixtures: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' provision: 'https://github.com/puppetlabs/provision.git' puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - symlinks: [] + symlinks: + test: "#{source_dir}/spec/fixtures/acceptance/modules/test" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00aaca050..feec48d3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,24 +1,53 @@ name: "ci" on: - schedule: - - cron: "0 0 * * *" + pull_request: + branches: + - "main" workflow_dispatch: jobs: - spec: + strategy: + 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: 'https://github.com/puppetlabs/puppet' # puppet8' + runs_on: + - "ubuntu-latest" + - "windows-latest" + name: "spec (${{ matrix.runs_on }} ruby ${{ matrix.ruby_version }} | puppet ${{matrix.puppet_gem_version}})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" + with: + ruby_version: ${{ matrix.ruby_version }} + puppet_gem_version: ${{ matrix.puppet_gem_version }} + runs_on: ${{ matrix.runs_on }} acceptance: needs: "spec" strategy: matrix: - puppet: - - "puppet6" - - "puppet7" + 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: + - "ubuntu-latest" + - "windows-latest" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" secrets: "inherit" with: - puppet_version: ${{ matrix.puppet }} + ruby_version: ${{ matrix.ruby_version }} + puppet_version: ${{ matrix.puppet_gem_version }} + runs_on: ${{ matrix.runs_on }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d6eddb512..b7af44609 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,25 +1,52 @@ name: "nightly" on: - pull_request: - branches: - - "main" + schedule: + - cron: "0 0 * * *" workflow_dispatch: jobs: - spec: + strategy: + 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: 'https://github.com/puppetlabs/puppet' # puppet8' + runs_on: + - "ubuntu-latest" + - "windows-latest" + name: "spec (${{ matrix.runs_on }} ruby ${{ matrix.ruby_version }} | puppet ${{matrix.puppet_gem_version}})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" + with: + ruby_version: ${{ matrix.ruby_version }} + puppet_gem_version: ${{ matrix.puppet_gem_version }} + runs_on: ${{ matrix.runs_on }} acceptance: needs: "spec" strategy: matrix: - puppet: - - "puppet6" - - "puppet7" + 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: + - "ubuntu-latest" + - "windows-latest" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" secrets: "inherit" with: - puppet_version: ${{ matrix.puppet }} + ruby_version: ${{ matrix.ruby_version }} + puppet_version: ${{ matrix.puppet_gem_version }} + runs_on: ${{ matrix.runs_on }} diff --git a/.rubocop.yml b/.rubocop.yml index 35821c9b1..2ccc89f3d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,520 +1,19 @@ ---- +inherit_from: .rubocop_todo.yml + require: -- rubocop-performance -- rubocop-rspec + - rubocop-performance + - rubocop-rspec + AllCops: - DisplayCopNames: true - TargetRubyVersion: '2.5' - Include: - - "**/*.rb" Exclude: - - bin/* - - ".vendor/**/*" - - "**/Gemfile" - - "**/Rakefile" - - pkg/**/* - - spec/fixtures/**/* - - vendor/**/* - - "**/Puppetfile" - - "**/Vagrantfile" - - "**/Guardfile" - - '**/*.erb' - - 'lib/puppet-strings/yard/templates/**/*' + - Gemfile + - Rakefile + - spec/fixtures/**/* + - vendor/bundle/**/* + NewCops: enable SuggestExtensions: false -Layout/LineLength: - Description: People have wide screens, use them. - Max: 200 -RSpec/BeforeAfterAll: - Description: Beware of using after(:all) as it may cause state to leak between tests. - A necessary evil in acceptance testing. - Exclude: - - spec/acceptance/**/*.rb -RSpec/HookArgument: - Description: Prefer explicit :each argument, matching existing module's style - EnforcedStyle: each -Style/BlockDelimiters: - Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to - be consistent then. - EnforcedStyle: braces_for_chaining + TargetRubyVersion: '2.7' + +# Disabled Style/ClassAndModuleChildren: - Description: Compact style reduces the required amount of indentation. - EnforcedStyle: compact -Style/EmptyElse: - Description: Enforce against empty else clauses, but allow `nil` for clarity. - EnforcedStyle: empty -Style/FormatString: - Description: Following the main puppet project's style, prefer the % format format. - EnforcedStyle: percent -Style/FormatStringToken: - Description: Following the main puppet project's style, prefer the simpler template - tokens over annotated ones. - EnforcedStyle: template -Style/Lambda: - Description: Prefer the keyword for easier discoverability. - EnforcedStyle: literal -Style/RegexpLiteral: - Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 - EnforcedStyle: percent_r -Style/TernaryParentheses: - Description: Checks for use of parentheses around ternary conditions. Enforce parentheses - on complex expressions for better readability, but seriously consider breaking - it up. - EnforcedStyle: require_parentheses_when_complex -Style/TrailingCommaInArguments: - Description: Prefer always trailing comma on multiline argument lists. This makes - diffs, and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/TrailingCommaInArrayLiteral: - Description: Prefer always trailing comma on multiline literals. This makes diffs, - and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/SymbolArray: - Description: Using percent style obscures symbolic intent of array's contents. - EnforcedStyle: brackets -RSpec/MessageSpies: - EnforcedStyle: receive -Style/Documentation: - Exclude: - - spec/**/* -Style/WordArray: - EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: true -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: true -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false -Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/FilePath: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..b91c658bc --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,198 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-13 12:45:07 UTC using RuboCop version 1.50.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +Naming/FileName: + Exclude: + - 'lib/puppet-strings.rb' + +Naming/MethodName: + Exclude: + - 'lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb' + - 'lib/puppet-strings/yard/parsers/puppet/parser.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'puppet-strings.gemspec' + +# Offense count: 46 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 98 + +# Offense count: 11 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 119 + +# Offense count: 1 +# Configuration parameters: CountBlocks. +Metrics/BlockNesting: + Max: 4 + +# Offense count: 5 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 283 + +# Offense count: 33 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 36 + +# Offense count: 44 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 75 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + MaxOptionalParameters: 5 + Max: 10 + +# Offense count: 28 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 37 + +# Offense count: 2 +Naming/AccessorMethodName: + Exclude: + - 'lib/puppet-strings/yard/handlers/puppet/base.rb' + - 'lib/puppet-strings/yard/handlers/ruby/type_base.rb' + +# Offense count: 1 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'spec/acceptance/generate_markdown_spec.rb' + +# Offense count: 24 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb' + - 'lib/puppet-strings/yard/parsers/puppet/parser.rb' + +# Offense count: 2 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'lib/puppet-strings/yard/handlers/ruby/provider_handler.rb' + - 'lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb' + +# Offense count: 1 +RSpec/BeforeAfterAll: + Exclude: + - 'spec/spec_helper.rb' + - 'spec/rails_helper.rb' + - 'spec/support/**/*.rb' + - 'spec/acceptance/running_strings_generate_spec.rb' + +# Offense count: 7 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/unit/puppet-strings/markdown/base_spec.rb' + - 'spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb' + - 'spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb' + - 'spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb' + +# Offense count: 3 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + - 'spec/acceptance/generate_json_spec.rb' + - 'spec/acceptance/generate_markdown_spec.rb' + - 'spec/acceptance/running_strings_generate_spec.rb' + +# Offense count: 48 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 66 + +# Offense count: 6 +RSpec/ExpectInHook: + Exclude: + - 'spec/unit/puppet-strings/json_spec.rb' + +# Offense count: 20 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: + Enabled: false + +# Offense count: 91 +RSpec/MultipleExpectations: + Max: 64 + +# Offense count: 5 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 4 + +# Offense count: 2 +RSpec/RepeatedExampleGroupDescription: + Exclude: + - 'spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb' + +# Offense count: 1 +Style/ClassVars: + Exclude: + - 'lib/puppet-strings/yard/templates/default/layout/html/setup.rb' + +# Offense count: 3 +Style/CombinableLoops: + Exclude: + - 'lib/puppet-strings/markdown.rb' + - 'lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb' + - 'lib/puppet-strings/tasks/generate.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/acceptance/running_strings_generate_spec.rb' + +# Offense count: 17 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'lib/puppet-strings.rb' + - 'lib/puppet-strings/describe.rb' + - 'lib/puppet-strings/yard/code_objects/class.rb' + - 'lib/puppet-strings/yard/code_objects/data_type.rb' + - 'lib/puppet-strings/yard/code_objects/data_type_alias.rb' + - 'lib/puppet-strings/yard/code_objects/defined_type.rb' + - 'lib/puppet-strings/yard/code_objects/function.rb' + - 'lib/puppet-strings/yard/code_objects/plan.rb' + - 'lib/puppet-strings/yard/code_objects/provider.rb' + - 'lib/puppet-strings/yard/code_objects/task.rb' + - '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: 139 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 200 diff --git a/COMMITTERS.md b/COMMITTERS.md deleted file mode 100644 index f0513bf58..000000000 --- a/COMMITTERS.md +++ /dev/null @@ -1,185 +0,0 @@ -Committing changes to Strings -==== - -We would like to make it easier for community members to contribute to strings -using pull requests, even if it makes the task of reviewing and committing -these changes a little harder. Pull requests are only ever based on a single -branch. As a result contributors should target their changes at the main branch. -This makes the process of contributing a little easier for the contributor since -they don't need to concern themselves with the question, "What branch do I base my changes -on?" This is already called out in the [CONTRIBUTING.md](http://goo.gl/XRH2J). - -Therefore, it is the responsibility of the committer to re-base the change set -on the appropriate branch which should receive the contribution. - -It is also the responsibility of the committer to review the change set in an -effort to make sure the end users must opt-in to new behavior that is -incompatible with previous behavior. We employ the use of [feature -flags](http://stackoverflow.com/questions/7707383/what-is-a-feature-flag) as -the primary way to achieve this user opt-in behavior. Finally, it is the -responsibility of the committer to make sure the `main` branch -is clean and working at all times. Clean means that dead code is not -allowed, everything needs to be usable in some manner at all points in time. - -The rest of this document addresses the concerns of the committer. This -document will help guide the committer decide which branch to base, or re-base -a contribution on top of. This document also describes our branch management -strategy, which is closely related to the decision of what branch to commit -changes into. - -Terminology -==== - -Many of these terms have more than one meaning. For the purposes of this -document, the following terms refer to specific things. - -**contributor** - A person who makes a change to strings and submits a change -set in the form of a pull request. - -**change set** - A set of discrete patches which combined together form a -contribution. A change set takes the form of Git commits and is submitted to -strings in the form of a pull request. - -**committer** - A person responsible for reviewing a pull request and then -making the decision what base branch to merge the change set into. - -**base branch** - A branch in Git that contains an active history of changes -and will eventually be released using semantic version guidelines. The branch -named `main` will always exist as a base branch. - -**main branch** - The branch where new functionality that and bug fixes are -merged. - -**security** - Where critical security fixes are merged. These change sets -will then be merged into release branches independently from one another. (i.e. -no merging up). Please do not submit pull requests against the security branch -and instead report all security related issues to security@puppet.com as -per our security policy published at -[https://puppet.com/security/](https://puppet.com/security/). - -Committer Guide -==== - -This section provides a guide to follow while committing change sets to strings -base branches. - -How to decide what release(s) should be patched ---- - -This section provides a guide to help a committer decide the specific base -branch that a change set should be merged into. - -The latest minor release of a major release is the only base branch that should -be patched. These patches will be merged into `main` if they contain new -functionality and if they fix a critical bug. Older minor releases in a major release -do not get patched. - -Before the switch to [semantic versions](http://semver.org/) committers did not -have to think about the difference between minor and major releases. -Committing to the latest minor release of a major release is a policy intended -to limit the number of active base branches that must be managed. - -Security patches are handled as a special case. Security patches may be -applied to earlier minor releases of a major release, but the patches should -first be merged into the `security` branch. Security patches should be merged -by Puppet Labs staff members. Pull requests should not be submitted with the -security branch as the base branch. Please send all security related -information or patches to security@puppet.com as per our [Security -Policy](https://puppet.com/security/). - -The CI systems are configured to run against `main`. Over time, this branch -will refer to different versions, but its name will remain fixed to avoid having -to update CI jobs and tasks as new versions are released. - -Code review checklist ---- - -This section aims to provide a checklist of things to look for when reviewing a -pull request and determining if the change set should be merged into a base -branch: - - * All tests pass - * Are there any platform gotchas? (Does a change make an assumption about - platform specific behavior that is incompatible with other platforms? e.g. - Windows paths vs. POSIX paths.) - * Is the change backwards compatible? (It should be) - * Are there YARD docs for API changes? - * Does the change set also require documentation changes? If so is the - documentation being kept up to date? - * Does the change set include clean code? (software code that is formatted - correctly and in an organized manner so that another coder can easily read - or modify it.) HINT: `git diff main --check` - * Does the change set conform to the contributing guide? - -Commit citizen guidelines: ---- - -This section aims to provide guidelines for being a good commit citizen by -paying attention to our automated build tools. - - * Don’t push on a broken build. (A broken build is defined as a failing job - in [Puppet Strings](https://travis-ci.com/github/puppetlabs/puppet-strings) - page.) - * Watch the build until your changes have gone through green - * Update the ticket status and target version. The target version field in - our issue tracker should be updated to be the next release of Puppet. For - example, if the most recent release of Puppet is 3.1.1 and you merge a - backwards compatible change set into main, then the target version should - be 3.2.0 in the issue tracker.) - * Ensure the pull request is closed (Hint: amend your merge commit to contain - the string `closes #123` where 123 is the pull request number and github - will automatically close the pull request when the branch is pushed.) - -Example Procedure -==== - -This section helps a committer rebase and merge a contribution into the base branch. - -Suppose a contributor submits a pull request based on main. The change set -fixes a bug reported against strings 0.1.0 which is the most recently released -version of strings. - -First, the committer pulls down the branch using the `hub` gem. This tool -automates the process of adding the remote repository and creating a local -branch to track the remote branch. - - $ hub checkout https://github.com/puppetlabs/puppet-strings/pull/123 - Branch jeffmccune-pdoc-34_fix_foo_error set up to track remote branch pdoc-34-fix_foo_error from jeffmccune. - Switched to a new branch 'jeffmccune-pdoc-34_fix_foo_error' - -It's possible that more changes have been merged into main since the pull -request was submitted. In this case it may be necessary to rebase the branch -that contains the changes: - - $ git rebase upstream/main - -After the branch has been checked out and rebased, the committer should ensure that -the code review check list has been completed. - -Now that we have a topic branch containing the change set based on the most recent -`main` branch, the committer merges in: - - $ git checkout main - Switched to branch 'main' - $ git merge --no-ff --log jeffmccune-pdoc-34_fix_foo_error - Merge made by the 'recursive' strategy. - foo | 0 - 1 file changed, 0 insertions(+), 0 deletions(-) - create mode 100644 foo - -Once the change set has been merged into one base branch, the change set should -not be modified in order to keep the history clean, avoid "double" commits, and -preserve the usefulness of `git branch --contains`. If there are any merge -conflicts, they are to be resolved in the merge commit itself and not by -re-writing (rebasing) the patches for one base branch, but not another. - -Once the change set has been merged into `main`, the committer pushes. -Please note, the checklist should be complete at this point. It's helpful to make -sure your local branches are up to date to avoid one of the branches failing to fast -forward while the other succeeds. - - $ git push origin main:main - -That's it! The committer then updates the pull request, updates the issue in -our issue tracker, and keeps an eye on the [build -status](http://jenkins.puppetlabs.com). diff --git a/Gemfile b/Gemfile index eff427aeb..5cf8c0a3c 100644 --- a/Gemfile +++ b/Gemfile @@ -4,18 +4,21 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" gemspec -gem 'rgen' -gem 'redcarpet' -gem 'yard', '~> 0.9.11' - -if ENV['PUPPET_GEM_VERSION'] - gem 'puppet', ENV['PUPPET_GEM_VERSION'], :require => false -else - gem 'puppet', :require => false +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] + else + [place_or_version, { require: false }] + end end group :development do - gem 'codecov' + gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION']) gem 'json_spec', '~> 1.1', '>= 1.1.5' @@ -24,6 +27,7 @@ group :development do gem 'pry', require: false gem 'pry-byebug', require: false gem 'pry-stack_explorer', require: false + # Need the following otherwise we end up with puppetlabs_spec_helper 1.1.1 gem 'mocha', '~> 1.0' gem 'puppetlabs_spec_helper' @@ -31,30 +35,19 @@ group :development do gem 'rake' gem 'rspec', '~> 3.1' gem 'rspec-its', '~> 1.0' - gem 'rubocop', '~> 1.6.1', require: false - gem 'rubocop-rspec', '~> 2.0.1', require: false - gem 'rubocop-performance', '~> 1.9.1', require: false + + gem 'rubocop', '~> 1.48', require: false + gem 'rubocop-performance', '~> 1.16', require: false + gem 'rubocop-rspec', '~> 2.19', require: false gem 'serverspec' - gem 'simplecov-console', require: false if ENV['COVERAGE'] == 'yes' - gem 'simplecov', require: false if ENV['COVERAGE'] == 'yes' + gem 'simplecov', require: false + gem 'simplecov-console', require: false + + gem 'redcarpet' end group :acceptance do gem 'puppet_litmus' gem 'net-ssh' end - -group :release do - gem 'github_changelog_generator', require: false -end - -# Evaluate Gemfile.local if it exists -if File.exists? "#{__FILE__}.local" - eval(File.read("#{__FILE__}.local"), binding) -end - -# Evaluate ~/.gemfile if it exists -if File.exists?(File.join(Dir.home, '.gemfile')) - eval(File.read(File.join(Dir.home, '.gemfile')), binding) -end diff --git a/HISTORY.md b/HISTORY.md deleted file mode 100644 index 57364a8f2..000000000 --- a/HISTORY.md +++ /dev/null @@ -1,218 +0,0 @@ -# Previous Changes - -## [2.0.0](https://github.com/puppetlabs/puppet-strings/tree/2.0.0) (2018-05-11) - -[Full Changelog](https://github.com/puppetlabs/puppet-strings/compare/1.2.1...2.0.0) - -### Changed - -- bump required ruby and puppet versions [\#178](https://github.com/puppetlabs/puppet-strings/pull/178) ([eputnam](https://github.com/eputnam)) - -### Added - -- \(PDOC-238\) add generated message to markdown [\#175](https://github.com/puppetlabs/puppet-strings/pull/175) ([eputnam](https://github.com/eputnam)) -- \(PDOC-228\) puppet plan support [\#168](https://github.com/puppetlabs/puppet-strings/pull/168) ([eputnam](https://github.com/eputnam)) -- \(PDOC-206\) support for tasks [\#161](https://github.com/puppetlabs/puppet-strings/pull/161) ([eputnam](https://github.com/eputnam)) - -### Fixed - -- \(PDOC-36\) fix hack for README urls [\#176](https://github.com/puppetlabs/puppet-strings/pull/176) ([eputnam](https://github.com/eputnam)) -- \(PDOC-240\) add handling for :array node type in rsapi\_handler [\#174](https://github.com/puppetlabs/puppet-strings/pull/174) ([eputnam](https://github.com/eputnam)) -- \(PDOC-159\) server urls fix [\#173](https://github.com/puppetlabs/puppet-strings/pull/173) ([eputnam](https://github.com/eputnam)) -- \(maint\) display Plans in markdown table of contents [\#171](https://github.com/puppetlabs/puppet-strings/pull/171) ([eputnam](https://github.com/eputnam)) -- \(PDOC-233\) markdown whitespace fixes [\#170](https://github.com/puppetlabs/puppet-strings/pull/170) ([JohnLyman](https://github.com/JohnLyman)) -- \(PDOC-229\) fix error with return\_type and @return [\#169](https://github.com/puppetlabs/puppet-strings/pull/169) ([eputnam](https://github.com/eputnam)) -- \(PDOC-36\) hack to fix README links in generated HTML [\#167](https://github.com/puppetlabs/puppet-strings/pull/167) ([eputnam](https://github.com/eputnam)) -- \(PDOC-192\) remove warning for title/name [\#166](https://github.com/puppetlabs/puppet-strings/pull/166) ([eputnam](https://github.com/eputnam)) -- \(maint\) add condition for misleading warning [\#155](https://github.com/puppetlabs/puppet-strings/pull/155) ([eputnam](https://github.com/eputnam)) - -## [1.2.1](https://github.com/puppetlabs/puppet-strings/tree/1.2.1) (2018-03-01) - -[Full Changelog](https://github.com/puppetlabs/puppet-strings/compare/1.2.0...1.2.1) - -### Fixed - -- (PDOC-224) Handle --emit-json(-stdout) again [\#162](https://github.com/puppetlabs/puppet-strings/pull/162) ([ekohl](https://github.com/ekohl)) - -## [1.2.0](https://github.com/puppetlabs/puppet-strings/tree/1.2.0) (2018-02-26) - -[Full Changelog](https://github.com/puppetlabs/puppet-strings/compare/1.1.1...1.2.0) - -### Added - -- \(PDOC-184\) generate markdown [\#156](https://github.com/puppetlabs/puppet-strings/pull/156) ([eputnam](https://github.com/eputnam)) -- \(PDK-437\) Add support for Resource API types [\#153](https://github.com/puppetlabs/puppet-strings/pull/153) ([DavidS](https://github.com/DavidS)) - -### Fixed - -- Fix return type matching for Puppet functions [\#159](https://github.com/puppetlabs/puppet-strings/pull/159) ([pegasd](https://github.com/pegasd)) -- Add rgen as a runtime dependency [\#149](https://github.com/puppetlabs/puppet-strings/pull/149) ([rnelson0](https://github.com/rnelson0)) - -## 2017-10-20 - Release 1.1.1 - -### BugFixes -- Remove timestamps from footer of generated HTML pages ([GeoffWilliams](https://github.com/GeoffWilliams)) -- Fix argument handling for `rake strings::generate` ([hashar](https://github.com/hashar)) - -### Other -- Fixed Markdown formatting issues in CHANGELOG ([maju6406](https://github.com/maju6406)) -- Fixed typo in README ([hfm](https://github.com/hfm)) -- Fixed Markdown formatting issues in README ([gguillotte](https://github.com/gguillotte)) -- Update Travis CI configurations for Ruby and Puppet versions ([ghoneycutt](https://github.com/ghoneycutt)) - -## 2017-03-20 - Release 1.1.0 - -### Summary - -This release adds a new `summary` tag which can be used to add a short description to classes, functions, types, and providers. In addition, `@param` tags can now include type information in Puppet 4 code without warnings being issued. - -All related tickets can be found under the [PDOC](https://tickets.puppetlabs.com/browse/PDOC) JIRA project with the fix version of [1.1.0](https://tickets.puppetlabs.com/issues/?filter=25603). - -### Features -- The `summary` tag can be added to any code that puppet-strings supports. The recommended length limit for a summary is 140 characters. Warnings will be issued for strings longer than this limit. -- Puppet 4 parameter types can now be explicitly documented. Previously, this was not allowed because Puppet 4 parameter types can be automatically determined without extra documentation. However, users may desire to do so anyway for consistency. Strings will emit a warning if the documented type does not match the actual type. In such an event, the incorrect documented type will be ignored in favor of the real one. - -## 2016-11-28 - Release 1.0.0 - -### Summary - -This release fixes up minor bugs from the 0.99.0 release and modifies the JSON schema for Puppet functions. - -All related tickets can be found under the [PDOC](https://tickets.puppetlabs.com/browse/PDOC) JIRA project with the fix version of [1.0.0](https://tickets.puppetlabs.com/issues/?filter=23607). - -### Features -- The JSON schema for Puppet functions has been altered to include a new 'signatures' top-level key **(PDOC-125)** - - Includes information about all function signatures (overloads). Existing overload key format has been preserved. -- Reworked README for enhanced clarity **(PDOC-133)** - -### BugFixes -- Fixed an issue where the search box in the code navigator overlapped list items below it **(PDOC-93)** -- Strings can now handle multiple `defaultfor` calls in Puppet providers **(PDOC-95)** -- Fixed an issue preventing the generated \_index.html file from being uploaded to GitHub pages via the gh_pages task **(PDOC-120)** -- Fixed several issues with String's handling of Puppet 3.x and 4.x function return types **(PDOC-135)**, **(PDOC-136)** -- Fixed an issue where String's didn't properly parse overloads if no summary description was provided **(PDOC-129)** -- Strings now correctly handles Puppet 3.x functions when the `newfunction` call is on a newline **(PDOC-122)** -- Fixed an issue where certain Ruby string constructs were incompletely stripped from some docstrings **(PDOC-126)** -- Hanging indents from type feature descriptions are now properly stripped **(PDOC-127)** - -## 2016-10-10 - Release 0.99.0 - -### Summary - -This release includes a complete rewrite of strings, fixing many bugs from previous versions and generally improving the user experience. This release is intended to be the last stop before the strings major version 1.0 is released, and nearly all of the functionality of the major release is included. - -All related tickets can be found under the [PDOC][PDOC JIRA] JIRA project with the fix version of [0.99.0](https://tickets.puppetlabs.com/issues/?filter=22705). - -### Features -- Complete overhaul, including code cleanup, bug fixes and new functionality **(PDOC-63)** - - Documentation has been split into sections based on type: puppet 3x API functions, puppet 4x API functions, ruby classes, puppet language functions, types, and providers - - New JSON schema organized to reflect the separation of types - - Support for custom functions written in the puppet language - - Support for puppet function overloads via the create_function 4.x API - - YARD bumped to latest version, 0.9.5 -- Markdown is now the default format for parsing docstring text **(PDOC-86)** - - Note: this means Markdown text in YARD comments and tags, not a change in the output of strings -- New commandline options: --emit-json and --emit-json-stdout to generate JSON documentation **(PDOC-84)** -- Runtime dependency on Puppet has been removed, allowing strings to function in Puppet Enterprise 3.8 **(PDOC-80)** - - Note that the gem still requires puppet. We recommend that the strings gem be installed with puppet, as suggested in the [README](https://github.com/puppetlabs/puppet-strings/blob/main/README.md#installing-puppet-strings) -- New gemspec requirement on Ruby version 1.9.3, the oldest supported Ruby version - -### BugFixes - -- Prevents a blizzard of errors when documenting Puppet Core source and some puppet modules **(PDOC-63)** - - As this is a complete rewrite, many known and unknown bugs from the original code were fixed along the way -- Allow strings to be installed in PE 3.8 without overwriting existing puppet and facter installations with newer gems - -## 2016-03-30 - Release 0.4.0 - -### Summary - -This release adds JSON output support for strings, fixes a major bug that prevented strings from working with the 4.4.0 release of puppet, and is the last version of strings that will be released as a module. - -All related tickets can be found under the [PDOC][PDOC JIRA] JIRA project with the fix version of [0.4.0](https://tickets.puppetlabs.com/issues/?filter=18810). - -### Features -- Support for JSON output **(PDOC-23)** - - Strings now has the ability to produce a JSON representation of a given puppet module - - The details of the JSON schema can be found [here](https://github.com/puppetlabs/puppet-strings/blob/main/json_dom.md) - - For details on how to generate JSON, see the [README](https://github.com/puppetlabs/puppet-strings/blob/main/README.md#running-puppet-strings) -- Migrate to ruby gems as a distribution method **(PDOC-28)** - - This is the last release of strings that will be available as a puppet module - - The 0.4.0 release will be released concurrently as a ruby gem - - After this release, all updates will only be available via the gem - -### Bugfixes - -- Fix issue that prevented strings from running with Puppet 4.4.0 **(PDOC-75)** - -## 2015-09-22 - Release 0.3.1 - -### Summary - -This is a minor bug fix release. - -All related tickets can be found under the [PDOC][PDOC JIRA] JIRA project with the fix version of [0.3.1](https://tickets.puppetlabs.com/issues/?filter=15530). - -### Bugfixes - -- Prevent strings from printing unnecessary quotes in error messages **(PDOC-57)** -- Issue correct type check warnings for defined types **(PDOC-56)** -- Allow providers, types, and defines to have the same name **(PDOC-54)** - -## 2015-09-21 - Release 0.3.0 - -### Summary - -This release includes support for Puppet Types and Providers, as well as -type checking Puppet 4x functions and defined types. - -All related tickets can be found under the [PDOC][PDOC JIRA] JIRA project with -the fix version of [0.3.0](https://tickets.puppetlabs.com/issues/?filter=15529). - -#### Features - -- Support for Puppet Types and Providers **(PDOC-35)** -- Type check Puppet 4x functions and defined types where possible and warn the user when types don't match. - - Type check defined types **(PDOC-21)** - - Type check Puppet 4x functions **(PDOC-38)** **(PDOC-19)** **(PDOC-37)** - - Output type info in generated HTML **(PDOC-19)** -- Improved warnings and logging. - - Create a consistent style for warnings. **(PDOC-49)** - - All warnings get printed on stderr. - - Yard warnings are redirected to a log file **(PDOC-38)** - - Prevent duplicate warnings **(PDOC-38)** -- Improved README installation and usage instructions. - - Installation instructions using Puppet **(PDOC-33)** - - -#### Bugfixes - -- Fix markdown list processing **(PDOC-30)** -- Fix namespacing for nested classes and defined types **(PDOC-20)** - - -## 2015-03-17 - Release 0.2.0 - -### Summary - -This release includes improvements to the HTML output generated by strings and a few bug fixes. -All related tickets can be found under the [PDOC][PDOC JIRA] JIRA project with the fix version of [0.2.0](https://tickets.puppetlabs.com/issues/?filter=13760). - -[PDOC JIRA]: https://tickets.puppetlabs.com/browse/PDOC - -#### Features -- Custom YARD templates for classes and defined types **(PDOC-17)** - - Improved HMTL output that is more appropriate for Puppet code (especially for parameters) - - Support for the explicit list of YARD tags we will be supporting initially (@param, @return, @since, @example) - - Our own custom YARD templates which can be easily extended and tweaked - -- Custom YARD templates for 3.x and 4.x functions **(PDOC-24)** - - Improved HMTL output that is more appropriate for listing several functions on one webpage in addition to being more consistent with the HTML produced for classes and defined types. - - Support for the explicit list of YARD tags we will be supporting initially (@param, @return, @since, @example) - - Our own custom YARD templates which can be easily extended and tweaked -- Addition of RubCop Travis CI job to ensure code quality and consistency **(PDOC-8)** - -#### Bugfixes -- Puppet namespaces are no longer mangled for nested classes and defined types **(PDOC-25)** -- Strings is now compatible with the renaming of the Puppetx/puppetx namespace to PuppetX/puppet_x **(PDOC-26)** -- Strings will no longer crash when documenting 3x functions with less than two arguments passed into newfunction **(PDOC-27)** diff --git a/Rakefile b/Rakefile index aa00696ee..9a7c6f9c8 100644 --- a/Rakefile +++ b/Rakefile @@ -15,7 +15,12 @@ RSpec::Core::RakeTask.new(:spec) do |t| t.exclude_pattern = "spec/acceptance/**/*.rb" end +RSpec::Core::RakeTask.new(:acceptance) do |t| + t.pattern = "spec/unit/**/*.rb" +end + task :spec => :spec_clean +task :acceptance => :spec_prep # Add our own tasks require 'puppet-strings/tasks' @@ -32,138 +37,3 @@ task :validate do sh "erb -P -x -T '-' #{template} | ruby -c" end end - -namespace :litmus do - def install_remote_gem(gem_name, target_nodes, inventory_hash) - # TODO: Currently this is Linux only - install_command = "/opt/puppetlabs/puppet/bin/gem install #{gem_name}" - result = run_command(install_command, target_nodes, config: nil, inventory: inventory_hash) - if result.is_a?(Array) - result.each do |node| - puts "#{node['target']} failed: '#{node['value']}'" if node['status'] != 'success' - end - else - raise "Failed trying to run '#{install_command}' against inventory." - end - end - - def install_build_tools(target_nodes, inventory_hash) - puts 'Installing build tools...' - install_build_command = "yum -y group install 'Development Tools'" - result = run_command(install_build_command, target_nodes, config: nil, inventory: inventory_hash) - if result.is_a?(Array) - result.each do |node| - puts "#{node['target']} failed: '#{node['value']}'" if node['status'] != 'success' - end - else - raise "Failed trying to run '#{install_build_command}' against inventory." - end - end - - # Install the gem under test and required fixture on a collection of nodes - # - # @param :target_node_name [Array] nodes on which to install a puppet module for testing. - desc 'install_gems - build and install module fixtures' - task :install_gems, [:target_node_name] do |_task, args| - inventory_hash = inventory_hash_from_inventory_file - target_nodes = find_targets(inventory_hash, args[:target_node_name]) - if target_nodes.empty? - puts 'No targets found' - exit 0 - end - require 'bolt_spec/run' - include BoltSpec::Run - - # Build the gem - puts 'Building gem...' - `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? - - # 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? - 'all' - else - args[:target_node_name] - end - puts 'Copying gem to targets...' - upload_file(gem_tar, File.basename(gem_tar), target_string, inventory: inventory_hash) - - install_build_tools(target_nodes, inventory_hash) - - # Install dependent gems - puts 'Installing yard gem...' - install_remote_gem('yard', target_nodes, inventory_hash) - puts 'Installing rgen gem...' - install_remote_gem('rgen', target_nodes, inventory_hash) - # Install puppet-strings - puts 'Installing puppet-strings gem...' - install_remote_gem(File.basename(gem_tar), target_nodes, inventory_hash) - puts 'Installed' - end -end - -#### CHANGELOG #### -begin - require 'github_changelog_generator/task' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - require 'puppet-strings/version' - config.future_release = "v#{PuppetStrings::VERSION}" - config.header = "# Changelog\n\n" \ - "All significant changes to this repo will be summarized in this file.\n" - config.configure_sections = { - added: { - prefix: "Added", - labels: ["enhancement"] - }, - fixed: { - prefix: "Fixed", - labels: ["bugfix"] - }, - breaking: { - prefix: "Changed", - labels: ["backwards-incompatible"] - } - } - config.exclude_labels = ['maintenance','incomplete'] - config.user = 'puppetlabs' - config.project = 'puppet-strings' - end -rescue LoadError - desc 'Install github_changelog_generator to get access to automatic changelog generation' - task :changelog do - raise 'Install github_changelog_generator to get access to automatic changelog generation' - end -end - -desc 'Run acceptance tests' -task :acceptance do - - begin - if ENV['MATRIX_TARGET'] - agent_version = ENV['MATRIX_TARGET'].chomp - else - agent_version = 'puppet7' - end - - Rake::Task['litmus:provision'].invoke('docker', 'litmusimage/centos:7') - - Rake::Task['litmus:install_agent'].invoke(agent_version.to_s) - - Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/acceptance/modules') - - Rake::Task['litmus:install_gems'].invoke - - Rake::Task['litmus:acceptance:parallel'].invoke - - rescue StandardError => e - puts e.message - raise e - end - -end diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index fd43b7159..000000000 --- a/codecov.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -# disable comments, info can be gotten from the pr status updates, and the comment editing spams the hipchat notifications -comment: false diff --git a/lib/puppet-strings.rb b/lib/puppet-strings.rb index db65123e4..614a3bc1a 100644 --- a/lib/puppet-strings.rb +++ b/lib/puppet-strings.rb @@ -1,5 +1,3 @@ -# rubocop:disable Naming/FileName - # frozen_string_literal: true # The root module for Puppet Strings. @@ -50,16 +48,13 @@ def self.generate(search_patterns = DEFAULT_SEARCH_PATTERNS, options = {}) YARD::CLI::Yardoc.run(*args) # If outputting JSON, render the output - if options[:json] && !options[:describe] - render_json(file) - end + render_json(file) if options[:json] && !options[:describe] # If outputting Markdown, render the output - if options[:markdown] - render_markdown(file) - end + render_markdown(file) if options[:markdown] return unless options[:describe] + render_describe(options[:describe_types], options[:describe_list], options[:providers]) end diff --git a/lib/puppet-strings/describe.rb b/lib/puppet-strings/describe.rb index 2583008d5..f63b72792 100644 --- a/lib/puppet-strings/describe.rb +++ b/lib/puppet-strings/describe.rb @@ -13,7 +13,7 @@ module PuppetStrings::Describe def self.render(describe_types = [], list = false, _providers = false) document = { defined_types: YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash), - resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash), + resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash) } if list @@ -32,7 +32,7 @@ def self.render(describe_types = [], list = false, _providers = false) end def self.show_one_type(resource_type) - puts "\n%{name}\n%{underscore}" % { name: resource_type[:name], underscore: '=' * resource_type[:name].length } + puts format("\n%s\n%s", name: resource_type[:name], underscore: '=' * resource_type[:name].length) puts resource_type[:docstring][:text] combined_list = (resource_type[:parameters].nil? ? [] : resource_type[:parameters]) + @@ -47,10 +47,10 @@ def self.show_one_type(resource_type) end def self.show_one_parameter(parameter) - puts "\n- **%{name}**\n" % { name: parameter[:name] } + puts format("\n- **%s**\n", name: parameter[:name]) puts parameter[:description] - puts 'Valid values are `%{values}`.' % { values: parameter[:values].join('`, `') } unless parameter[:values].nil? - puts 'Requires features %{required_features}.' % { required_features: parameter[:required_features] } unless parameter[:required_features].nil? + puts format('Valid values are `%s`.', values: parameter[:values].join('`, `')) unless parameter[:values].nil? + puts format('Requires features %s.', required_features: parameter[:required_features]) unless parameter[:required_features].nil? end def self.list_one_type(type) @@ -58,12 +58,8 @@ def self.list_one_type(type) shortento = targetlength - 4 contentstring = type[:docstring][:text] end_of_line = contentstring.index("\n") # "." gives closer results to old describeb, but breaks for '.k5login' - unless end_of_line.nil? - contentstring = contentstring[0..end_of_line] - end - if contentstring.length > targetlength - contentstring = contentstring[0..shortento] + ' ...' - end + contentstring = contentstring[0..end_of_line] unless end_of_line.nil? + contentstring = "#{contentstring[0..shortento]} ..." if contentstring.length > targetlength puts "#{type[:name].to_s.ljust(15)} - #{contentstring}" end diff --git a/lib/puppet-strings/markdown.rb b/lib/puppet-strings/markdown.rb index 3ef2e9d89..401227965 100644 --- a/lib/puppet-strings/markdown.rb +++ b/lib/puppet-strings/markdown.rb @@ -23,7 +23,7 @@ def self.groups PuppetStrings::Markdown::Function, PuppetStrings::Markdown::DataType, PuppetStrings::Markdown::PuppetTask, - PuppetStrings::Markdown::PuppetPlan, + PuppetStrings::Markdown::PuppetPlan ] end @@ -33,14 +33,14 @@ def self.generate output = [ "# Reference\n\n", "\n\n", - "## Table of Contents\n\n", + "## Table of Contents\n\n" ] # Create table of contents template = erb(File.join(__dir__, 'markdown', 'templates', 'table_of_contents.erb')) groups.each do |group| group_name = group.group_name - items = group.items.map { |item| item.toc_info } + items = group.items.map(&:toc_info) has_private = items.any? { |item| item[:private] } has_public = items.any? { |item| !item[:private] } @@ -49,14 +49,14 @@ def self.generate # Create actual contents groups.each do |group| - items = group.items.reject { |item| item.private? } + items = group.items.reject(&:private?) unless items.empty? output << "## #{group.group_name}\n\n" - output.append(items.map { |item| item.render }) + output.append(items.map(&:render)) end end - output.join('') + output.join end # mimicks the behavior of the json render, although path will never be nil @@ -66,7 +66,7 @@ def self.render(path = nil) puts generate exit else - File.open(path, 'w') { |file| file.write(generate) } + File.write(path, generate) YARD::Logger.instance.debug "Wrote markdown to #{path}" end end @@ -76,11 +76,9 @@ def self.render(path = nil) # @param [String] path The full path to the template file. # @return [ERB] Template def self.erb(path) - if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0') - ERB.new(File.read(path), trim_mode: '-') - else + unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0') # This outputs warnings in Ruby 2.6+. - ERB.new(File.read(path), nil, '-') end + ERB.new(File.read(path), trim_mode: '-') end end diff --git a/lib/puppet-strings/markdown/base.rb b/lib/puppet-strings/markdown/base.rb index 4f2e0eaff..5e5e49b14 100644 --- a/lib/puppet-strings/markdown/base.rb +++ b/lib/puppet-strings/markdown/base.rb @@ -161,7 +161,7 @@ def enums # @return [Array] option tag hashes that have a parent parameter_name def options_for_param(parameter_name) opts_for_p = options.select { |o| o[:parent] == parameter_name } unless options.nil? - opts_for_p unless opts_for_p.nil? || opts_for_p.length.zero? + opts_for_p unless opts_for_p.nil? || opts_for_p.empty? end # @param parameter_name @@ -169,7 +169,7 @@ def options_for_param(parameter_name) # @return [Array] enum tag hashes that have a parent parameter_name def enums_for_param(parameter_name) enums_for_p = enums.select { |e| e[:parent] == parameter_name } unless enums.nil? - enums_for_p unless enums_for_p.nil? || enums_for_p.length.zero? + enums_for_p unless enums_for_p.nil? || enums_for_p.empty? end # @return [Hash] any defaults found for the component @@ -200,7 +200,7 @@ def word_wrap(text, line_width: 120, break_sequence: "\n") return unless text text.split("\n").map! { |line| - line.length > line_width ? line.gsub(%r{(.{1,#{line_width}})(\s+|$)}, "\\1#{break_sequence}").strip : line + line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").strip : line } * break_sequence end diff --git a/lib/puppet-strings/markdown/data_type.rb b/lib/puppet-strings/markdown/data_type.rb index 3f2040ab1..a11239b65 100644 --- a/lib/puppet-strings/markdown/data_type.rb +++ b/lib/puppet-strings/markdown/data_type.rb @@ -5,17 +5,16 @@ module PuppetStrings::Markdown # This class encapsualtes ruby data types and puppet type aliases class DataType < Base - attr_reader :alias_of - attr_reader :functions + attr_reader :alias_of, :functions group_name 'Data types' - yard_types [:puppet_data_type, :puppet_data_type_alias] + yard_types %i[puppet_data_type puppet_data_type_alias] def initialize(registry) @template = 'data_type.erb' super(registry, 'data type') @alias_of = registry[:alias_of] unless registry[:alias_of].nil? - @functions = @registry[:functions].nil? ? nil : @registry[:functions].map { |func| DataType::Function.new(func) } + @functions = @registry[:functions]&.map { |func| DataType::Function.new(func) } end def render diff --git a/lib/puppet-strings/markdown/function.rb b/lib/puppet-strings/markdown/function.rb index da7e215e5..901acd1ec 100644 --- a/lib/puppet-strings/markdown/function.rb +++ b/lib/puppet-strings/markdown/function.rb @@ -25,11 +25,11 @@ def render def type t = @registry[:type] - if %r{ruby4x}.match?(t) + if t.include?('ruby4x') 'Ruby 4.x API' - elsif %r{ruby3}.match?(t) + elsif t.include?('ruby3') 'Ruby 3.x API' - elsif %r{ruby}.match?(t) + elsif t.include?('ruby') 'Ruby' else 'Puppet Language' @@ -37,11 +37,11 @@ def type end def error_type(type) - "`#{type.split(' ')[0]}`" + "`#{type.split[0]}`" end def error_text(text) - text.split(' ').drop(1).join(' ').to_s + text.split.drop(1).join(' ').to_s end end diff --git a/lib/puppet-strings/markdown/resource_type.rb b/lib/puppet-strings/markdown/resource_type.rb index f2b9e31aa..a25ff7e03 100644 --- a/lib/puppet-strings/markdown/resource_type.rb +++ b/lib/puppet-strings/markdown/resource_type.rb @@ -50,7 +50,7 @@ def parameters def regex_in_data_type?(data_type) m = data_type.match(%r{\w+\[/.*/\]}) - m unless m.nil? || m.length.zero? + m unless m.nil? || m.to_a.empty? end end end diff --git a/lib/puppet-strings/tasks.rb b/lib/puppet-strings/tasks.rb index 08cadf4a3..fa09d8e28 100644 --- a/lib/puppet-strings/tasks.rb +++ b/lib/puppet-strings/tasks.rb @@ -8,7 +8,7 @@ module PuppetStrings end # The module for Puppet Strings rake tasks. module PuppetStrings::Tasks - require 'puppet-strings/tasks/generate.rb' - require 'puppet-strings/tasks/gh_pages.rb' - require 'puppet-strings/tasks/validate.rb' + require 'puppet-strings/tasks/generate' + require 'puppet-strings/tasks/gh_pages' + require 'puppet-strings/tasks/validate' end diff --git a/lib/puppet-strings/tasks/generate.rb b/lib/puppet-strings/tasks/generate.rb index 57b8d9934..777ecbb6f 100644 --- a/lib/puppet-strings/tasks/generate.rb +++ b/lib/puppet-strings/tasks/generate.rb @@ -13,7 +13,7 @@ options = { debug: args[:debug] == 'true', backtrace: args[:backtrace] == 'true', - markup: args[:markup] || 'markdown', + markup: args[:markup] || 'markdown' } raise('Error: Both JSON and Markdown output have been selected. Please select one.') if args[:json] == 'true' && args[:markdown] == 'true' @@ -29,13 +29,15 @@ # @return nil def parse_format_option(args, options, format) return unless args.has_key? format - options[format] = args[format] == 'false' || args[format].empty? ? false : true + + options[format] = !(args[format] == 'false' || args[format].empty?) return unless options[format] + options[:path] = args[format] == 'true' ? nil : args[format] end # rubocop:enable Style/PreferredHashMethods - [:json, :markdown].each { |format| parse_format_option(args, options, format) } + %i[json markdown].each { |format| parse_format_option(args, options, format) } warn('yard_args behavior is a little dodgy, use at your own risk') if args[:yard_args] options[:yard_args] = args[:yard_args].split if args.key? :yard_args diff --git a/lib/puppet-strings/tasks/gh_pages.rb b/lib/puppet-strings/tasks/gh_pages.rb index 576d5da4f..f921f2902 100644 --- a/lib/puppet-strings/tasks/gh_pages.rb +++ b/lib/puppet-strings/tasks/gh_pages.rb @@ -30,7 +30,7 @@ task :configure do unless File.exist?(File.join('doc', '_config.yml')) Dir.chdir('doc') do - File.open('_config.yml', 'w+') { |f| f.write('include: _index.html') } + File.write('_config.yml', 'include: _index.html') end end end @@ -48,11 +48,11 @@ end desc 'Update docs on the gh-pages branch and push to GitHub.' - task update: [ - :checkout, - :'strings:generate', - :configure, - :push, + task update: %i[ + checkout + strings:generate + configure + push ] end end diff --git a/lib/puppet-strings/tasks/validate.rb b/lib/puppet-strings/tasks/validate.rb index 7b475061f..21251d8ce 100644 --- a/lib/puppet-strings/tasks/validate.rb +++ b/lib/puppet-strings/tasks/validate.rb @@ -10,7 +10,7 @@ filename = 'REFERENCE.md' unless File.exist?(filename) - STDERR.puts "#{filename} does not exist" + warn "#{filename} does not exist" exit 1 end @@ -24,7 +24,7 @@ backtrace: args[:backtrace] == 'true', json: false, markdown: true, - path: file, + path: file } PuppetStrings.generate(patterns, options) @@ -34,7 +34,7 @@ existing = File.read(filename) if generated != existing - STDERR.puts "#{filename} is outdated" + warn "#{filename} is outdated" exit 1 end end diff --git a/lib/puppet-strings/yard.rb b/lib/puppet-strings/yard.rb index fe9912980..2f9f256cd 100644 --- a/lib/puppet-strings/yard.rb +++ b/lib/puppet-strings/yard.rb @@ -61,7 +61,7 @@ def all_objects :puppet_provider, :puppet_function, :puppet_task, - :puppet_plan, + :puppet_plan ) end end diff --git a/lib/puppet-strings/yard/code_objects/base.rb b/lib/puppet-strings/yard/code_objects/base.rb index c6e23cec7..2f6c19db7 100644 --- a/lib/puppet-strings/yard/code_objects/base.rb +++ b/lib/puppet-strings/yard/code_objects/base.rb @@ -7,9 +7,9 @@ class PuppetStrings::Yard::CodeObjects::Base < YARD::CodeObjects::NamespaceObjec # @return Returns the code object. def self.new(*args) # Skip the super class' implementation because it detects :: in names and this will cause namespaces in the output we don't want - object = Object.class.instance_method(:new).bind(self).call(*args) + object = Object.class.instance_method(:new).bind_call(self, *args) existing = YARD::Registry.at(object.path) - object = existing if existing && existing.class == self + object = existing if existing.instance_of?(self) yield(object) if block_given? object end diff --git a/lib/puppet-strings/yard/code_objects/class.rb b/lib/puppet-strings/yard/code_objects/class.rb index 5346d6bd5..692e8db95 100644 --- a/lib/puppet-strings/yard/code_objects/class.rb +++ b/lib/puppet-strings/yard/code_objects/class.rb @@ -20,8 +20,7 @@ def name(_prefix = false) # Implements the Puppet class code object. class PuppetStrings::Yard::CodeObjects::Class < PuppetStrings::Yard::CodeObjects::Base - attr_reader :statement - attr_reader :parameters + attr_reader :statement, :parameters # Initializes a Puppet class code object. # @param [PuppetStrings::Parsers::ClassStatement] statement The class statement that was parsed. diff --git a/lib/puppet-strings/yard/code_objects/data_type.rb b/lib/puppet-strings/yard/code_objects/data_type.rb index 39f343f3a..2c3b85793 100644 --- a/lib/puppet-strings/yard/code_objects/data_type.rb +++ b/lib/puppet-strings/yard/code_objects/data_type.rb @@ -87,14 +87,14 @@ def to_hash hash[:name] = name hash[:file] = file hash[:line] = line - hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, [:param, :option, :enum, :return, :example]) + hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) 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, signature: func.signature, - docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, [:param, :option, :enum, :return, :example]) + docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, %i[param option enum return example]) } end hash diff --git a/lib/puppet-strings/yard/code_objects/defined_type.rb b/lib/puppet-strings/yard/code_objects/defined_type.rb index 2e5cb1c01..00c067ce7 100644 --- a/lib/puppet-strings/yard/code_objects/defined_type.rb +++ b/lib/puppet-strings/yard/code_objects/defined_type.rb @@ -20,8 +20,7 @@ def name(_prefix = false) # Implements the Puppet defined type code object. class PuppetStrings::Yard::CodeObjects::DefinedType < PuppetStrings::Yard::CodeObjects::Base - attr_reader :statement - attr_reader :parameters + attr_reader :statement, :parameters # Initializes a Puppet defined type code object. # @param [PuppetStrings::Parsers::DefinedTypeStatement] statement The defined type statement that was parsed. diff --git a/lib/puppet-strings/yard/code_objects/function.rb b/lib/puppet-strings/yard/code_objects/function.rb index 59a79380d..e2f9007ec 100644 --- a/lib/puppet-strings/yard/code_objects/function.rb +++ b/lib/puppet-strings/yard/code_objects/function.rb @@ -65,16 +65,16 @@ def signature return '' if has_tag? :overload tags = self.tags(:param) - args = @parameters.map { |parameter| + args = @parameters.map do |parameter| name, default = parameter tag = tags.find { |t| t.name == name } if tags type = tag&.types ? "#{tag.type} " : 'Any ' prefix = (name[0]).to_s if name.start_with?('*', '&') - name = name[1..-1] if prefix + name = name[1..] if prefix default = " = #{default}" if default "#{type}#{prefix}$#{name}#{default}" - }.join(', ') - @name.to_s + '(' + args + ')' + end.join(', ') + "#{@name}(#{args})" end # Converts the code object to a hash representation. @@ -91,10 +91,10 @@ def to_hash if has_tag? :overload # loop over overloads and append onto the signatures array tags(:overload).each do |o| - hash[:signatures] << { signature: o.signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(o.docstring, [:param, :option, :enum, :return, :example]) } + 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, [:param, :option, :enum, :return, :example]) } + hash[:signatures] << { signature: 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/code_objects/plan.rb b/lib/puppet-strings/yard/code_objects/plan.rb index 6bec1fb3c..5cc01a866 100644 --- a/lib/puppet-strings/yard/code_objects/plan.rb +++ b/lib/puppet-strings/yard/code_objects/plan.rb @@ -20,8 +20,7 @@ def name(_prefix = false) # Implements the Puppet plan code object. class PuppetStrings::Yard::CodeObjects::Plan < PuppetStrings::Yard::CodeObjects::Base - attr_reader :statement - attr_reader :parameters + attr_reader :statement, :parameters # Initializes a Puppet plan code object. # @param [PuppetStrings::Parsers::PlanStatement] statement The plan statement that was parsed. diff --git a/lib/puppet-strings/yard/code_objects/type.rb b/lib/puppet-strings/yard/code_objects/type.rb index 1240fba87..fe6131fdd 100644 --- a/lib/puppet-strings/yard/code_objects/type.rb +++ b/lib/puppet-strings/yard/code_objects/type.rb @@ -158,7 +158,7 @@ def parameters provider_param = Parameter.new( 'provider', "The specific backend to use for this `#{name}` resource. You will seldom need " \ - 'to specify this --- Puppet will usually discover the appropriate provider for your platform.', + 'to specify this --- Puppet will usually discover the appropriate provider for your platform.' ) @parameters ||= [] @@ -185,11 +185,11 @@ def to_hash hash[:line] = line hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) - hash[:properties] = properties.sort_by { |p| p.name }.map(&:to_hash) if properties && !properties.empty? - hash[:parameters] = parameters.sort_by { |p| p.name }.map(&:to_hash) if parameters && !parameters.empty? - hash[:checks] = checks.sort_by { |c| c.name }.map(&:to_hash) if checks && !checks.empty? - hash[:features] = features.sort_by { |f| f.name }.map(&:to_hash) if features && !features.empty? - hash[:providers] = providers.sort_by { |p| p.name }.map(&:to_hash) if providers && !providers.empty? + hash[:properties] = properties.sort_by(&:name).map(&:to_hash) if properties && !properties.empty? + hash[:parameters] = parameters.sort_by(&:name).map(&:to_hash) if parameters && !parameters.empty? + hash[:checks] = checks.sort_by(&:name).map(&:to_hash) if checks && !checks.empty? + hash[:features] = features.sort_by(&:name).map(&:to_hash) if features && !features.empty? + hash[:providers] = providers.sort_by(&:name).map(&:to_hash) if providers && !providers.empty? hash end diff --git a/lib/puppet-strings/yard/handlers/helpers.rb b/lib/puppet-strings/yard/handlers/helpers.rb index 358282602..61070fd48 100644 --- a/lib/puppet-strings/yard/handlers/helpers.rb +++ b/lib/puppet-strings/yard/handlers/helpers.rb @@ -4,6 +4,7 @@ module PuppetStrings::Yard::Handlers::Helpers def self.validate_summary_tag(object) return unless object.has_tag?(:summary) && object.tag(:summary).text.length > 140 + log.warn "The length of the summary for #{object.type} '#{object.name}' exceeds the recommended limit of 140 characters." end end diff --git a/lib/puppet-strings/yard/handlers/json/task_handler.rb b/lib/puppet-strings/yard/handlers/json/task_handler.rb index 6ce505f79..19652fdcb 100644 --- a/lib/puppet-strings/yard/handlers/json/task_handler.rb +++ b/lib/puppet-strings/yard/handlers/json/task_handler.rb @@ -26,6 +26,7 @@ def validate_description def validate_params return if @statement.parameters.empty? + @statement.parameters.each do |param, val| log.warn "Missing description for param '#{param}' in #{@kind}" if val['description'].nil? end diff --git a/lib/puppet-strings/yard/handlers/puppet/base.rb b/lib/puppet-strings/yard/handlers/puppet/base.rb index bbc713149..ffa0b0cc7 100644 --- a/lib/puppet-strings/yard/handlers/puppet/base.rb +++ b/lib/puppet-strings/yard/handlers/puppet/base.rb @@ -37,9 +37,9 @@ def set_parameter_types(object) # Warn if the parameter type and tag types don't match if parameter.type && tag.types && !tag.types.empty? && parameter.type != tag.types[0] - log.warn "The type of the @param tag for parameter '#{parameter.name}' "\ - "does not match the parameter type specification near #{statement.file}:#{statement.line}: "\ - 'ignoring in favor of parameter type information.' + log.warn "The type of the @param tag for parameter '#{parameter.name}' " \ + "does not match the parameter type specification near #{statement.file}:#{statement.line}: " \ + 'ignoring in favor of parameter type information.' end if parameter.type diff --git a/lib/puppet-strings/yard/handlers/ruby/base.rb b/lib/puppet-strings/yard/handlers/ruby/base.rb index 7b263b524..81c3c9bfa 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 = %r{^ actual_function[:param_types].count - log.warn "The @param tag for '#{tag.name}' should not exist for function "\ - "'#{meth.name}' that is defined near #{object.file}:#{object.line}. "\ - "Expected only #{actual_function[:param_types].count} parameter/s" + log.warn "The @param tag for '#{tag.name}' should not exist for function " \ + "'#{meth.name}' that is defined near #{object.file}:#{object.line}. " \ + "Expected only #{actual_function[:param_types].count} parameter/s" true else false diff --git a/lib/puppet-strings/yard/handlers/ruby/function_handler.rb b/lib/puppet-strings/yard/handlers/ruby/function_handler.rb index dbf067d56..f23c19c95 100644 --- a/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/function_handler.rb @@ -8,17 +8,17 @@ # Implements the handler for Puppet functions written in Ruby. class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard::Handlers::Ruby::Base # Represents the list of Puppet 4.x function API methods to support. - DISPATCH_METHOD_NAMES = [ - 'param', - 'required_param', - 'optional_param', - 'repeated_param', - 'optional_repeated_param', - 'required_repeated_param', - 'block_param', - 'required_block_param', - 'optional_block_param', - 'return_type', + DISPATCH_METHOD_NAMES = %w[ + param + required_param + optional_param + repeated_param + optional_repeated_param + required_repeated_param + block_param + required_block_param + optional_block_param + return_type ].freeze namespace_only @@ -39,7 +39,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard is_3x = ['Puppet::Parser::Functions', 'newfunction'].include?(module_name) object = PuppetStrings::Yard::CodeObjects::Function.new( get_name(statement, 'Puppet::Functions.create_function'), - is_3x ? PuppetStrings::Yard::CodeObjects::Function::RUBY_3X : PuppetStrings::Yard::CodeObjects::Function::RUBY_4X, + is_3x ? PuppetStrings::Yard::CodeObjects::Function::RUBY_3X : PuppetStrings::Yard::CodeObjects::Function::RUBY_4X ) object.source = statement register object @@ -76,21 +76,21 @@ def add_tags(object) log.warn "Missing documentation for Puppet function '#{object.name}' at #{statement.file}:#{statement.line}." if object.docstring.empty? && object.tags.empty? unless object.tags(:param).empty? - log.warn "The docstring for Puppet 4.x function '#{object.name}' "\ - "contains @param tags near #{object.file}:#{object.line}: parameter "\ - 'documentation should be made on the dispatch call.' + log.warn "The docstring for Puppet 4.x function '#{object.name}' " \ + "contains @param tags near #{object.file}:#{object.line}: parameter " \ + 'documentation should be made on the dispatch call.' end unless object.tags(:return).empty? - log.warn "The docstring for Puppet 4.x function '#{object.name}' "\ - "contains @return tags near #{object.file}:#{object.line}: return "\ - 'value documentation should be made on the dispatch call.' + log.warn "The docstring for Puppet 4.x function '#{object.name}' " \ + "contains @return tags near #{object.file}:#{object.line}: return " \ + 'value documentation should be made on the dispatch call.' end unless object.tags(:overload).empty? - log.warn "The docstring for Puppet 4.x function '#{object.name}' "\ - "contains @overload tags near #{object.file}:#{object.line}: overload "\ - 'tags are automatically generated from the dispatch calls.' + log.warn "The docstring for Puppet 4.x function '#{object.name}' " \ + "contains @overload tags near #{object.file}:#{object.line}: overload " \ + 'tags are automatically generated from the dispatch calls.' end # Delete any existing param/return/overload tags @@ -123,6 +123,7 @@ def add_tags(object) # If there's only one overload, move the tags to the object itself return unless overloads.length == 1 + overload = overloads.first object.parameters = overload.parameters object.add_tag(*overload.tags) @@ -184,7 +185,7 @@ def add_overload_tag(object, node) node_as_string(parameters[0]), nil, # TODO: determine default from corresponding Ruby method signature? method_name.include?('optional'), - method_name.include?('repeated'), + method_name.include?('repeated') ) end @@ -215,7 +216,7 @@ def add_overload_tag(object, node) nil, # TODO: determine default from corresponding Ruby method signature? block.method_name.source.include?('optional'), false, # Not repeated - true, # Is block + true # Is block ) end end @@ -243,7 +244,7 @@ def add_method_overload(object, node) param_tags, parameter.source, parameter.file, - parameter.line, + parameter.line ) end @@ -258,7 +259,7 @@ def add_method_overload(object, node) parameter.line, nil, parameter[1].source, - true, + true ) end @@ -274,7 +275,7 @@ def add_method_overload(object, node) nil, nil, false, - true, + true ) end @@ -291,7 +292,7 @@ def add_method_overload(object, node) nil, false, false, - true, + true ) end @@ -309,15 +310,15 @@ def add_param_tag(object, tags, name, file, line, type = nil, default = nil, opt log.warn "Missing @param tag for parameter '#{name}' near #{file}:#{line}." unless tag || object.docstring.all.empty? if type && tag && tag.types && !tag.types.empty? - log.warn "The @param tag for parameter '#{name}' should not contain a "\ - "type specification near #{file}:#{line}: ignoring in favor of "\ - 'dispatch type information.' + log.warn "The @param tag for parameter '#{name}' should not contain a " \ + "type specification near #{file}:#{line}: ignoring in favor of " \ + 'dispatch type information.' end if repeated - name = '*' + name + name = "*#{name}" elsif block - name = '&' + name + name = "&#{name}" end type ||= tag&.types ? tag.type : 'Any' diff --git a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb index 1a199a347..8f16f9919 100644 --- a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb @@ -94,7 +94,7 @@ def populate_provider_data(object) object.add_confine(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source) end - elsif ['has_feature', 'has_features'].include?(method_name) + elsif %w[has_feature has_features].include?(method_name) # Add the features to the object parameters.each do |parameter| object.add_feature(node_as_string(parameter) || parameter.source) diff --git a/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb b/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb index c9c36f526..f18decfa5 100644 --- a/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb @@ -53,9 +53,9 @@ def raise_parse_error(msg, location = statement) # check that the params of the register_type call are key/value pairs. def kv_arg_list?(params) params.type == :list && - params.children.count > 0 && + params.children.count.positive? && params.children.first.type == :list && - params.children.first.children.count > 0 && + params.children.first.children.count.positive? && statement.parameters.children.first.children.first.type == :assoc end @@ -101,7 +101,7 @@ def hash_from_node(node) kv_pairs = node.children.map do |assoc| [value_from_node(assoc.children[0]), value_from_node(assoc.children[1])] end - Hash[kv_pairs] + kv_pairs.to_h end def var_ref_from_node(node) @@ -129,7 +129,7 @@ def populate_type_data(object, schema) schema['attributes'].each do |name, definition| # puts "Processing #{name}: #{definition.inspect}" - if ['parameter', 'namevar'].include? definition['behaviour'] + if %w[parameter namevar].include? definition['behaviour'] object.add_parameter(create_parameter(name, definition)) else object.add_property(create_property(name, definition)) diff --git a/lib/puppet-strings/yard/handlers/ruby/type_base.rb b/lib/puppet-strings/yard/handlers/ruby/type_base.rb index ea681f88e..9e1fba879 100644 --- a/lib/puppet-strings/yard/handlers/ruby/type_base.rb +++ b/lib/puppet-strings/yard/handlers/ruby/type_base.rb @@ -110,15 +110,18 @@ def set_values(node, object) return unless object.is_a? PuppetStrings::Yard::CodeObjects::Type::Parameter # Process the options for parameter base types return unless parameters.count >= 2 + 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' + # rubocop:disable Performance/InefficientHashSearch object.add('true') unless object.values.include? 'true' object.add('false') unless object.values.include? 'false' object.add('yes') unless object.values.include? 'yes' object.add('no') unless object.values.include? 'no' + # rubocop:enable Performance/InefficientHashSearch end break end diff --git a/lib/puppet-strings/yard/handlers/ruby/type_handler.rb b/lib/puppet-strings/yard/handlers/ruby/type_handler.rb index a5eeba5c1..7b84c45b3 100644 --- a/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/type_handler.rb @@ -52,7 +52,8 @@ def populate_type_data(object) method_name = node.method_name.source parameters = node.parameters(false) - if method_name == 'newproperty' + case method_name + when 'newproperty' # Add a property to the object next unless parameters.count >= 1 @@ -60,7 +61,7 @@ def populate_type_data(object) next unless name object.add_property(create_property(name, node)) - elsif method_name == 'newparam' + when 'newparam' # Add a parameter to the object next unless parameters.count >= 1 @@ -68,7 +69,7 @@ def populate_type_data(object) next unless name object.add_parameter(create_parameter(name, node)) - elsif method_name == 'newcheck' + when 'newcheck' # Add a check to the object next unless parameters.count >= 1 @@ -76,7 +77,7 @@ def populate_type_data(object) next unless name object.add_check(create_check(name, node)) - elsif method_name == 'feature' + when 'feature' # Add a feature to the object next unless parameters.count >= 2 @@ -87,7 +88,7 @@ def populate_type_data(object) next unless docstring object.add_feature(PuppetStrings::Yard::CodeObjects::Type::Feature.new(name, docstring)) - elsif method_name == 'ensurable' + when 'ensurable' if node.block property = create_property('ensure', node) property.docstring = DEFAULT_ENSURABLE_DOCSTRING if property.docstring.empty? diff --git a/lib/puppet-strings/yard/parsers/json/parser.rb b/lib/puppet-strings/yard/parsers/json/parser.rb index 3fcfcc534..d5b21e7f1 100644 --- a/lib/puppet-strings/yard/parsers/json/parser.rb +++ b/lib/puppet-strings/yard/parsers/json/parser.rb @@ -28,7 +28,7 @@ def parse # TODO: this should compare json to a Task metadata json-schema or perform some other hueristics # to determine what type of statement it represents @statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty? - rescue + rescue StandardError log.error "Failed to parse #{@file}: " @statements = [] end diff --git a/lib/puppet-strings/yard/parsers/puppet/parser.rb b/lib/puppet-strings/yard/parsers/puppet/parser.rb index a8c76b9e7..98f4e3029 100644 --- a/lib/puppet-strings/yard/parsers/puppet/parser.rb +++ b/lib/puppet-strings/yard/parsers/puppet/parser.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -# rubocop:disable Naming/MethodName - require 'puppet' require 'puppet/pops' require 'puppet-strings/yard/parsers/puppet/statement' @@ -24,10 +22,6 @@ def initialize(source, filename) # rubocop:disable Lint/MissingSuper # @return [void] def parse begin - if @file.to_s.match?(%r{^plans|/plans/}) && Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') < 0 - log.warn "Skipping #{@file}: Puppet Plans require Puppet 5 or greater." - return - end Puppet[:tasks] = true if Puppet.settings.include?(:tasks) @statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact rescue ::Puppet::ParseError => e diff --git a/lib/puppet-strings/yard/parsers/puppet/statement.rb b/lib/puppet-strings/yard/parsers/puppet/statement.rb index a52479406..07102494d 100644 --- a/lib/puppet-strings/yard/parsers/puppet/statement.rb +++ b/lib/puppet-strings/yard/parsers/puppet/statement.rb @@ -7,13 +7,9 @@ module PuppetStrings::Yard::Parsers::Puppet # Represents the base Puppet language statement. class Statement # The pattern for parsing docstring comments. - COMMENT_REGEX = %r{^\s*#+\s?}.freeze + COMMENT_REGEX = /^\s*#+\s?/.freeze - attr_reader :source - attr_reader :file - attr_reader :line - attr_reader :docstring - attr_reader :comments_range + attr_reader :source, :file, :line, :docstring, :comments_range # Initializes the Puppet language statement. # @param object The Puppet parser model object for the statement. @@ -67,7 +63,7 @@ def comments_hash_flag private def first_line - @source.split(%r{\r?\n}).first.strip + @source.split(/\r?\n/).first.strip end end @@ -75,20 +71,17 @@ def first_line class ParameterizedStatement < Statement # Implements a parameter for a parameterized statement. class Parameter - attr_reader :name - attr_reader :type - attr_reader :value + attr_reader :name, :type, :value # Initializes the parameter. # @param [Puppet::Pops::Model::Parameter] parameter The parameter model object. def initialize(parameter) @name = parameter.name # Take the exact text for the type expression - if parameter.type_expr - @type = PuppetStrings::Yard::Util.ast_to_text(parameter.type_expr) - end + @type = PuppetStrings::Yard::Util.ast_to_text(parameter.type_expr) if parameter.type_expr # Take the exact text for the default value expression return unless parameter.value + @value = PuppetStrings::Yard::Util.ast_to_text(parameter.value) end end @@ -106,8 +99,7 @@ def initialize(object, file) # Implements the Puppet class statement. class ClassStatement < ParameterizedStatement - attr_reader :name - attr_reader :parent_class + attr_reader :name, :parent_class # Initializes the Puppet class statement. # @param [Puppet::Pops::Model::HostClassDefinition] object The model object for the class statement. @@ -134,8 +126,7 @@ def initialize(object, file) # Implements the Puppet function statement. class FunctionStatement < ParameterizedStatement - attr_reader :name - attr_reader :type + attr_reader :name, :type # Initializes the Puppet function statement. # @param [Puppet::Pops::Model::FunctionDefinition] object The model object for the function statement. @@ -144,8 +135,10 @@ def initialize(object, file) super(object, file) @name = object.name return unless object.respond_to? :return_type + type = object.return_type return unless type + @type = PuppetStrings::Yard::Util.ast_to_text(type).gsub('>> ', '') end end @@ -165,8 +158,7 @@ def initialize(object, file) # Implements the Puppet data type alias statement. class DataTypeAliasStatement < Statement - attr_reader :name - attr_reader :alias_of + attr_reader :name, :alias_of # Initializes the Puppet data type alias statement. # @param [Puppet::Pops::Model::TypeAlias] object The model object for the type statement. @@ -178,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 = +"#{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/tags/overload_tag.rb b/lib/puppet-strings/yard/tags/overload_tag.rb index e474dbc01..8ae294250 100644 --- a/lib/puppet-strings/yard/tags/overload_tag.rb +++ b/lib/puppet-strings/yard/tags/overload_tag.rb @@ -21,16 +21,16 @@ def initialize(name, docstring) # @return [String] Returns the signature of the overload. def signature tags = self.tags(:param) - args = @parameters.map { |parameter| + args = @parameters.map do |parameter| name, default = parameter tag = tags.find { |t| t.name == name } if tags type = tag&.types ? "#{tag.type} " : 'Any ' prefix = (name[0]).to_s if name.start_with?('*', '&') - name = name[1..-1] if prefix + name = name[1..] if prefix default = " = #{default}" if default "#{type}#{prefix}$#{name}#{default}" - }.join(', ') - @name + '(' + args + ')' + end.join(', ') + "#{@name}(#{args})" end # Adds a tag to the overload's docstring. diff --git a/lib/puppet-strings/yard/tags/parameter_directive.rb b/lib/puppet-strings/yard/tags/parameter_directive.rb index da9023192..ec8506db4 100644 --- a/lib/puppet-strings/yard/tags/parameter_directive.rb +++ b/lib/puppet-strings/yard/tags/parameter_directive.rb @@ -7,7 +7,7 @@ class PuppetStrings::Yard::Tags::ParameterDirective < YARD::Tags::Directive # Called to invoke the directive. # @return [void] def call - return unless 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) diff --git a/lib/puppet-strings/yard/tags/property_directive.rb b/lib/puppet-strings/yard/tags/property_directive.rb index 9cf25b43e..999e38832 100644 --- a/lib/puppet-strings/yard/tags/property_directive.rb +++ b/lib/puppet-strings/yard/tags/property_directive.rb @@ -7,7 +7,7 @@ class PuppetStrings::Yard::Tags::PropertyDirective < YARD::Tags::Directive # Called to invoke the directive. # @return [void] def call - return unless 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) diff --git a/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb b/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb index 4087e9d9c..611d9a311 100644 --- a/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Generates the searchable Puppet class list. # @return [void] def generate_puppet_class_list @@ -10,7 +12,7 @@ def generate_puppet_class_list # Generates the searchable Puppet data type list. # @return [void] def generate_puppet_data_type_list - @items = Registry.all(:puppet_data_type, :puppet_data_type_alias).sort_by {|dt| dt.name.to_s } + @items = Registry.all(:puppet_data_type, :puppet_data_type_alias).sort_by { |dt| dt.name.to_s } @list_title = 'Data Type List' @list_type = 'puppet_data_type' generate_list_contents @@ -19,7 +21,7 @@ def generate_puppet_data_type_list # Generates the searchable Puppet defined type list. # @return [void] def generate_puppet_defined_type_list - @items = Registry.all(:puppet_defined_type).sort_by {|dt| dt.name.to_s } + @items = Registry.all(:puppet_defined_type).sort_by { |dt| dt.name.to_s } @list_title = 'Defined Type List' @list_type = 'puppet_defined_type' generate_list_contents @@ -28,7 +30,7 @@ def generate_puppet_defined_type_list # Generates the searchable Puppet resource type list. # @return [void] def generate_puppet_type_list - @items = Registry.all(:puppet_type).sort_by {|t| t.name.to_s } + @items = Registry.all(:puppet_type).sort_by { |t| t.name.to_s } @list_title = 'Resource Type List' @list_type = 'puppet_type' generate_list_contents @@ -37,7 +39,7 @@ def generate_puppet_type_list # Generates the searchable Puppet provider list. # @return [void] def generate_puppet_provider_list - @items = Registry.all(:puppet_provider).sort_by {|p| p.name.to_s } + @items = Registry.all(:puppet_provider).sort_by { |p| p.name.to_s } @list_title = 'Provider List' @list_type = 'puppet_provider' generate_list_contents @@ -46,7 +48,7 @@ def generate_puppet_provider_list # Generates the searchable Puppet function list. # @return [void] def generate_puppet_function_list - @items = Registry.all(:puppet_function).sort_by {|f| f.name.to_s } + @items = Registry.all(:puppet_function).sort_by { |f| f.name.to_s } @list_title = 'Puppet Function List' @list_type = 'puppet_function' generate_list_contents @@ -56,8 +58,8 @@ def generate_puppet_function_list # @return [void] def generate_method_list @items = prune_method_listing(Registry.all(:method), false) - @items = @items.reject {|m| m.name.to_s =~ /=$/ && m.is_attribute? } - @items = @items.sort_by {|m| m.name.to_s } + @items = @items.reject { |m| m.name.to_s =~ /=$/ && m.is_attribute? } + @items = @items.sort_by { |m| m.name.to_s } @list_title = 'Ruby Method List' @list_type = 'method' generate_list_contents @@ -75,7 +77,7 @@ def generate_class_list # Generates the searchable Puppet Task list. # @return [void] def generate_puppet_task_list - @items = Registry.all(:puppet_task).sort_by {|t| t.name.to_s } + @items = Registry.all(:puppet_task).sort_by { |t| t.name.to_s } @list_title = 'Puppet Task List' @list_type = 'puppet_task' generate_list_contents @@ -84,7 +86,7 @@ def generate_puppet_task_list # Generates the searchable Puppet Plan list. # @return [void] def generate_puppet_plan_list - @items = Registry.all(:puppet_plan).sort_by {|t| t.name.to_s } + @items = Registry.all(:puppet_plan).sort_by { |t| t.name.to_s } @list_title = 'Puppet Plan List' @list_type = 'puppet_plan' generate_list_contents diff --git a/lib/puppet-strings/yard/templates/default/layout/html/setup.rb b/lib/puppet-strings/yard/templates/default/layout/html/setup.rb index 0750fce36..d29daca7a 100644 --- a/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/layout/html/setup.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init case object when '_index.html' @page_title = options.title - sections :layout, [:index, [:listing, [:classes, :data_types, :defined_types, :types, :providers, :functions, :tasks, :plans, :files, :objects]]] + sections :layout, [:index, [:listing, %i[classes data_types defined_types types providers functions tasks plans files objects]]] else super end @@ -64,9 +66,7 @@ def layout final_layout = erb(:layout) - if @file && @file.name == 'README' - PuppetStrings::Yard::Util.github_to_yard_links(final_layout) - end + PuppetStrings::Yard::Util.github_to_yard_links(final_layout) if @file && @file.name == 'README' final_layout end @@ -83,12 +83,12 @@ def create_menu_lists { type: 'puppet_data_type', title: 'Data Types', - search_title: 'Data Types', + search_title: 'Data Types' }, { type: 'puppet_defined_type', title: 'Defined Types', - search_title: 'Defined Types', + search_title: 'Defined Types' }, { type: 'puppet_type', @@ -124,17 +124,19 @@ def create_menu_lists type: 'method', title: 'Ruby Methods', search_title: 'Method List' - }, + } ] menu_lists.delete_if { |e| YARD::Registry.all(e[:type].intern).empty? } # We must always return at least one group, so always keep the files list - menu_lists << { - type: 'file', - title: 'Files', - search_title: 'File List' - } if menu_lists.empty? || !YARD::Registry.all(:file).empty? + if menu_lists.empty? || !YARD::Registry.all(:file).empty? + menu_lists << { + type: 'file', + title: 'Files', + search_title: 'File List' + } + end menu_lists end @@ -150,9 +152,9 @@ def menu_lists # @return [Hash] Returns a hash of first letter of the object name to list of objects. def objects_by_letter(*types) hash = {} - objects = Registry.all(*types).sort_by {|o| o.name.to_s } + objects = Registry.all(*types).sort_by { |o| o.name.to_s } objects = run_verifier(objects) - objects.each {|o| (hash[o.name.to_s[0,1].upcase] ||= []) << o } + objects.each { |o| (hash[o.name.to_s[0, 1].upcase] ||= []) << o } hash end diff --git a/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb index bc98a85c0..be711d566 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init @@ -7,8 +9,8 @@ def init # Renders the box_info section. # @return [String] Returns the rendered section. def box_info - @subclasses = Registry.all(:puppet_class).find_all { |c| + @subclasses = Registry.all(:puppet_class).find_all do |c| c.statement.parent_class == object.name.to_s - } + end erb(:box_info) end diff --git a/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb index e7369a2cc..08a486930 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init @@ -9,5 +11,5 @@ def method_listing end def sort_listing(list) - list.sort_by {|o| [o.scope.to_s, o.name.to_s.downcase] } + list.sort_by { |o| [o.scope.to_s, o.name.to_s.downcase] } end diff --git a/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb index 288661e75..ae0cf43c8 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init @@ -9,8 +11,8 @@ def init def alias_of # Properties are the same thing as parameters (from the documentation standpoint), # so reuse the same template but with a different title and data source. - #@parameters = object.properties || [] - #@parameters.sort_by! { |p| p.name } + # @parameters = object.properties || [] + # @parameters.sort_by! { |p| p.name } @tag_title = 'Alias of' @alias_of = object.alias_of erb(:alias_of) diff --git a/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb index 345336a40..7798bbad0 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init diff --git a/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb index e99b57e96..ccaad68ba 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init diff --git a/lib/puppet-strings/yard/templates/default/puppet_plan/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_plan/html/setup.rb index c0bb74d03..79f4ba94c 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_plan/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_plan/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init diff --git a/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb index 0ad6dce9e..894fec0ed 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init diff --git a/lib/puppet-strings/yard/templates/default/puppet_task/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_task/html/setup.rb index 27820f88f..972e29ada 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_task/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_task/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init diff --git a/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb b/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb index 759bdf929..28455c656 100644 --- a/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +++ b/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Initializes the template. # @return [void] def init @@ -19,7 +21,7 @@ def properties # # "checks" such as "creates" and "onlyif" are another type of property @parameters = (object.properties || []) + (object.checks || []) - @parameters.sort_by! { |p| p.name } + @parameters.sort_by!(&:name) @tag_title = 'Properties' erb(:parameters) end @@ -28,7 +30,7 @@ def properties # @return [String] Returns the rendered section. def parameters @parameters = object.parameters || [] - @parameters.sort_by! { |p| p.name } + @parameters.sort_by!(&:name) @tag_title = 'Parameters' erb(:parameters) end diff --git a/lib/puppet-strings/yard/templates/default/tags/setup.rb b/lib/puppet-strings/yard/templates/default/tags/setup.rb index b47b07720..d6af2d2fd 100644 --- a/lib/puppet-strings/yard/templates/default/tags/setup.rb +++ b/lib/puppet-strings/yard/templates/default/tags/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Called to return parameter tags. # @return [Array] Returns the parameter tags if the object should have parameters. def param @@ -14,7 +16,7 @@ def param # Renders the overload section. # @return [String] Returns the rendered section. def overload - erb(if object.type == :puppet_function then :puppet_overload else :overload end) + erb(object.type == :puppet_function ? :puppet_overload : :overload) end # Renders the enum section. diff --git a/lib/puppet-strings/yard/util.rb b/lib/puppet-strings/yard/util.rb index 75c13691a..ecf4b6e50 100644 --- a/lib/puppet-strings/yard/util.rb +++ b/lib/puppet-strings/yard/util.rb @@ -9,10 +9,8 @@ module PuppetStrings::Yard::Util # @param [String] str The string to scrub. # @return [String] A scrubbed string. def self.scrub_string(str) - match = str.match(%r{^%[Qq]{(.*)}$}m) - if match - return Puppet::Util::Docs.scrub(match[1]) - end + match = str.match(/^%[Qq]{(.*)}$/m) + return Puppet::Util::Docs.scrub(match[1]) if match Puppet::Util::Docs.scrub(str) end @@ -25,7 +23,7 @@ def self.scrub_string(str) # @param [String] data HTML document to convert # @return [String] HTML document with links converted def self.github_to_yard_links(data) - data.scan(%r{href\=\"\#(.+)\"}).each do |bad_link| + data.scan(/href="\#(.+)"/).each do |bad_link| data = data.gsub("=\"##{bad_link.first}\"", "=\"#label-#{bad_link.first.capitalize.tr('-', '+')}\"") end diff --git a/lib/puppet/face/strings.rb b/lib/puppet/face/strings.rb index 5c90fc826..a09e85966 100644 --- a/lib/puppet/face/strings.rb +++ b/lib/puppet/face/strings.rb @@ -28,7 +28,7 @@ PuppetStrings.generate( args.count > 1 ? args[0..-2] : PuppetStrings::DEFAULT_SEARCH_PATTERNS, - build_generate_options(args.last), + build_generate_options(args.last) ) nil end @@ -127,7 +127,7 @@ search_patterns = ['types/**/*.pp', 'lib/**/*.rb'] PuppetStrings.generate( search_patterns, - build_generate_options(options), + build_generate_options(options) ) nil end @@ -138,7 +138,7 @@ def check_required_features raise "The 'yard' gem must be installed in order to use this face." unless Puppet.features.yard? raise "The 'rgen' gem must be installed in order to use this face." unless Puppet.features.rgen? - raise 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION.match?(%r{^1\.8}) + raise 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION.match?(/^1\.8/) end # Builds the options to PuppetStrings.generate. diff --git a/misc/ANNOUNCEMENT_TEMPLATE.md b/misc/ANNOUNCEMENT_TEMPLATE.md deleted file mode 100644 index c395ec731..000000000 --- a/misc/ANNOUNCEMENT_TEMPLATE.md +++ /dev/null @@ -1,40 +0,0 @@ -Send out announcements for major new feature releases, and high-impact bugfixes to , , , , and the puppet internal mailing lists and . - -Before sending, do check that all links are still valid. Feel free to adjust the text to match better with the circumstances of the release, or add other news that are relevant at the time. If you make changes, consider committing them here, for the benefit of future-you. - -The github rendering of the markdown seems to copy&paste acceptably into Google Inbox. - -The [CHANGELOG](https://github.com/puppetlabs/puppet-strings/blob/main/CHANGELOG.md) is a good starting point for finding enhancements and bug-fixes. - ---- - -Subject: [ANN] Puppet Strings vX.Y.Z Release - -Hi all, - -We're pleased to announce that version X.Y.Z of the Puppet Strings is being released today. - -Puppet Strings provides a simple way to extract source documentation into useful docs. It is provided as a Ruby gem to be referenced within modules. See the [README](https://github.com/puppetlabs/puppet-strings#installing-puppet-strings) for documentation on how to install and use it. - - -The new release of Puppet Strings provides the following enhancements: - -* A -* B -* C - -The new release also contains the following notable bugfixes: - -* D -* E -* F - -See the [CHANGELOG](https://github.com/puppetlabs/puppet-strings/blob/main/CHANGELOG.md) for a full list of changes - -We encourage all module developers to review puppet-strings and use it when creating modules. - -Please let us know of your experiences with Puppet Strings, either here, on [Slack](https://slack.puppet.com/) (#forge-modules), or on the [github repo](https://github.com/puppetlabs/puppet-strings). - - -Thanks, -YOUR NAME diff --git a/puppet-strings.gemspec b/puppet-strings.gemspec index 4c04f8994..33e8f0352 100644 --- a/puppet-strings.gemspec +++ b/puppet-strings.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'puppet-strings/version' @@ -19,11 +19,11 @@ Gem::Specification.new do |s| 'COMMITTERS.md', 'CONTRIBUTING.md', 'LICENSE', - 'README.md', + 'README.md' ] s.files = Dir['CHANGELOG.md', 'README.md', 'LICENSE', 'lib/**/*', 'exe/**/*'] - s.add_runtime_dependency 'yard', '~> 0.9.5' - s.add_runtime_dependency 'rgen', '~> 0.9.0' - s.requirements << 'puppet, >= 6.0.0' + s.add_runtime_dependency 'rgen', '~> 0.9' + s.add_runtime_dependency 'yard', '~> 0.9' + s.requirements << 'puppet, >= 7.0.0' end diff --git a/spec/acceptance/generate_json_spec.rb b/spec/acceptance/generate_json_spec.rb index 5858a69b8..d0ee995fb 100644 --- a/spec/acceptance/generate_json_spec.rb +++ b/spec/acceptance/generate_json_spec.rb @@ -4,7 +4,7 @@ describe 'Generating JSON' do let(:test_module_path) do - sut_module_path(%r{Module test}) + sut_module_path(/Module test/) end let(:remote_tmp_path) do @@ -34,16 +34,16 @@ 'tag_name' => 'return', 'text' => '', 'types' => ['Any'] - }, + } ] } - }, + } ], 'docstring' => { 'text' => 'This is the function documentation for `function3x`', 'tags' => ['tag_name' => 'return', 'text' => '', 'types' => ['Any']] }, - 'source' => "Puppet::Parser::Functions.newfunction(:function3x, :doc => \"This is the function documentation for `function3x`\") do |args|\nend", + 'source' => "Puppet::Parser::Functions.newfunction(:function3x, :doc => \"This is the function documentation for `function3x`\") do |args|\nend" ], 'puppet_tasks' => [], 'puppet_plans' => [] diff --git a/spec/acceptance/generate_markdown_spec.rb b/spec/acceptance/generate_markdown_spec.rb index 925d0c92c..96200c4c2 100644 --- a/spec/acceptance/generate_markdown_spec.rb +++ b/spec/acceptance/generate_markdown_spec.rb @@ -4,14 +4,14 @@ describe 'Generating Markdown' do let(:test_module_path) do - sut_module_path(%r{Module test}) + sut_module_path(/Module test/) end let(:remote_tmp_path) do sut_tmp_path end - expected = <<~'EOF' + expected = <<~EOF # Reference ## Classes diff --git a/spec/acceptance/running_strings_generate_spec.rb b/spec/acceptance/running_strings_generate_spec.rb index af37a9a4d..776dfebd0 100644 --- a/spec/acceptance/running_strings_generate_spec.rb +++ b/spec/acceptance/running_strings_generate_spec.rb @@ -10,7 +10,7 @@ before :all do # TODO: Linux only - test_module_path = sut_module_path(%r{Module test}) + test_module_path = sut_module_path(/Module test/) PuppetLitmus::PuppetHelpers.run_shell("puppet strings generate \"#{test_module_path}/**/*.{rb,pp}\"") end @@ -33,7 +33,7 @@ def expect_file_contain(path, expected_contents) # These tests are failing. Appear to be legitimate failures. '

The first integer to add.

', '

The second integer to add.

', - '

Returns the sum of x and y.

', + '

Returns the sum of x and y.

' ]) end @@ -52,7 +52,7 @@ def expect_file_contain(path, expected_contents) '

Documentation for a dynamic property.

', '

The database server name.

', '

Documentation for a dynamic parameter.

', - '

The provider supports encryption.

', + '

The provider supports encryption.

' ]) end @@ -60,7 +60,7 @@ def expect_file_contain(path, expected_contents) expect_file_contain('doc/puppet_providers_database/linux.html', [ 'The database provider on Linux', 'osfamily — linux', - 'database — /usr/bin/database', + 'database — /usr/bin/database' ]) end @@ -71,7 +71,7 @@ def expect_file_contain(path, expected_contents) '

func1

', '

func1 documentation

', '

param1 func1 documentation

', - '

param2 func1 documentation

', + '

param2 func1 documentation

' ]) end @@ -79,7 +79,7 @@ def expect_file_contain(path, expected_contents) expect_file_contain('doc/puppet_data_type_aliases/Test_3A_3AElephant.html', [ 'Data Type: Test::Elephant', 'types/elephant.pp', - 'A simple elephant type.', + 'A simple elephant type.' ]) end @@ -87,9 +87,9 @@ def expect_file_contain(path, expected_contents) expect_file_contain('doc/puppet_classes/test.html', [ '

Enum Options (myenum):

', 'a', - "—
\n

Option A

\n
", + "—

Option A

\n
", 'b', - "—
\n

Option B

\n
", + "—

Option B

\n
" ]) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9fce165c4..fc3c86fea 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,7 @@ SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console, - SimpleCov::Formatter::Codecov, + SimpleCov::Formatter::Codecov ] SimpleCov.start do @@ -46,7 +46,7 @@ RSpec.configure do |config| config.mock_with :mocha - config.before(:each) do + config.before do # Always clear the YARD registry before each example YARD::Registry.clear end @@ -54,7 +54,7 @@ def lint_markdown(content) # Load default mdl ruleset - ruleset = MarkdownLint::RuleSet.new.tap { |r| r.load_default } + ruleset = MarkdownLint::RuleSet.new.tap(&:load_default) # Apply custom style to ruleset rules MarkdownLint::Style.load(File.join(__dir__, 'markdownlint_style.rb'), ruleset.rules) @@ -84,6 +84,6 @@ def lint_markdown(content) end failure_message do |actual| - "expected that #{actual.length > 80 ? actual.slice(0, 80).inspect + '...' : actual.inspect} would have no markdown lint errors but got #{@violations.join("\n")}" + "expected that #{actual.length > 80 ? "#{actual.slice(0, 80).inspect}..." : actual.inspect} would have no markdown lint errors but got #{@violations.join("\n")}" end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 7234e6974..d6f1ce0e2 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true def sut_module_path(module_regex) - modules = JSON.parse(run_shell('puppet module list --render-as json').stdout) + modules = JSON.parse(run_shell('bundle exec puppet module list --modulepath spec/fixtures/modules --render-as json').stdout) test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex } - test_module_info.match(%r{\(([^)]*)\)})[1] + test_module_info.match(/\(([^)]*)\)/)[1] end def sut_tmp_path diff --git a/spec/unit/puppet-strings/describe_spec.rb b/spec/unit/puppet-strings/describe_spec.rb index d4543b0b2..28a7eb7b9 100644 --- a/spec/unit/puppet-strings/describe_spec.rb +++ b/spec/unit/puppet-strings/describe_spec.rb @@ -12,16 +12,16 @@ #--short - only list params describe PuppetStrings::Describe do - before :each do + before do # Populate the YARD registry with both Puppet and Ruby source - YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :ruby) + YARD::Parser::SourceParser.parse_string(<<~SOURCE, :ruby) Puppet::Type.newtype(:database) do desc 'An example database server resource type.' end SOURCE - YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :ruby) + YARD::Parser::SourceParser.parse_string(<<~SOURCE, :ruby) Puppet::ResourceApi.register_type( name: 'apt_key', docs: <<~'EOS', @@ -42,7 +42,7 @@ ) SOURCE - YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :ruby) + YARD::Parser::SourceParser.parse_string(<<~SOURCE, :ruby) Puppet::Type.type(:file).newproperty(:content) do include Puppet::Util::Checksums include Puppet::DataSync @@ -80,7 +80,7 @@ end SOURCE - YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :ruby) + YARD::Parser::SourceParser.parse_string(<<~SOURCE, :ruby) Puppet::Type.type(:file).newproperty(:source) do include Puppet::Util::Checksums include Puppet::DataSync @@ -97,7 +97,7 @@ describe 'rendering DESCRIBE to stdout' do it 'outputs the expected describe content for the list of types' do - output = <<~'DATA' + output = <<~DATA These are the types known to puppet: apt_key - This type provides Puppet with the capabiliti ... database - An example database server resource type. @@ -105,6 +105,7 @@ DATA expect { described_class.render(nil, true) }.to output(output).to_stdout end + it 'outputs the expected describe content for a type' do output = <<~'DATA' diff --git a/spec/unit/puppet-strings/json_spec.rb b/spec/unit/puppet-strings/json_spec.rb index 4c3ec4b8f..034312450 100644 --- a/spec/unit/puppet-strings/json_spec.rb +++ b/spec/unit/puppet-strings/json_spec.rb @@ -5,9 +5,9 @@ require 'tempfile' describe PuppetStrings::Json do - before :each do + before do # Populate the YARD registry with both Puppet and Ruby source - expect(YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :puppet).enumerator.length).to eq(2) + expect(YARD::Parser::SourceParser.parse_string(<<~SOURCE, :puppet).enumerator.length).to eq(2) # A simple class. # @todo Do a thing # @deprecated No longer supported and will be removed in a future release @@ -26,7 +26,7 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { } SOURCE - expect(YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :puppet).enumerator.length).to eq(1) if TEST_PUPPET_PLANS + expect(YARD::Parser::SourceParser.parse_string(<<~SOURCE, :puppet).enumerator.length).to eq(1) if TEST_PUPPET_PLANS # A simple plan. # @param param1 First param. # @param param2 Second param. @@ -36,7 +36,7 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { SOURCE # Only include Puppet functions for 4.1+ - expect(YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :puppet).enumerator.length).to eq(1) if TEST_PUPPET_FUNCTIONS + expect(YARD::Parser::SourceParser.parse_string(<<~SOURCE, :puppet).enumerator.length).to eq(1) if TEST_PUPPET_FUNCTIONS # A simple function. # @param param1 First param. # @param param2 Second param. @@ -47,7 +47,7 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { SOURCE # Only include Puppet types for 5.0+ - expect(YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :ruby).enumerator.length).to eq(1) if TEST_PUPPET_DATATYPES + expect(YARD::Parser::SourceParser.parse_string(<<~SOURCE, :ruby).enumerator.length).to eq(1) if TEST_PUPPET_DATATYPES # Basic Puppet Data Type in Ruby # # @param msg A message parameter @@ -68,7 +68,7 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { end SOURCE - expect(YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :json).enumerator.length).to eq(1) + expect(YARD::Parser::SourceParser.parse_string(<<~SOURCE, :json).enumerator.length).to eq(1) { "description": "Allows you to backup your database to local file.", "input_method": "stdin", diff --git a/spec/unit/puppet-strings/markdown/base_spec.rb b/spec/unit/puppet-strings/markdown/base_spec.rb index 250858c79..f36cb0633 100644 --- a/spec/unit/puppet-strings/markdown/base_spec.rb +++ b/spec/unit/puppet-strings/markdown/base_spec.rb @@ -4,8 +4,8 @@ describe PuppetStrings::Markdown::Base do context 'basic class' do - before :each do - YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :puppet) + before do + YARD::Parser::SourceParser.parse_string(<<~SOURCE, :puppet) # An overview # @api private # @summary A simple class. @@ -27,11 +27,11 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { end end - ['examples', - 'see', - 'since', - 'return_val', - 'return_type'].each do |method| + %w[examples + see + since + return_val + return_type].each do |method| describe "##{method}" do it 'returns nil' do expect(component.method(method.to_sym).call).to be_nil @@ -69,14 +69,16 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { it 'returns a hash' do expect(toc).to be_instance_of Hash end + it 'prefers the summary for :desc' do expect(toc[:desc]).to eq 'A simple class.' end end end + context 'less basic class' do - before :each do - YARD::Parser::SourceParser.parse_string(<<~'SOURCE', :puppet) + before do + YARD::Parser::SourceParser.parse_string(<<~SOURCE, :puppet) # An overview # It's a longer overview # Ya know? @@ -106,11 +108,11 @@ class klass::yeah( end end - ['summary', - 'see', - 'since', - 'return_val', - 'return_type'].each do |method| + %w[summary + see + since + return_val + return_type].each do |method| describe "##{method}" do it 'returns nil' do expect(component.method(method.to_sym).call).to be_nil @@ -142,6 +144,7 @@ class klass::yeah( it 'returns a hash' do expect(toc).to be_instance_of Hash end + it 'uses overview for :desc in absence of summary' do expect(toc[:desc]).to eq 'An overview It\'s a longer overview Ya know?' end diff --git a/spec/unit/puppet-strings/markdown_spec.rb b/spec/unit/puppet-strings/markdown_spec.rb index bfb5ae892..139fd9e7f 100644 --- a/spec/unit/puppet-strings/markdown_spec.rb +++ b/spec/unit/puppet-strings/markdown_spec.rb @@ -49,7 +49,7 @@ def parse_data_type_content end end - before(:each) do + before do parse_shared_content end @@ -57,48 +57,48 @@ def parse_data_type_content describe 'table of contents' do it 'includes links to public classes' do - expect(output).to match(%r{\[`klass`\]\(#.*\).*simple class}i) + expect(output).to match(/\[`klass`\]\(#.*\).*simple class/i) end it 'includes links to private classes' do - expect(output).to match(%r{`noparams`.*overview.*noparams}i) + expect(output).to match(/`noparams`.*overview.*noparams/i) end it 'includes links to defined types' do - expect(output).to match(%r{\[`klass::dt`\]\(#.*\).*simple defined type}i) + expect(output).to match(/\[`klass::dt`\]\(#.*\).*simple defined type/i) end it 'includes links to resource types' do - expect(output).to match(%r{\[`apt_key`\]\(#.*\).*resource type.*new api}i) - expect(output).to match(%r{\[`database`\]\(#.*\).*example database.*type}i) + expect(output).to match(/\[`apt_key`\]\(#.*\).*resource type.*new api/i) + expect(output).to match(/\[`database`\]\(#.*\).*example database.*type/i) end it 'includes links to functions' do - expect(output).to match(%r{\[`func`\]\(#.*\).*simple puppet function}i) - expect(output).to match(%r{\[`func3x`\]\(#.*\).*example 3\.x function}i) - expect(output).to match(%r{\[`func4x`\]\(#.*\).*example 4\.x function}i) - expect(output).to match(%r{\[`func4x_1`\]\(#.*\).*example 4\.x function.*one signature}i) + expect(output).to match(/\[`func`\]\(#.*\).*simple puppet function/i) + expect(output).to match(/\[`func3x`\]\(#.*\).*example 3\.x function/i) + expect(output).to match(/\[`func4x`\]\(#.*\).*example 4\.x function/i) + expect(output).to match(/\[`func4x_1`\]\(#.*\).*example 4\.x function.*one signature/i) end it 'includes links to tasks' do - expect(output).to match(%r{\[`backup`\]\(#.*\).*backup your database}i) + expect(output).to match(/\[`backup`\]\(#.*\).*backup your database/i) end end describe 'resource types' do it 'includes checks in parameter list for the database type' do - expect(output).to match(%r{check to see if the database already exists}i) + expect(output).to match(/check to see if the database already exists/i) end end describe 'deprecated message' do it 'includes deprecated message' do - expect(output).to match(%r{\*\*DEPRECATED\*\* No longer supported and will be removed in a future release}) + expect(output).to match(/\*\*DEPRECATED\*\* No longer supported and will be removed in a future release/) end end describe 'with Puppet Plans', if: TEST_PUPPET_PLANS do - before(:each) do + before do parse_plan_content end @@ -106,13 +106,13 @@ def parse_data_type_content describe 'table of contents' do it 'includes links to plans' do - expect(output).to match(%r{\[`plann`\]\(#.*\).*simple plan}i) + expect(output).to match(/\[`plann`\]\(#.*\).*simple plan/i) end end end describe 'with Puppet Data Types', if: TEST_PUPPET_DATATYPES do - before(:each) do + before do parse_data_type_content end @@ -120,58 +120,58 @@ def parse_data_type_content describe 'table of contents' do it 'includes links to data types' do - expect(output).to match(%r{\[`Amodule::ComplexAlias`\]\(#.*\).*Amodule::ComplexAlias}i) - expect(output).to match(%r{\[`Amodule::SimpleAlias`\]\(#.*\).*Amodule::SimpleAlias}i) - expect(output).to match(%r{\[`UnitDataType`\]\(#.*\).*data type in ruby}i) + expect(output).to match(/\[`Amodule::ComplexAlias`\]\(#.*\).*Amodule::ComplexAlias/i) + expect(output).to match(/\[`Amodule::SimpleAlias`\]\(#.*\).*Amodule::SimpleAlias/i) + expect(output).to match(/\[`UnitDataType`\]\(#.*\).*data type in ruby/i) end end describe 'parameter docs' do it 'includes param name' do - expect(output).to match(%r{#+ `param1`}) + expect(output).to match(/#+ `param1`/) end it 'includes param type' do - expect(output).to match(%r{Data type: `Variant\[Numeric, String\[1,2\]\]`}) + expect(output).to match(/Data type: `Variant\[Numeric, String\[1,2\]\]`/) end it 'includes param description' do - expect(output).to match(%r{a variant parameter}i) + expect(output).to match(/a variant parameter/i) end it 'includes param default' do - expect(output).to match(%r{default value: `param2`}i) + expect(output).to match(/default value: `param2`/i) end end describe 'function docs' do it 'includes signature' do - expect(output).to match(%r{UnitDataType\.func1\(param1, param2\)}) + expect(output).to match(/UnitDataType\.func1\(param1, param2\)/) end it 'includes summary' do - expect(output).to match(%r{func1 documentation}i) + expect(output).to match(/func1 documentation/i) end it 'includes parameter docs' do - expect(output).to match(%r{param1 documentation}i) + expect(output).to match(/param1 documentation/i) end it 'includes return value' do - expect(output).to match(%r{returns: `optional\[string\]`}i) + expect(output).to match(/returns: `optional\[string\]`/i) end end end end it 'renders only private functions correctly' do - expect(YARD::Parser::SourceParser.parse_string(<<~'PUPPET', :puppet).enumerator.length).to eq(1) + expect(YARD::Parser::SourceParser.parse_string(<<~PUPPET, :puppet).enumerator.length).to eq(1) # @return void # @api private function func_private() {} PUPPET - expect(described_class.generate).to eq(<<~'MARKDOWN') + expect(described_class.generate).to eq(<<~MARKDOWN) # Reference @@ -188,12 +188,12 @@ def parse_data_type_content end it 'renders only public functions correctly' do - expect(YARD::Parser::SourceParser.parse_string(<<~'PUPPET', :puppet).enumerator.length).to eq(1) + expect(YARD::Parser::SourceParser.parse_string(<<~PUPPET, :puppet).enumerator.length).to eq(1) # @return void function func_public() {} PUPPET - expect(described_class.generate).to eq(<<~'MARKDOWN') + expect(described_class.generate).to eq(<<~MARKDOWN) # Reference @@ -222,7 +222,7 @@ def parse_data_type_content end it 'renders both public and private functions correctly' do - expect(YARD::Parser::SourceParser.parse_string(<<~'PUPPET', :puppet).enumerator.length).to eq(2) + expect(YARD::Parser::SourceParser.parse_string(<<~PUPPET, :puppet).enumerator.length).to eq(2) # @return void function func_public() {} @@ -231,7 +231,7 @@ def parse_data_type_content function func_private() {} PUPPET - expect(described_class.generate).to eq(<<~'MARKDOWN') + expect(described_class.generate).to eq(<<~MARKDOWN) # Reference @@ -266,16 +266,16 @@ def parse_data_type_content end it 'renders single-line data types with inline code' do - expect(YARD::Parser::SourceParser.parse_string(<<~'PUPPET', :puppet).enumerator.length).to eq(1) + expect(YARD::Parser::SourceParser.parse_string(<<~PUPPET, :puppet).enumerator.length).to eq(1) # @summary it’s for testing type MyEnum = Enum[a, b] PUPPET - expect(described_class.generate).to match(%r{^Alias of `Enum\[a, b\]`$}) + expect(described_class.generate).to match(/^Alias of `Enum\[a, b\]`$/) end it 'renders multi-line data types with inline code' do - expect(YARD::Parser::SourceParser.parse_string(<<~'PUPPET', :puppet).enumerator.length).to eq(1) + expect(YARD::Parser::SourceParser.parse_string(<<~PUPPET, :puppet).enumerator.length).to eq(1) # summary Test Type # type Test_module::Test_type = Hash[ @@ -290,7 +290,7 @@ def parse_data_type_content ] PUPPET - expect(described_class.generate).to include(<<~'MARKDOWN') + expect(described_class.generate).to include(<<~MARKDOWN) Alias of ```puppet @@ -306,7 +306,7 @@ def parse_data_type_content end it 'renders single-line default values with inline code' do - expect(YARD::Parser::SourceParser.parse_string(<<~'PUPPET', :puppet).enumerator.length).to eq(1) + expect(YARD::Parser::SourceParser.parse_string(<<~PUPPET, :puppet).enumerator.length).to eq(1) # @summary Test class myclass ( String $os = 'linux', @@ -314,7 +314,7 @@ class myclass ( } PUPPET - expect(described_class.generate).to include(<<~'MARKDOWN') + expect(described_class.generate).to include(<<~MARKDOWN) Default value: `'linux'` MARKDOWN end @@ -322,7 +322,7 @@ class myclass ( it 'renders multi-line default values with a code block' do skip('Broken by https://tickets.puppetlabs.com/browse/PUP-11632') - expect(YARD::Parser::SourceParser.parse_string(<<~'PUPPET', :puppet).enumerator.length).to eq(1) + expect(YARD::Parser::SourceParser.parse_string(<<~PUPPET, :puppet).enumerator.length).to eq(1) # @summary Test class myclass ( String $os = $facts['kernel'] ? { @@ -334,7 +334,7 @@ class myclass ( } PUPPET - expect(described_class.generate).to include(<<~'MARKDOWN') + expect(described_class.generate).to include(<<~MARKDOWN) Default value: ```puppet 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 f0edd015f..83cb33463 100644 --- a/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +++ b/spec/unit/puppet-strings/yard/code_objects/task_spec.rb @@ -7,7 +7,7 @@ describe PuppetStrings::Yard::CodeObjects::Task do subject(:spec_subject) { described_class.new(statement) } - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "description": "Allows you to backup your database to local file.", "input_method": "stdin", @@ -77,7 +77,7 @@ tag_name: 'param', text: 'Path to file you want backup to', types: ['String[1]'] - }, + } ] }, file: 'test.json', 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 650b7323e..f739ed554 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 @@ -10,7 +10,7 @@ end describe 'parsing task metadata with a syntax error' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "input_method": "stdin", "parameters": @@ -23,13 +23,13 @@ SOURCE it 'logs an error' do - expect { spec_subject }.to output(%r{\[error\]: Failed to parse \(stdin\):}).to_stdout_from_any_process - expect(spec_subject.empty?).to eq(true) + expect { spec_subject }.to output(/\[error\]: Failed to parse \(stdin\):/).to_stdout_from_any_process + expect(spec_subject.empty?).to be(true) end end describe 'parsing task metadata with a missing description' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "input_method": "stdin", "parameters": { @@ -54,12 +54,12 @@ SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing a description for Puppet Task \(stdin\)}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing a description for Puppet Task \(stdin\)/).to_stdout_from_any_process end end describe 'parsing task metadata with a description' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "description": "Allows you to backup your database to local file.", "input_method": "stdin", @@ -94,7 +94,7 @@ end describe 'parsing task metadata with a missing parameter description' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "description": "Allows you to backup your database to local file.", "input_method": "stdin", @@ -107,7 +107,7 @@ SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing description for param 'database' in Puppet Task \(stdin\)}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing description for param 'database' in Puppet Task \(stdin\)/).to_stdout_from_any_process end end end 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 9fedb2fd2..8a50ef65c 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 @@ -13,7 +13,7 @@ let(:source) { 'notice hi' } it 'no classes should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end @@ -21,8 +21,8 @@ let(:source) { 'class foo{' } it 'logs an error' do - expect { spec_subject }.to output(%r{\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)}).to_stdout_from_any_process - expect(spec_subject.empty?).to eq(true) + expect { spec_subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)/).to_stdout_from_any_process + expect(spec_subject.empty?).to be(true) end end @@ -30,12 +30,12 @@ let(:source) { 'class foo{}' } it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing documentation for Puppet class 'foo' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing documentation for Puppet class 'foo' at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a class with a docstring' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @param param1 First param. # @param param2 Second param. @@ -53,8 +53,8 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Class) expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Classes.instance) expect(object.name).to eq(:foo) - expect(object.statement).not_to eq(nil) - expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']]) + expect(object.statement).not_to be_nil + expect(object.parameters).to eq([['param1', nil], ['param2', nil], %w[param3 hi]]) expect(object.docstring).to eq('A simple foo class.') expect(object.docstring.tags.size).to eq(4) tags = object.docstring.tags(:param) @@ -75,7 +75,7 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { end describe 'parsing a class with a missing parameter' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @param param1 First param. # @param param2 Second param. @@ -89,12 +89,12 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process end end describe 'parsing a class with a missing @param tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @param param1 First param. # @param param2 Second param. @@ -106,12 +106,12 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process end end describe 'parsing a class with a typed parameter that also has a @param tag type which matches' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @param [Integer] param1 First param. # @param param2 Second param. @@ -133,7 +133,7 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { end describe 'parsing a class with a typed parameter that also has a @param tag type which does not match' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @param [Boolean] param1 First param. # @param param2 Second param. @@ -148,14 +148,14 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { it 'outputs a warning' do expect { spec_subject } .to output( - %r{\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information.}, + /\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information./ ) .to_stdout_from_any_process end end describe 'parsing a class with a untyped parameter that also has a @param tag type' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @param param1 First param. # @param [Boolean] param2 Second param. @@ -178,7 +178,7 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { describe 'parsing a class with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @summary A short summary. class foo() { @@ -197,7 +197,7 @@ class foo() { end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo class. # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!! class foo() { @@ -208,7 +208,7 @@ class foo() { SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_class 'foo' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_class 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 c40939ad3..b83e8d16b 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 @@ -13,7 +13,7 @@ let(:source) { 'notice hi' } it 'no aliases should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end @@ -21,8 +21,8 @@ let(:source) { 'type Testype =' } it 'logs an error' do - expect { spec_subject }.to output(%r{\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)}).to_stdout_from_any_process - expect(spec_subject.empty?).to eq(true) + expect { spec_subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)/).to_stdout_from_any_process + expect(spec_subject.empty?).to be(true) end end @@ -30,13 +30,13 @@ let(:source) { 'type Testype = String[1]' } it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing documentation for Puppet type alias 'Testype' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing documentation for Puppet type alias 'Testype' at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a data type alias with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo type. # @summary A short summary. type Testype = String[1] @@ -51,14 +51,14 @@ end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo type. # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!! type Testype = String[1] SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_data_type_alias 'Testype' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_data_type_alias 'Testype' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 5807d1790..82f0c13eb 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 @@ -13,7 +13,7 @@ let(:source) { 'notice hi' } it 'no defined types should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end @@ -21,8 +21,8 @@ let(:source) { 'define foo{' } it 'logs an error' do - expect { spec_subject }.to output(%r{\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)}).to_stdout_from_any_process - expect(spec_subject.empty?).to eq(true) + expect { spec_subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)/).to_stdout_from_any_process + expect(spec_subject.empty?).to be(true) end end @@ -30,12 +30,12 @@ let(:source) { 'define foo{}' } it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing documentation for Puppet defined type 'foo' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing documentation for Puppet defined type 'foo' at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a defined type with a docstring' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @param name The type name. # @param param1 First param. @@ -49,7 +49,7 @@ SOURCE it 'does not output a warning for title/name' do - expect { spec_subject }.not_to output(%r{\[warn\].*(name|title).*}).to_stdout_from_any_process + expect { spec_subject }.not_to output(/\[warn\].*(name|title).*/).to_stdout_from_any_process end it 'registers a defined type object' do @@ -58,15 +58,15 @@ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::DefinedType) expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::DefinedTypes.instance) expect(object.name).to eq(:foo) - expect(object.statement).not_to eq(nil) - expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']]) + expect(object.statement).not_to be_nil + expect(object.parameters).to eq([['param1', nil], ['param2', nil], %w[param3 hi]]) expect(object.docstring).to eq('A simple foo defined type.') expect(object.docstring.tags.size).to eq(5) tags = object.docstring.tags(:param) expect(tags.size).to eq(4) expect(tags[0].name).to eq('name') expect(tags[0].text).to eq('The type name.') - expect(tags[0].types).to eq(nil) + expect(tags[0].types).to be_nil expect(tags[1].name).to eq('param1') expect(tags[1].text).to eq('First param.') expect(tags[1].types).to eq(['Integer']) @@ -83,7 +83,7 @@ end describe 'parsing a defined type with a missing parameter' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @param param1 First param. # @param param2 Second param. @@ -97,12 +97,12 @@ SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process end end describe 'parsing a defined type with a missing @param tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @param param1 First param. # @param param2 Second param. @@ -114,12 +114,12 @@ SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process end end describe 'parsing a defined type with a typed parameter that also has a @param tag type which matches' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @param [Integer] param1 First param. # @param param2 Second param. @@ -141,7 +141,7 @@ end describe 'parsing a defined type with a typed parameter that also has a @param tag type which does not match' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @param [Boolean] param1 First param. # @param param2 Second param. @@ -155,13 +155,13 @@ it 'outputs a warning' do expect { spec_subject } - .to output(%r{\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information.}) + .to output(/\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information./) .to_stdout_from_any_process end end describe 'parsing a defined type with a untyped parameter that also has a @param tag type' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @param param1 First param. # @param [Boolean] param2 Second param. @@ -184,7 +184,7 @@ describe 'parsing a defined type with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @summary A short summary. # @param param1 First param. @@ -206,7 +206,7 @@ end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo defined type. # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!! # @param param1 First param. @@ -220,7 +220,7 @@ SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_defined_type 'foo' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_defined_type 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 aea363e8f..1297993ba 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 @@ -14,7 +14,7 @@ let(:source) { 'notice hi' } it 'no functions should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end @@ -22,8 +22,8 @@ let(:source) { 'function foo{' } it 'logs an error' do - expect { spec_subject }.to output(%r{\[error\]: Failed to parse \(stdin\): Syntax error at end of}).to_stdout_from_any_process - expect(spec_subject.empty?).to eq(true) + expect { spec_subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of/).to_stdout_from_any_process + expect(spec_subject.empty?).to be(true) end end @@ -31,12 +31,12 @@ let(:source) { 'function foo{}' } it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a function with a docstring' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @param param1 First param. # @param param2 Second param. @@ -55,7 +55,7 @@ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::PUPPET)) expect(object.name).to eq(:foo) expect(object.signature).to eq('foo(Integer $param1, Any $param2, String $param3 = hi)') - expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']]) + expect(object.parameters).to eq([['param1', nil], ['param2', nil], %w[param3 hi]]) expect(object.docstring).to eq('A simple foo function.') expect(object.docstring.tags.size).to eq(5) tags = object.docstring.tags(:param) @@ -81,7 +81,7 @@ end describe 'parsing a function with a missing parameter' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @param param1 First param. # @param param2 Second param. @@ -95,13 +95,13 @@ it 'outputs a warning' do expect { spec_subject } - .to output(%r{\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):7\.}) + .to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):7\./) .to_stdout_from_any_process end end describe 'parsing a function with a missing @param tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @param param1 First param. # @param param2 Second param. @@ -112,12 +112,12 @@ SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):5\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):5\./).to_stdout_from_any_process end end describe 'parsing a function with a typed parameter that also has a @param tag type which matches' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @param [Integer] param1 First param. # @param param2 Second param. @@ -138,7 +138,7 @@ end describe 'parsing a function with a typed parameter that also has a @param tag type which does not match' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @param [Boolean] param1 First param. # @param param2 Second param. @@ -152,14 +152,14 @@ it 'outputs a warning' do expect { spec_subject } .to output( - %r{\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):6: ignoring in favor of parameter type information.}, + /\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):6: ignoring in favor of parameter type information./ ) .to_stdout_from_any_process end end describe 'parsing a function with a untyped parameter that also has a @param tag type' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @param param1 First param. # @param [Boolean] param2 Second param. @@ -180,7 +180,7 @@ end describe 'parsing a function with a missing @return tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @param param1 First param. # @param param2 Second param. @@ -191,12 +191,12 @@ SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @return tag near \(stdin\):5\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):5\./).to_stdout_from_any_process end end describe 'parsing a function with a missing @return tag and return type specified in the function definition', if: TEST_FUNCTION_RETURN_TYPE do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. function foo() >> String { notice 'hello world' @@ -204,7 +204,7 @@ SOURCE it 'registers a function object with the correct return type' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @return tag near \(stdin\):2\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):2\./).to_stdout_from_any_process expect(spec_subject.size).to eq(1) object = spec_subject.first expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function) @@ -217,7 +217,7 @@ end describe 'parsing a function with a non-conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function # @return [String] Hi there function foo() >> String { @@ -226,12 +226,12 @@ SOURCE it 'does not output a warning if return types match' do - expect { spec_subject }.not_to output(%r{Documented return type does not match return type in function definition}).to_stdout_from_any_process + expect { spec_subject }.not_to output(/Documented return type does not match return type in function definition/).to_stdout_from_any_process end end describe 'parsing a function with a conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @return [Integer] this is a lie. function foo() >> Struct[{'a' => Integer[1, 10]}] { @@ -240,7 +240,7 @@ SOURCE it 'prefers the return type from the function definition' do - expect { spec_subject }.to output(%r{\[warn\]: Documented return type does not match return type in function definition near \(stdin\):3\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Documented return type does not match return type in function definition near \(stdin\):3\./).to_stdout_from_any_process expect(spec_subject.size).to eq(1) object = spec_subject.first expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function) @@ -253,7 +253,7 @@ end describe 'parsing a function with return tag without type', if: TEST_FUNCTION_RETURN_TYPE do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @return This is something. function foo() >> Struct[{'a' => Integer[1, 10]}] { @@ -275,7 +275,7 @@ end describe 'parsing a function without a return tag or return type in the function definition' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. function foo() { notice 'hello world' @@ -283,7 +283,7 @@ SOURCE it 'adds a return tag with a default type value of Any' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @return tag near \(stdin\):2\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):2\./).to_stdout_from_any_process expect(spec_subject.size).to eq(1) object = spec_subject.first expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function) @@ -297,7 +297,7 @@ describe 'parsing a function with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @summary A short summary. # @return [String] foo @@ -315,7 +315,7 @@ end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!! function foo() { @@ -325,7 +325,7 @@ SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_function 'foo' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_function 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 2d5fbe177..6462511f6 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 @@ -13,7 +13,7 @@ # so remember the logging object prior to running the test. original_yard_logging_object = YARD::Logger.instance.io - after(:each) do + after do # Restore the original logging IO object YARD::Logger.instance.io = original_yard_logging_object end @@ -26,12 +26,12 @@ def suppress_yard_logging let(:source) { 'puts "hi"' } it 'no data types should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end describe 'parsing an empty data type definition' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::DataTypes.create_type('RubyDataType') do end SOURCE @@ -54,7 +54,7 @@ def suppress_yard_logging end describe 'parsing a data type definition with missing param tags' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. Puppet::DataTypes.create_type('RubyDataType') do interface <<~'PUPPET' @@ -66,7 +66,7 @@ def suppress_yard_logging SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @param tag for attribute 'msg' near \(stdin\):2}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @param tag for attribute 'msg' near \(stdin\):2/).to_stdout_from_any_process end it 'registers a data type object with all param tags' do @@ -98,7 +98,7 @@ def suppress_yard_logging describe 'parsing a data type definition with missing function' do context 'which has parameters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. Puppet::DataTypes.create_type('RubyDataType') do interface <<~'PUPPET' @@ -110,7 +110,7 @@ def suppress_yard_logging SOURCE it 'outputs a warning about the missing functions' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @!method tag for function 'func1' near \(stdin\):2}m).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @!method tag for function 'func1' near \(stdin\):2/m).to_stdout_from_any_process end it 'registers a data type object with all functions' do @@ -145,7 +145,7 @@ def suppress_yard_logging end context 'which has multiple functions' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. Puppet::DataTypes.create_type('RubyDataType') do interface <<~'PUPPET' @@ -158,11 +158,11 @@ def suppress_yard_logging SOURCE it 'outputs a warning about the first missing function' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @!method tag for function 'func1' near \(stdin\):2}m).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @!method tag for function 'func1' near \(stdin\):2/m).to_stdout_from_any_process end it 'outputs a warning about the second missing function' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @!method tag for function 'func2' near \(stdin\):2}m).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @!method tag for function 'func2' near \(stdin\):2/m).to_stdout_from_any_process end it 'registers a data type object with all functions' do @@ -193,7 +193,7 @@ def suppress_yard_logging end describe 'parsing a data type definition with extra tags' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. # @param msg A message parameter. # @param arg1 Optional String parameter. Defaults to 'param'. @@ -213,11 +213,11 @@ def suppress_yard_logging SOURCE it 'outputs a warning about the extra attribute' do - expect { spec_subject }.to output(%r{\[warn\]: The @param tag for 'arg1' has no matching attribute near \(stdin\):7}m).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The @param tag for 'arg1' has no matching attribute near \(stdin\):7/m).to_stdout_from_any_process end it 'outputs a warning about the extra function' do - expect { spec_subject }.to output(%r{\[warn\]: The @!method tag for 'does_not_exist' has no matching function definition near \(stdin\):7}m).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The @!method tag for 'does_not_exist' has no matching function definition near \(stdin\):7/m).to_stdout_from_any_process end it 'registers a data type object with extra information removed' do @@ -255,7 +255,7 @@ def suppress_yard_logging describe 'parsing a valid data type definition' do # TODO: What about testing for `type_parameters => {}` # e.g. https://github.com/puppetlabs/puppet/blob/main/lib/puppet/datatypes/error.rb - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. # # @param msg A message parameter5. @@ -305,7 +305,7 @@ def suppress_yard_logging # Check for default values expect(object.parameters.size).to eq(2) expect(object.parameters[0]).to eq(['msg', nil]) - expect(object.parameters[1]).to eq(['arg1', 'param']) + expect(object.parameters[1]).to eq(%w[arg1 param]) # Check for functions expect(object.functions.size).to eq(1) @@ -325,7 +325,7 @@ def suppress_yard_logging end context 'with multiple interfaces' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. # # @param msg A message parameter5. @@ -389,7 +389,7 @@ def suppress_yard_logging end context 'with missing, partial and addition function parameters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. # # @!method func1(foo1, foo2) @@ -416,23 +416,23 @@ def suppress_yard_logging SOURCE it 'outputs a warning about the incorrect return type' do - expect { spec_subject }.to output(%r{\[warn\]: The @return tag for 'func1' has a different type definition .+ Expected \["Optional\[String\]"\]}m).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The @return tag for 'func1' has a different type definition .+ Expected \["Optional\[String\]"\]/m).to_stdout_from_any_process end it 'outputs a warning about the additional parameter' do - expect { spec_subject }.to output(%r{\[warn\]: The @param tag for 'extra' should not exist for function 'func1' that is defined near}m).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The @param tag for 'extra' should not exist for function 'func1' that is defined near/m).to_stdout_from_any_process end it 'outputs a warning about the wrong parameter type (func1)' do - expect { + expect do spec_subject - } .to output(%r{\[warn\]: The @param tag for 'foo1' for function 'func1' has a different type definition than the actual function near .+ Expected \["Integer"\]}m).to_stdout_from_any_process + end.to output(/\[warn\]: The @param tag for 'foo1' for function 'func1' has a different type definition than the actual function near .+ Expected \["Integer"\]/m).to_stdout_from_any_process end it 'outputs a warning about the wrong parameter type (func2)' do - expect { + expect do spec_subject - } .to output(%r{\[warn\]: The @param tag for 'param1' for function 'func2' has a different type definition than the actual function near .+ Expected \["Integer"\]}m).to_stdout_from_any_process + end.to output(/\[warn\]: The @param tag for 'param1' for function 'func2' has a different type definition than the actual function near .+ Expected \["Integer"\]/m).to_stdout_from_any_process end it 'automatically fixes function parameters, except for differring types' do @@ -480,7 +480,7 @@ def suppress_yard_logging { value: '0xFF', expected: 255 }, { value: '0.1', expected: 0.1 }, { value: '31.415e-1', expected: 3.1415 }, - { value: '0.31415e1', expected: 3.1415 }, + { value: '0.31415e1', expected: 3.1415 } ].each do |testcase| describe "parsing a valid data type definition with numeric default #{testcase[:value]}" do let(:source) { <<~SOURCE } @@ -506,7 +506,7 @@ def suppress_yard_logging end describe 'parsing an invalid data type definition' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # The msg attribute is missing a comma. # # @param msg A message parameter5. @@ -551,13 +551,13 @@ def suppress_yard_logging end it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Invalid datatype definition at (.+):[0-9]+: Syntax error at 'arg1'}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Invalid datatype definition at (.+):[0-9]+: Syntax error at 'arg1'/).to_stdout_from_any_process end end describe 'parsing a data type with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. # # @summary A short summary. @@ -577,7 +577,7 @@ def suppress_yard_logging end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example Puppet Data Type in Ruby. # # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!! @@ -589,7 +589,7 @@ def suppress_yard_logging SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_data_type 'RubyDataType' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_data_type 'RubyDataType' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 08ee26987..f08659c05 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 @@ -13,19 +13,19 @@ let(:source) { 'puts "hi"' } it 'no functions should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end describe 'parsing 3.x API functions' do describe 'parsing a function with a missing docstring' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Parser::Functions.newfunction(:foo) do |*args| end SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process end end @@ -39,7 +39,7 @@ # # Given that this occurs only in old-style functions, it’s probably not # worth pursuing. - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Parser::Functions.newfunction(:foo, doc: <<~'DOC' An example 3.x function. @param [String] first The first parameter. @@ -90,7 +90,7 @@ # # Given that this occurs only in old-style functions, it’s probably not # worth pursuing. - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } module Puppet::Parser::Functions newfunction(:foo, doc: <<~'DOC' An example 3.x function. @@ -134,7 +134,7 @@ module Puppet::Parser::Functions end describe 'parsing a function with a missing @return tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Parser::Functions.newfunction(:foo, doc: <<~'DOC') do |*args| An example 3.x function. @param [String] first The first parameter. @@ -145,25 +145,25 @@ module Puppet::Parser::Functions SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @return tag near \(stdin\):1}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):1/).to_stdout_from_any_process end end end describe 'parsing 4.x API functions' do describe 'parsing a function with a missing docstring' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Functions.create_function(:foo) do end SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a function with a simple docstring' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do end @@ -186,7 +186,7 @@ module Puppet::Parser::Functions end describe 'parsing a function without any dispatches' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param [Integer] param1 The first parameter. @@ -205,7 +205,7 @@ def foo(param1, param2, param3 = nil) expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X)) expect(object.name).to eq(:foo) expect(object.signature).to eq('foo(Integer $param1, Any $param2, Optional[String] $param3 = undef)') - expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'undef']]) + expect(object.parameters).to eq([['param1', nil], ['param2', nil], %w[param3 undef]]) expect(object.docstring).to eq('An example 4.x function.') expect(object.docstring.tags.size).to eq(5) tags = object.docstring.tags(:param) @@ -231,7 +231,7 @@ def foo(param1, param2, param3 = nil) end describe 'parsing a function with a single dispatch' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param param1 The first parameter. @@ -258,7 +258,7 @@ def foo(param1, param2, param3 = nil) expect(object.signature).to eq('foo(Integer $param1, Any $param2, Optional[Array[String]] $param3)') expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', nil]]) expect(object.docstring).to eq('An example 4.x function.') - expect(object.docstring.tags(:overload).empty?).to be_truthy + expect(object.docstring.tags(:overload)).to be_empty expect(object.docstring.tags.size).to eq(5) tags = object.docstring.tags(:param) expect(tags.size).to eq(3) @@ -283,7 +283,7 @@ def foo(param1, param2, param3 = nil) end describe 'parsing a function using only return_type' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param param1 The first parameter. @@ -315,7 +315,7 @@ def foo(param1, param2, param3 = nil) end describe 'parsing a function with various dispatch parameters.' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param param1 The first parameter. @@ -341,7 +341,7 @@ def foo(param1, param2, param3 = nil) expect(object.signature).to eq('foo(String $param1, Integer $param2, Optional[Array] $param3, String *$param4)') expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', nil], ['*param4', nil]]) expect(object.docstring).to eq('An example 4.x function.') - expect(object.docstring.tags(:overload).empty?).to be_truthy + expect(object.docstring.tags(:overload)).to be_empty expect(object.docstring.tags.size).to eq(6) tags = object.docstring.tags(:param) expect(tags.size).to eq(4) @@ -369,7 +369,7 @@ def foo(param1, param2, param3 = nil) end describe 'parsing a function with an optional repeated param.' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param param The first parameter. @@ -389,7 +389,7 @@ def foo(param1, param2, param3 = nil) expect(object.signature).to eq('foo(Optional[String] *$param)') expect(object.parameters).to eq([['*param', nil]]) expect(object.docstring).to eq('An example 4.x function.') - expect(object.docstring.tags(:overload).empty?).to be_truthy + expect(object.docstring.tags(:overload)).to be_empty expect(object.docstring.tags.size).to eq(3) tags = object.docstring.tags(:param) expect(tags.size).to eq(1) @@ -408,7 +408,7 @@ def foo(param1, param2, param3 = nil) end describe 'parsing a function with a block param with one parameter' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param a_block The block parameter. @@ -428,7 +428,7 @@ def foo(param1, param2, param3 = nil) expect(object.signature).to eq('foo(Callable &$a_block)') expect(object.parameters).to eq([['&a_block', nil]]) expect(object.docstring).to eq('An example 4.x function.') - expect(object.docstring.tags(:overload).empty?).to be_truthy + expect(object.docstring.tags(:overload)).to be_empty expect(object.docstring.tags.size).to eq(3) tags = object.docstring.tags(:param) expect(tags.size).to eq(1) @@ -447,7 +447,7 @@ def foo(param1, param2, param3 = nil) end describe 'parsing a function with a block param with two parameter' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param a_block The block parameter. @@ -467,7 +467,7 @@ def foo(param1, param2, param3 = nil) expect(object.signature).to eq('foo(Optional[Callable[String]] &$a_block)') expect(object.parameters).to eq([['&a_block', nil]]) expect(object.docstring).to eq('An example 4.x function.') - expect(object.docstring.tags(:overload).empty?).to be_truthy + expect(object.docstring.tags(:overload)).to be_empty expect(object.docstring.tags.size).to eq(3) tags = object.docstring.tags(:param) expect(tags.size).to eq(1) @@ -487,7 +487,7 @@ def foo(param1, param2, param3 = nil) end describe 'parsing a function with a multiple dispatches' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # The first overload. @@ -528,8 +528,8 @@ def other(b) expect(object.signature).to eq('') expect(object.parameters).to eq([]) expect(object.docstring).to eq('An example 4.x function.') - expect(object.docstring.tags(:param).empty?).to be_truthy - expect(object.docstring.tags(:return).empty?).to be_truthy + expect(object.docstring.tags(:param)).to be_empty + expect(object.docstring.tags(:return)).to be_empty expect(object.docstring.tags.size).to eq(3) overloads = object.docstring.tags(:overload) expect(overloads.size).to eq(2) @@ -577,7 +577,7 @@ def other(b) end describe 'parsing a function with a namespaced name' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:'foo::bar::baz') do # @return [Undef] @@ -593,7 +593,7 @@ def other(b) end describe 'parsing a function with a missing parameter' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param missing A missing parameter. @@ -604,12 +604,12 @@ def other(b) SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The @param tag for parameter 'missing' has no matching parameter at \(stdin\):5}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The @param tag for parameter 'missing' has no matching parameter at \(stdin\):5/).to_stdout_from_any_process end end describe 'parsing a function with a missing @param tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @return [Undef] Returns nothing. @@ -620,12 +620,12 @@ def other(b) SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @param tag for parameter 'param1' near \(stdin\):5}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @param tag for parameter 'param1' near \(stdin\):5/).to_stdout_from_any_process end end describe 'parsing a function with a typed @param tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param [Integer] param1 The first parameter. @@ -639,14 +639,14 @@ def other(b) it 'outputs a warning' do expect { spec_subject } .to output( - %r{\[warn\]: The @param tag for parameter 'param1' should not contain a type specification near \(stdin\):6: ignoring in favor of dispatch type information\.}, + /\[warn\]: The @param tag for parameter 'param1' should not contain a type specification near \(stdin\):6: ignoring in favor of dispatch type information\./ ) .to_stdout_from_any_process end end describe 'parsing a function with a typed @param tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. Puppet::Functions.create_function(:foo) do # @param param1 The first parameter. @@ -657,12 +657,12 @@ def other(b) SOURCE it 'outputs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing @return tag near \(stdin\):4}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):4/).to_stdout_from_any_process end end describe 'parsing a function with a root @param tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. # @param param Nope. Puppet::Functions.create_function(:foo) do @@ -675,14 +675,14 @@ def other(b) it 'outputs a warning' do expect { spec_subject } .to output( - %r{\[warn\]: The docstring for Puppet 4.x function 'foo' contains @param tags near \(stdin\):3: parameter documentation should be made on the dispatch call\.}, + /\[warn\]: The docstring for Puppet 4.x function 'foo' contains @param tags near \(stdin\):3: parameter documentation should be made on the dispatch call\./ ) .to_stdout_from_any_process end end describe 'parsing a function with a root @overload tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. # @overload foo Puppet::Functions.create_function(:foo) do @@ -695,14 +695,14 @@ def other(b) it 'outputs a warning' do expect { spec_subject } .to output( - %r{\[warn\]: The docstring for Puppet 4.x function 'foo' contains @overload tags near \(stdin\):3: overload tags are automatically generated from the dispatch calls\.}, + /\[warn\]: The docstring for Puppet 4.x function 'foo' contains @overload tags near \(stdin\):3: overload tags are automatically generated from the dispatch calls\./ ) .to_stdout_from_any_process end end describe 'parsing a function with a root @return tag' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. # @return [Undef] foo Puppet::Functions.create_function(:foo) do @@ -715,7 +715,7 @@ def other(b) it 'outputs a warning' do expect { spec_subject } .to output( - %r{\[warn\]: The docstring for Puppet 4.x function 'foo' contains @return tags near \(stdin\):3: return value documentation should be made on the dispatch call\.}, + /\[warn\]: The docstring for Puppet 4.x function 'foo' contains @return tags near \(stdin\):3: return value documentation should be made on the dispatch call\./ ) .to_stdout_from_any_process end @@ -723,7 +723,7 @@ def other(b) describe 'parsing a function with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. # @summary A short summary. Puppet::Functions.create_function(:foo) do @@ -742,7 +742,7 @@ def other(b) end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # An example 4.x function. # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!! Puppet::Functions.create_function(:foo) do @@ -753,7 +753,7 @@ def other(b) SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_function 'foo' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_function 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 90dfc189b..01470dd97 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 @@ -13,35 +13,35 @@ let(:source) { 'puts "hi"' } it 'no providers should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end describe 'parsing a provider with a missing description' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.type(:custom).provide :linux do end SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing a description for Puppet provider 'linux' \(resource type 'custom'\) at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing a description for Puppet provider 'linux' \(resource type 'custom'\) at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a provider with an invalid docstring assignment' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.type(:custom).provide :linux do @doc = 123 end SOURCE it 'logs an error' do - expect { spec_subject }.to output(%r{Failed to parse docstring}).to_stdout_from_any_process + expect { spec_subject }.to output(/Failed to parse docstring/).to_stdout_from_any_process end end describe 'parsing a provider with a valid docstring assignment' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.type(:custom).provide :linux do @doc = 'An example provider on Linux.' end @@ -71,7 +71,7 @@ end describe 'parsing a provider definition' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.type(:custom).provide :linux do desc 'An example provider on Linux.' confine kernel: 'Linux' @@ -97,14 +97,14 @@ expect(tags.size).to eq(1) expect(tags[0].text).to eq('public') expect(object.confines).to eq({ 'kernel' => 'Linux', 'osfamily' => 'RedHat' }) - expect(object.defaults).to eq([[['kernel', 'Linux']], [['osfamily', 'RedHat'], ['operatingsystemmajrelease', '7']]]) - expect(object.features).to eq(['implements_some_feature', 'some_other_feature']) + expect(object.defaults).to eq([[%w[kernel Linux]], [%w[osfamily RedHat], %w[operatingsystemmajrelease 7]]]) + expect(object.features).to eq(%w[implements_some_feature some_other_feature]) expect(object.commands).to eq({ 'foo' => '/usr/bin/foo' }) end end describe 'parsing a provider definition with a string based name' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.type(:'custom').provide :'linux' do desc 'An example provider on Linux.' end @@ -123,7 +123,7 @@ describe 'parsing a provider with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.type(:custom).provide :linux do @doc = '@summary A short summary.' end @@ -138,14 +138,14 @@ end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.type(:custom).provide :linux do @doc = '@summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!' end SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_provider 'linux' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_provider 'linux' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 e1c841ce8..3a14fa4d8 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 @@ -13,24 +13,24 @@ let(:source) { 'puts "hi"' } it 'no types should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end describe 'parsing a type with a missing description' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::ResourceApi.register_type( name: 'database' ) SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing a description for Puppet resource type 'database' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing a description for Puppet resource type 'database' at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a type with a valid docstring assignment' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::ResourceApi.register_type( name: 'database', docs: 'An example database server resource type.', @@ -63,7 +63,7 @@ end describe 'parsing a type definition' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # @!puppet.type.param [value1, value2] dynamic_param Documentation for a dynamic parameter. # @!puppet.type.property [foo, bar] dynamic_prop Documentation for a dynamic property. Puppet::ResourceApi.register_type( @@ -122,56 +122,56 @@ tags = object.docstring.tags(:api) expect(tags.size).to eq(1) expect(tags[0].text).to eq('public') - expect(object.properties.map(&:name)).to eq(['dynamic_prop', 'ensure', 'file', 'log_level']) + expect(object.properties.map(&:name)).to eq(%w[dynamic_prop ensure file log_level]) expect(object.properties.size).to eq(4) expect(object.properties[0].name).to eq('dynamic_prop') expect(object.properties[0].docstring).to eq('Documentation for a dynamic property.') - expect(object.properties[0].isnamevar).to eq(false) - expect(object.properties[0].values).to eq(['foo', 'bar']) + expect(object.properties[0].isnamevar).to be(false) + expect(object.properties[0].values).to eq(%w[foo bar]) expect(object.properties[1].name).to eq('ensure') expect(object.properties[1].docstring).to eq('What state the database should be in.') - expect(object.properties[1].isnamevar).to eq(false) + expect(object.properties[1].isnamevar).to be(false) expect(object.properties[1].default).to eq('up') expect(object.properties[1].data_type).to eq('Enum[present, absent, up, down]') expect(object.properties[1].aliases).to eq({}) expect(object.properties[2].name).to eq('file') expect(object.properties[2].docstring).to eq('The database file to use.') - expect(object.properties[2].isnamevar).to eq(false) + expect(object.properties[2].isnamevar).to be(false) expect(object.properties[2].default).to be_nil expect(object.properties[2].data_type).to eq('String') expect(object.properties[2].aliases).to eq({}) expect(object.properties[3].name).to eq('log_level') expect(object.properties[3].docstring).to eq('The log level to use.') - expect(object.properties[3].isnamevar).to eq(false) + expect(object.properties[3].isnamevar).to be(false) expect(object.properties[3].default).to eq('warn') expect(object.properties[3].data_type).to eq('Enum[debug, warn, error]') expect(object.properties[3].aliases).to eq({}) expect(object.parameters.size).to eq(5) expect(object.parameters[0].name).to eq('dynamic_param') expect(object.parameters[0].docstring).to eq('Documentation for a dynamic parameter.') - expect(object.parameters[0].isnamevar).to eq(false) - expect(object.parameters[0].values).to eq(['value1', 'value2']) + expect(object.parameters[0].isnamevar).to be(false) + expect(object.parameters[0].values).to eq(%w[value1 value2]) expect(object.parameters[1].name).to eq('address') expect(object.parameters[1].docstring).to eq('The database server name.') - expect(object.parameters[1].isnamevar).to eq(true) + expect(object.parameters[1].isnamevar).to be(true) expect(object.parameters[1].default).to be_nil expect(object.parameters[1].data_type).to eq('String') expect(object.parameters[1].aliases).to eq({}) expect(object.parameters[2].name).to eq('encrypt') expect(object.parameters[2].docstring).to eq('Whether or not to encrypt the database.') - expect(object.parameters[2].isnamevar).to eq(false) - expect(object.parameters[2].default).to eq(false) + expect(object.parameters[2].isnamevar).to be(false) + expect(object.parameters[2].default).to be(false) expect(object.parameters[2].data_type).to eq('Boolean') expect(object.parameters[2].aliases).to eq({}) expect(object.parameters[3].name).to eq('encryption_key') expect(object.parameters[3].docstring).to eq('The encryption key to use.') - expect(object.parameters[3].isnamevar).to eq(false) + expect(object.parameters[3].isnamevar).to be(false) expect(object.parameters[3].default).to be_nil expect(object.parameters[3].data_type).to eq('Optional[String]') expect(object.parameters[3].aliases).to eq({}) expect(object.parameters[4].name).to eq('backup') expect(object.parameters[4].docstring).to eq('How often to backup the database.') - expect(object.parameters[4].isnamevar).to eq(false) + expect(object.parameters[4].isnamevar).to be(false) expect(object.parameters[4].default).to eq('never') expect(object.parameters[4].data_type).to eq('Enum[daily, monthly, never]') end @@ -179,7 +179,7 @@ describe 'parsing a type with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::ResourceApi.register_type( name: 'database', docs: '@summary A short summary.', @@ -195,7 +195,7 @@ end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::ResourceApi.register_type( name: 'database', docs: '@summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!', @@ -203,13 +203,13 @@ SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_type 'database' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_type 'database' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end describe 'parsing a type with title_patterns' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::ResourceApi.register_type( name: 'database', docs: 'An example database server resource type.', @@ -223,7 +223,7 @@ SOURCE it 'does not emit a warning' do - expect { spec_subject }.not_to output(%r{\[warn\].*unexpected construct regexp_literal}).to_stdout_from_any_process + expect { spec_subject }.not_to output(/\[warn\].*unexpected construct regexp_literal/).to_stdout_from_any_process end end end diff --git a/spec/unit/puppet-strings/yard/handlers/ruby/type_extras_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/ruby/type_extras_handler_spec.rb index a79239edc..00a15f080 100644 --- a/spec/unit/puppet-strings/yard/handlers/ruby/type_extras_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/ruby/type_extras_handler_spec.rb @@ -10,7 +10,7 @@ end describe 'parsing source with newproperty' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do desc 'database' end @@ -29,7 +29,7 @@ end describe 'parsing source with newparam' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do desc 'database' end @@ -44,12 +44,12 @@ expect(object.parameters.size).to eq(1) expect(object.parameters[0].name).to eq('name') expect(object.parameters[0].docstring).to eq('The database server name.') - expect(object.parameters[0].isnamevar).to eq(true) + expect(object.parameters[0].isnamevar).to be(true) end end describe 'parsing source with ensurable' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do desc 'database' end 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 db0e402a2..8e226a0cd 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 @@ -13,35 +13,35 @@ let(:source) { 'puts "hi"' } it 'no types should be in the registry' do - expect(spec_subject.empty?).to eq(true) + expect(spec_subject.empty?).to be(true) end end describe 'parsing a type with a missing description' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do end SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: Missing a description for Puppet resource type 'database' at \(stdin\):1\.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: Missing a description for Puppet resource type 'database' at \(stdin\):1\./).to_stdout_from_any_process end end describe 'parsing a type with an invalid docstring assignment' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do @doc = 123 end SOURCE it 'logs an error' do - expect { spec_subject }.to output(%r{Failed to parse docstring}).to_stdout_from_any_process + expect { spec_subject }.to output(/Failed to parse docstring/).to_stdout_from_any_process end end describe 'parsing a type with a valid docstring assignment' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do @doc = 'An example database server resource type.' end @@ -71,7 +71,7 @@ end describe 'parsing a type with a param with arguments' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do feature :encryption, 'The provider supports encryption.', methods: [:encrypt] @@ -96,7 +96,7 @@ end describe 'parsing a type definition' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # @!puppet.type.param [value1, value2] dynamic_param Documentation for a dynamic parameter. # @!puppet.type.property [foo, bar] dynamic_prop Documentation for a dynamic property. Puppet::Type.newtype(:database) do @@ -163,54 +163,54 @@ expect(object.properties.size).to eq(4) expect(object.properties[0].name).to eq('dynamic_prop') expect(object.properties[0].docstring).to eq('Documentation for a dynamic property.') - expect(object.properties[0].isnamevar).to eq(false) - expect(object.properties[0].values).to eq(['foo', 'bar']) + expect(object.properties[0].isnamevar).to be(false) + expect(object.properties[0].values).to eq(%w[foo bar]) expect(object.properties[1].name).to eq('ensure') expect(object.properties[1].docstring).to eq('What state the database should be in.') - expect(object.properties[1].isnamevar).to eq(false) + expect(object.properties[1].isnamevar).to be(false) expect(object.properties[1].default).to eq('up') - expect(object.properties[1].values).to eq(['present', 'absent', 'up', 'down']) + expect(object.properties[1].values).to eq(%w[present absent up down]) expect(object.properties[1].aliases).to eq({ 'down' => 'absent', 'up' => 'present' }) expect(object.properties[2].name).to eq('file') expect(object.properties[2].docstring).to eq('The database file to use.') - expect(object.properties[2].isnamevar).to eq(false) + expect(object.properties[2].isnamevar).to be(false) expect(object.properties[2].default).to be_nil expect(object.properties[2].values).to eq([]) expect(object.properties[2].aliases).to eq({}) expect(object.properties[3].name).to eq('log_level') expect(object.properties[3].docstring).to eq('The log level to use.') - expect(object.properties[3].isnamevar).to eq(false) + expect(object.properties[3].isnamevar).to be(false) expect(object.properties[3].default).to eq('warn') - expect(object.properties[3].values).to eq(['debug', 'warn', 'error']) + expect(object.properties[3].values).to eq(%w[debug warn error]) expect(object.properties[3].aliases).to eq({}) expect(object.parameters.size).to eq(5) expect(object.parameters[0].name).to eq('dynamic_param') expect(object.parameters[0].docstring).to eq('Documentation for a dynamic parameter.') - expect(object.parameters[0].isnamevar).to eq(false) - expect(object.parameters[0].values).to eq(['value1', 'value2']) + expect(object.parameters[0].isnamevar).to be(false) + expect(object.parameters[0].values).to eq(%w[value1 value2]) expect(object.parameters[1].name).to eq('address') expect(object.parameters[1].docstring).to eq('The database server name.') - expect(object.parameters[1].isnamevar).to eq(true) + expect(object.parameters[1].isnamevar).to be(true) expect(object.parameters[1].default).to be_nil expect(object.parameters[1].values).to eq([]) expect(object.parameters[1].aliases).to eq({}) expect(object.parameters[2].name).to eq('encryption_key') expect(object.parameters[2].docstring).to eq('The encryption key to use.') - expect(object.parameters[2].isnamevar).to eq(false) + expect(object.parameters[2].isnamevar).to be(false) expect(object.parameters[2].default).to be_nil expect(object.parameters[2].values).to eq([]) expect(object.parameters[2].aliases).to eq({}) expect(object.parameters[3].name).to eq('encrypt') expect(object.parameters[3].docstring).to eq('Whether or not to encrypt the database.') - expect(object.parameters[3].isnamevar).to eq(false) + expect(object.parameters[3].isnamevar).to be(false) expect(object.parameters[3].default).to eq('false') - expect(object.parameters[3].values).to eq(['true', 'false', 'yes', 'no']) + expect(object.parameters[3].values).to eq(%w[true false yes no]) expect(object.parameters[3].aliases).to eq({}) expect(object.parameters[4].name).to eq('backup') expect(object.parameters[4].docstring).to eq('How often to backup the database.') - expect(object.parameters[4].isnamevar).to eq(false) + expect(object.parameters[4].isnamevar).to be(false) expect(object.parameters[4].default).to eq('never') - expect(object.parameters[4].values).to eq(['daily', 'monthly', 'never']) + expect(object.parameters[4].values).to eq(%w[daily monthly never]) expect(object.features.size).to eq(2) expect(object.features[0].name).to eq('encryption') expect(object.features[0].docstring).to eq('The provider supports encryption.') @@ -220,7 +220,7 @@ end describe 'parsing a valid type with string based name' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:'database') do desc 'An example database server resource type.' ensurable @@ -235,7 +235,7 @@ end describe 'parsing an ensurable type with default ensure values' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do desc 'An example database server resource type.' ensurable @@ -248,12 +248,12 @@ expect(object.properties[0].name).to eq('ensure') expect(object.properties[0].docstring).to eq('The basic property that the resource should be in.') expect(object.properties[0].default).to eq('present') - expect(object.properties[0].values).to eq(['present', 'absent']) + expect(object.properties[0].values).to eq(%w[present absent]) end end describe 'parsing a type with a parameter with the name of "name"' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do desc 'An example database server resource type.' newparam(:name) do @@ -267,12 +267,12 @@ object = spec_subject.first expect(object.parameters.size).to eq(1) expect(object.parameters[0].name).to eq('name') - expect(object.parameters[0].isnamevar).to eq(true) + expect(object.parameters[0].isnamevar).to be(true) end end describe 'parsing a type with a check with the name of "onlyif"' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:testexec) do desc 'An example exec type with a check.' newcheck(:onlyif) do @@ -291,7 +291,7 @@ describe 'parsing a type with a summary' do context 'when the summary has fewer than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do @doc = '@summary A short summary.' end @@ -306,14 +306,14 @@ end context 'when the summary has more than 140 characters' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } Puppet::Type.newtype(:database) do @doc = '@summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!' end SOURCE it 'logs a warning' do - expect { spec_subject }.to output(%r{\[warn\]: The length of the summary for puppet_type 'database' exceeds the recommended limit of 140 characters.}).to_stdout_from_any_process + expect { spec_subject }.to output(/\[warn\]: The length of the summary for puppet_type 'database' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process end end end 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 264eab6d7..7dc1f0d49 100644 --- a/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +++ b/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb @@ -22,22 +22,22 @@ it 'has no relevant statements' do spec_subject.parse - expect(spec_subject.enumerator.empty?).to be_truthy + expect(spec_subject.enumerator).to be_empty end end describe 'parsing invalid JSON' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } class foo { SOURCE it 'raises an exception' do - expect { spec_subject.parse }.to output(%r{\[error\]: Failed to parse test.json}).to_stdout_from_any_process + expect { spec_subject.parse }.to output(/\[error\]: Failed to parse test.json/).to_stdout_from_any_process end end describe 'parsing valid task metadata JSON' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "description": "Allows you to backup your database to local file.", "input_method": "stdin", 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 54d592313..4bc831123 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 @@ -5,7 +5,7 @@ describe PuppetStrings::Yard::Parsers::JSON::TaskStatement do subject(:spec_subject) { described_class.new(json, source, 'test.json') } - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "description": "Allows you to backup your database to local file.", "input_method": "stdin", @@ -36,14 +36,16 @@ expect(spec_subject.comments).to eq 'Allows you to backup your database to local file.' end end + describe '#parameters' do context 'with params' do it 'returns params' do expect(!spec_subject.parameters.empty?).to be true end end + context 'no params' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } { "description": "Allows you to backup your database to local file.", "input_method": "stdin" 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 108b767b1..deb0dc77b 100644 --- a/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +++ b/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb @@ -21,22 +21,22 @@ it 'has no relevant statements' do spec_subject.parse - expect(spec_subject.enumerator.empty?).to be_truthy + expect(spec_subject.enumerator).to be_empty end end describe 'parsing invalid Puppet source code' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } class foo { SOURCE it 'raises an exception' do - expect { spec_subject.parse }.to output(%r{\[error\]: Failed to parse test.pp: Syntax error at end of (file|input)}).to_stdout_from_any_process + expect { spec_subject.parse }.to output(/\[error\]: Failed to parse test.pp: Syntax error at end of (file|input)/).to_stdout_from_any_process end end describe 'parsing class definitions' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } notice hello # A simple foo class. # @param param1 First param. @@ -74,7 +74,7 @@ class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar { end describe 'parsing nested class definitions' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } class foo { class bar { } @@ -96,7 +96,7 @@ class bar { end describe 'parsing defined types' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } notice hello # A simple foo defined type. # @param param1 First param. @@ -136,7 +136,7 @@ class bar { # The parsing code actually checks this and sets a global (Puppet[:tasks]). # Plan parsing will fail if it hasn't yet encountered a file under plans/. let(:file) { 'plans/test.pp' } - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple plan. # @param param1 First param. # @param param2 Second param. @@ -151,7 +151,7 @@ class bar { statement = spec_subject.enumerator.first expect(statement).to be_a(PuppetStrings::Yard::Parsers::Puppet::PlanStatement) expect(statement.name).to eq('plann') - expect(statement.source).to eq(source.sub(%r{\A.*?\n([^#])}m, '\1').chomp) + expect(statement.source).to eq(source.sub(/\A.*?\n([^#])/m, '\1').chomp) expect(statement.file).to eq(file) expect(statement.line).to eq(5) expect(statement.docstring).to eq('A simple plan.') @@ -169,7 +169,7 @@ class bar { end describe 'parsing puppet functions', if: TEST_PUPPET_FUNCTIONS do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } notice hello # A simple foo function. # @param param1 First param. @@ -204,7 +204,7 @@ class bar { end describe 'parsing puppet functions with return type in defintion', if: TEST_FUNCTION_RETURN_TYPE do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @return Returns a string function foo() >> String { @@ -222,7 +222,7 @@ class bar { end describe 'parsing puppet functions with complex return types in defintion', if: TEST_FUNCTION_RETURN_TYPE do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo function. # @return Returns a struct with a hash including one key which must be an integer between 1 and 10. function foo() >> Struct[{'a' => Integer[1, 10]}] { @@ -235,13 +235,13 @@ class bar { expect(spec_subject.enumerator.size).to eq(1) statement = spec_subject.enumerator.first expect(statement).to be_a(PuppetStrings::Yard::Parsers::Puppet::FunctionStatement) - expect(statement.type).to eq("Struct\[{'a' => Integer[1, 10]}\]") + expect(statement.type).to eq("Struct[{'a' => Integer[1, 10]}]") end end describe 'parsing type alias definitions', if: TEST_PUPPET_DATATYPES do context 'given a type alias on a single line' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A simple foo type. type Module::Typename = Variant[Stdlib::Windowspath, Stdlib::Unixpath] SOURCE @@ -258,7 +258,7 @@ class bar { end context 'given a type alias over multiple lines' do - let(:source) { <<~'SOURCE' } + let(:source) { <<~SOURCE } # A multiline foo type # with long docs type OptionsWithoutName = Struct[{ @@ -295,7 +295,7 @@ class bar { '1 + 1', 'func()', '$param1.foo(1)', - '$param1.foo($param2 + $param3.bar())', + '$param1.foo($param2 + $param3.bar())' ].each do |value| describe "parsing parameter with #{value} default value" do let(:source) { <<~PUPPET } @@ -319,7 +319,7 @@ class foo ( 'Linux' => 'linux', 'Darwin' => 'darwin', default => $facts['kernel'], - }", + }" ].each do |value| describe "parsing parameter with #{value} default value" do let(:source) { <<~PUPPET } diff --git a/spec/unit/puppet-strings/yard/util_spec.rb b/spec/unit/puppet-strings/yard/util_spec.rb index 3c3673b10..1a89f79e9 100644 --- a/spec/unit/puppet-strings/yard/util_spec.rb +++ b/spec/unit/puppet-strings/yard/util_spec.rb @@ -18,7 +18,7 @@ end it 'does not affect newlines when %Q notation is used' do - str = <<~'STR' + str = <<~STR %Q{this is a test string} STR