diff -Nru puppet-lint-3.0.1/.rubocop.yml puppet-lint-4.2.4/.rubocop.yml --- puppet-lint-3.0.1/.rubocop.yml 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/.rubocop.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,522 +0,0 @@ ---- -require: -- rubocop-performance -- rubocop-rspec -AllCops: - DisplayCopNames: true - TargetRubyVersion: '2.6' - SuggestExtensions: false - Include: - - "**/*.rb" - Exclude: - - bin/* - - ".vendor/**/*" - - "**/Gemfile" - - "**/Rakefile" - - pkg/**/* - - spec/fixtures/**/* - - vendor/**/* - - "**/Puppetfile" - - "**/Vagrantfile" - - "**/Guardfile" -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 -RSpec/DescribeSymbol: - Exclude: - - spec/unit/facter/**/*.rb -Style/BlockDelimiters: - Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to - be consistent then. - EnforcedStyle: braces_for_chaining -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: - - lib/puppet/parser/functions/**/* - - 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: false -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: false -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/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 -RSpec/FilePath: - Enabled: false diff -Nru puppet-lint-3.0.1/README.md puppet-lint-4.2.4/README.md --- puppet-lint-3.0.1/README.md 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/README.md 2024-02-12 13:18:23.000000000 +0000 @@ -1,15 +1,15 @@ # Puppet Lint -[![Build -Status](https://secure.travis-ci.org/rodjek/puppet-lint.png)](http://travis-ci.org/rodjek/puppet-lint) -[![Inline docs](http://inch-ci.org/github/rodjek/puppet-lint.png?branch=master)](http://inch-ci.org/github/rodjek/puppet-lint) +[![Code Owners](https://img.shields.io/badge/owners-DevX--team-blue)](https://github.com/puppetlabs/puppet-lint/blob/main/CODEOWNERS) +![ci](https://github.com/puppetlabs/puppet-lint/actions/workflows/ci.yml/badge.svg) +![GitHub release (latest by date)](https://img.shields.io/github/v/release/puppetlabs/puppet-lint) Puppet Lint tests Puppet code against the recommended [Puppet language style guide](http://puppet.com/docs/puppet/latest/style_guide.html). Puppet Lint validates only code style; it does not validate syntax. To test syntax, use Puppet's `puppet parser validate` command. ## Compatibility warning -Puppet Lint version 2 is the last planned version with support for Puppet 3 and Ruby 1.8.7. The next major version of Puppet Lint will drop support for these versions. +This tool is only supported on Puppet 7 & 8 environments. In cases where Puppet Lint is required in an environment with Puppet 6, we recommend pinning to version 2.5.2. ## Installation @@ -114,7 +114,7 @@ --no-hard_tabs-check ``` -Or to specify a whitelist of allowed checks, include a line like: +Or to specify an allowlist of allowed checks, include a line like: ``` --only-checks=trailing_whitespace,hard_tabs,duplicate_params,double_quoted_strings,unquoted_file_mode,only_variable_string,variables_not_enclosed,single_quote_string_with_variables,variable_contains_dash,ensure_not_symlink_target,unquoted_resource_title,relative_classname_inclusion,file_mode,resource_reference_without_title_capital,leading_zero,arrow_alignment,variable_is_lowercase,ensure_first_param,resource_reference_without_whitespace,file_ensure,trailing_comma,leading_zero @@ -213,6 +213,30 @@ * [puppet-lint-action](https://github.com/marketplace/actions/puppet-lint-action) +## Integration with GitLab Code Quality + +[GitLab](https://gitlab.com/) users can use the `--codeclimate-report-file` configuration option to generate a report for use with the +[Code Quality](https://docs.gitlab.com/ee/ci/testing/code_quality.html) feature. + +The easiest way to set this option, (and without having to modify rake tasks), is with the `CODECLIMATE_REPORT_FILE` environment variable. + +For example, the following GitLab job sets the environment variable and +[archives the report](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportscodequality) produced. +```yaml +validate lint check rubocop-Ruby 2.7.2-Puppet ~> 7: + stage: syntax + image: ruby:2.7.2 + script: + - bundle exec rake validate lint check rubocop + variables: + PUPPET_GEM_VERSION: '~> 7' + CODECLIMATE_REPORT_FILE: 'gl-code-quality-report.json' + artifacts: + reports: + codequality: gl-code-quality-report.json + expire_in: 1 week +``` + ## Options See `puppet-lint --help` for a full list of command line options and checks. @@ -268,9 +292,21 @@ ## Reporting bugs or incorrect results If you find a bug in Puppet Lint or its results, please create an issue in the -[repo issues tracker](https://github.com/rodjek/puppet-lint/issues/). Bonus +[repo issues tracker](https://github.com/puppetlabs/puppet-lint/issues/). Bonus points will be awarded if you also include a patch that fixes the issue. +## Development + +Acceptance tests for this tool leverage [puppet_litmus](https://github.com/puppetlabs/puppet_litmus). +To run the acceptance tests follow the instructions [here](https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)#install-the-necessary-gems-for-the-module). +You can also find a tutorial and walkthrough of using Litmus and the PDK on [YouTube](https://www.youtube.com/watch?v=FYfR7ZEGHoE). + +If you run into an issue with this tool or would like to request a feature you can [raise a PR](https://github.com/puppetlabs/puppet-lint/pulls) with your suggested changes. Alternatively, you can [raise a Github issue](https://github.com/puppetlabs/puppet-lint/issues) with a feature request or to report any bugs. +Every other Tuesday the DevX team holds [office hours](https://puppet.com/community/office-hours) in the [Puppet Community Slack](http://slack.puppet.com/), where you can ask questions about this and any other supported tools. +This session runs at 15:00 (GMT) for about an hour. + +If you have problems getting this tool up and running, please [contact Support](http://puppetlabs.com/services/customer-support). + ## Thank you Many thanks to the following people for contributing to puppet-lint diff -Nru puppet-lint-3.0.1/debian/changelog puppet-lint-4.2.4/debian/changelog --- puppet-lint-3.0.1/debian/changelog 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/changelog 2024-02-22 05:30:18.000000000 +0000 @@ -1,3 +1,26 @@ +puppet-lint (4.2.4-2) unstable; urgency=medium + + * Team upload. + * generate manpage using help2man + * d/control: streamline build-deps + * d/control: drop obsolete XB-Ruby-Versions field + * d/copyright: set field Upstream-Contact + * d/upstream: remove obsolete fields Contact, Name + * update upstream github namespace to puppetlabs + * drop obsolete d/clean + + -- Jérôme Charaoui Thu, 22 Feb 2024 00:30:18 -0500 + +puppet-lint (4.2.4-1) unstable; urgency=medium + + * Team upload. + * New upstream version 4.2.4 + * d/patches: remove obsolete test patch + * d/control: bump Standards-Version, no changes needed + * d/control: drop deprecated XS-Ruby-Versions field + + -- Jérôme Charaoui Mon, 12 Feb 2024 08:31:40 -0500 + puppet-lint (3.0.1-1) unstable; urgency=medium * New upstream version 3.0.1. diff -Nru puppet-lint-3.0.1/debian/clean puppet-lint-4.2.4/debian/clean --- puppet-lint-3.0.1/debian/clean 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/clean 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -coverage/ diff -Nru puppet-lint-3.0.1/debian/control puppet-lint-4.2.4/debian/control --- puppet-lint-3.0.1/debian/control 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/control 2024-02-22 05:30:18.000000000 +0000 @@ -2,32 +2,32 @@ Section: admin Priority: optional Maintainer: Puppet Package Maintainers -Uploaders: Stig Sandbeck Mathisen , - Apollon Oikonomopoulos , - Sebastien Badia , - Georg Faerber , -Build-Depends: debhelper-compat (= 13), - gem2deb, - ruby-rspec-collection-matchers, - ruby-rspec-its, - ruby-simplecov, - ruby-rspec, - sharness, -Standards-Version: 4.6.1 +Uploaders: + Stig Sandbeck Mathisen , + Apollon Oikonomopoulos , + Sebastien Badia , + Georg Faerber , +Build-Depends: + debhelper-compat (= 13), + gem2deb, + help2man , + ruby-rspec-its, + ruby-rspec-mocks, +Standards-Version: 4.6.2 Vcs-Git: https://salsa.debian.org/puppet-team/puppet-lint.git Vcs-Browser: https://salsa.debian.org/puppet-team/puppet-lint Homepage: https://github.com/puppetlabs/puppet-lint -XS-Ruby-Versions: all Testsuite: autopkgtest-pkg-ruby Rules-Requires-Root: no Package: puppet-lint Architecture: all -XB-Ruby-Versions: ${ruby:Versions} -Depends: ruby:any, - ${misc:Depends}, - ${shlibs:Depends}, -Suggests: rake, +Depends: + ruby:any, + ${misc:Depends}, + ${shlibs:Depends}, +Suggests: + rake, Description: check puppet manifests for style guide conformity Checks your Puppet manifests against the Puppet Labs style guide and alerts you to any discrepancies. diff -Nru puppet-lint-3.0.1/debian/copyright puppet-lint-4.2.4/debian/copyright --- puppet-lint-3.0.1/debian/copyright 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/copyright 2024-02-22 05:30:18.000000000 +0000 @@ -1,6 +1,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: puppet-lint -Source: https://github.com/rodjek/puppet-lint +Source: https://github.com/puppetlabs/puppet-lint +Upstream-Contact: https://github.com/puppetlabs/puppet-lint/issues Files: * Copyright: 2011-2016 Tim Sharpe diff -Nru puppet-lint-3.0.1/debian/patches/0001-skip-failing-specs.patch puppet-lint-4.2.4/debian/patches/0001-skip-failing-specs.patch --- puppet-lint-3.0.1/debian/patches/0001-skip-failing-specs.patch 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/patches/0001-skip-failing-specs.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -Index: puppet-lint/spec/unit/puppet-lint/bin_spec.rb -=================================================================== ---- puppet-lint.orig/spec/unit/puppet-lint/bin_spec.rb 2022-10-23 14:31:35.035635012 +0000 -+++ puppet-lint/spec/unit/puppet-lint/bin_spec.rb 2022-10-23 16:48:56.115555401 +0000 -@@ -375,6 +375,7 @@ - - its(:exitstatus) { is_expected.to eq(0) } - its(:stdout) do -+ skip - if respond_to?(:include_json) - is_expected.to include_json([[{ 'KIND' => 'WARNING' }]]) - else -@@ -394,6 +395,7 @@ - - its(:exitstatus) { is_expected.to eq(1) } - its(:stdout) do -+ skip - if respond_to?(:include_json) - is_expected.to include_json([[{ 'KIND' => 'ERROR' }], [{ 'KIND' => 'WARNING' }]]) - else diff -Nru puppet-lint-3.0.1/debian/patches/series puppet-lint-4.2.4/debian/patches/series --- puppet-lint-3.0.1/debian/patches/series 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -0001-skip-failing-specs.patch diff -Nru puppet-lint-3.0.1/debian/puppet-lint.1 puppet-lint-4.2.4/debian/puppet-lint.1 --- puppet-lint-3.0.1/debian/puppet-lint.1 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/puppet-lint.1 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -.TH PUPPET-LINT "1" "September 2011" "puppet-lint 0.1.4" "User Commands" -.SH NAME -puppet-lint \- check puppet manifests for style guide conformity -.SH DESCRIPTION -Puppet\-lint -.SS "Basic Command Line Usage:" -.IP -puppet\-lint [OPTIONS] [PATH] -.TP -PATH -The path to the Puppet manifest. -.SH OPTIONS -.TP -\fB\-\-version\fR -Display current version. diff -Nru puppet-lint-3.0.1/debian/puppet-lint.manpages puppet-lint-4.2.4/debian/puppet-lint.manpages --- puppet-lint-3.0.1/debian/puppet-lint.manpages 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/puppet-lint.manpages 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -debian/puppet-lint.1 diff -Nru puppet-lint-3.0.1/debian/rules puppet-lint-4.2.4/debian/rules --- puppet-lint-3.0.1/debian/rules 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/rules 2024-02-22 05:30:18.000000000 +0000 @@ -3,5 +3,14 @@ export GEM2DEB_TEST_RUNNER = --check-dependencies export DH_RUBY = --gem-install +mandir := $(CURDIR)/debian/puppet-lint/usr/share/man/man1 + %: dh $@ --buildsystem=ruby --with ruby + +ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS))) +override_dh_installman: + mkdir -p $(mandir) + help2man --name='Puppet Lint' --no-info \ + -o $(mandir)/puppet-lint.1 bin/puppet-lint +endif diff -Nru puppet-lint-3.0.1/debian/tests/control puppet-lint-4.2.4/debian/tests/control --- puppet-lint-3.0.1/debian/tests/control 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/tests/control 2024-02-22 05:30:18.000000000 +0000 @@ -1,4 +1,5 @@ Tests: run-tests -Depends: perl, - sharness, - @, +Depends: + perl, + sharness, + @, diff -Nru puppet-lint-3.0.1/debian/upstream/metadata puppet-lint-4.2.4/debian/upstream/metadata --- puppet-lint-3.0.1/debian/upstream/metadata 2022-10-23 17:29:10.000000000 +0000 +++ puppet-lint-4.2.4/debian/upstream/metadata 2024-02-22 05:30:18.000000000 +0000 @@ -1,9 +1,7 @@ --- Archive: GitHub -Bug-Database: https://github.com/rodjek/puppet-lint/issues -Bug-Submit: https://github.com/rodjek/puppet-lint/issues -Changelog: https://github.com/rodjek/puppet-lint/tags -Contact: https://github.com/rodjek/puppet-lint/issues -Name: puppet-lint -Repository: https://github.com/rodjek/puppet-lint.git -Repository-Browse: https://github.com/rodjek/puppet-lint +Bug-Database: https://github.com/puppetlabs/puppet-lint/issues +Bug-Submit: https://github.com/puppetlabs/puppet-lint/issues +Changelog: https://github.com/puppetlabs/puppet-lint/tags +Repository: https://github.com/puppetlabs/puppet-lint.git +Repository-Browse: https://github.com/puppetlabs/puppet-lint diff -Nru puppet-lint-3.0.1/lib/puppet-lint/bin.rb puppet-lint-4.2.4/lib/puppet-lint/bin.rb --- puppet-lint-3.0.1/lib/puppet-lint/bin.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/bin.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,6 +1,7 @@ require 'pathname' require 'uri' require 'puppet-lint/optparser' +require 'puppet-lint/report/codeclimate' # Internal: The logic of the puppet-lint bin script, contained in a class for # ease of testing. @@ -48,7 +49,7 @@ begin path = @args[0] - full_path = File.expand_path(path, ENV['PWD']) + full_path = File.expand_path(path, ENV.fetch('PWD', nil)) full_base_path = if File.directory?(full_path) full_path else @@ -78,19 +79,17 @@ path.each do |f| next if ignore_paths.any? { |p| File.fnmatch(p, f) } + l = PuppetLint.new l.file = f l.run all_problems << l.print_problems - if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings) - return_val = 1 - end + return_val = 1 if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings) next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax } - File.open(f, 'wb') do |fd| - fd.write(l.manifest) - end + + File.binwrite(f, l.manifest) end if PuppetLint.configuration.sarif @@ -104,6 +103,8 @@ puts JSON.pretty_generate(all_problems) end + PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) if PuppetLint.configuration.codeclimate_report_file + return_val rescue PuppetLint::NoCodeError puts 'puppet-lint: no file specified or specified file does not exist' @@ -143,7 +144,7 @@ 'ruleIndex' => rule_index, 'message' => { 'text' => message[:message] }, 'locations' => [{ 'physicalLocation' => { 'artifactLocation' => { 'uri' => relative_path, 'uriBaseId' => 'ROOTPATH' }, -'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }], + 'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }] } results << result end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/checkplugin.rb puppet-lint-4.2.4/lib/puppet-lint/checkplugin.rb --- puppet-lint-3.0.1/lib/puppet-lint/checkplugin.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/checkplugin.rb 2024-02-12 13:18:23.000000000 +0000 @@ -179,10 +179,10 @@ # Returns a Hash of default problem information. def default_info @default_info ||= { - check: self.class.const_get('NAME'), + check: self.class.const_get(:NAME), fullpath: fullpath, path: path, - filename: filename, + filename: filename } end @@ -202,14 +202,10 @@ problem[:kind] = kind problem.merge!(default_info) { |_key, v1, _v2| v1 } - unless [:warning, :error, :fixed].include?(kind) - raise ArgumentError, 'unknown value passed for kind' - end + raise ArgumentError, 'unknown value passed for kind' unless [:warning, :error, :fixed].include?(kind) [:message, :line, :column, :check].each do |attr| - unless problem.key?(attr) - raise ArgumentError, "problem hash must contain #{attr.inspect}" - end + raise ArgumentError, "problem hash must contain #{attr.inspect}" unless problem.key?(attr) end @problems << problem diff -Nru puppet-lint-3.0.1/lib/puppet-lint/checks.rb puppet-lint-4.2.4/lib/puppet-lint/checks.rb --- puppet-lint-3.0.1/lib/puppet-lint/checks.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/checks.rb 2024-02-12 13:18:23.000000000 +0000 @@ -39,7 +39,7 @@ column: e.column, fullpath: PuppetLint::Data.fullpath, path: PuppetLint::Data.path, - filename: PuppetLint::Data.filename, + filename: PuppetLint::Data.filename } PuppetLint::Data.tokens = [] end @@ -76,18 +76,18 @@ kind: :error, check: :syntax, message: 'Syntax error', - fullpath: File.expand_path(fileinfo, ENV['PWD']), + fullpath: File.expand_path(fileinfo, ENV.fetch('PWD', nil)), filename: File.basename(fileinfo), path: fileinfo, line: e.token.line, - column: e.token.column, + column: e.token.column } @problems - rescue => e + rescue StandardError => e $stdout.puts <<-END.gsub(%r{^ {6}}, '') Whoops! It looks like puppet-lint has encountered an error that it doesn't - know how to handle. Please open an issue at https://github.com/rodjek/puppet-lint + know how to handle. Please open an issue at https://github.com/puppetlabs/puppet-lint and paste the following output into the issue description. --- puppet-lint version: #{PuppetLint::VERSION} @@ -120,10 +120,8 @@ # # Returns an Array of String check names. def enabled_checks - @enabled_checks ||= begin - PuppetLint.configuration.checks.select do |check| - PuppetLint.configuration.send("#{check}_enabled?") - end + @enabled_checks ||= PuppetLint.configuration.checks.select do |check| + PuppetLint.configuration.send(:"#{check}_enabled?") end end @@ -131,6 +129,6 @@ # # Returns the manifest as a String. def manifest - PuppetLint::Data.tokens.map(&:to_manifest).join('') + PuppetLint::Data.tokens.map(&:to_manifest).join end end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/configuration.rb puppet-lint-4.2.4/lib/puppet-lint/configuration.rb --- puppet-lint-3.0.1/lib/puppet-lint/configuration.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/configuration.rb 2024-02-12 13:18:23.000000000 +0000 @@ -17,21 +17,21 @@ # Public: Determine if the named check is enabled. # # Returns true if the check is enabled, otherwise return false. - define_method("#{check}_enabled?") do - settings["#{check}_disabled"] == true ? false : true + define_method(:"#{check}_enabled?") do + settings["#{check}_disabled"] != true end # Public: Disable the named check. # # Returns nothing. - define_method("disable_#{check}") do + define_method(:"disable_#{check}") do settings["#{check}_disabled"] = true end # Public: Enable the named check. # # Returns nothing. - define_method("enable_#{check}") do + define_method(:"enable_#{check}") do settings["#{check}_disabled"] = false end end @@ -92,7 +92,7 @@ # value - The value to set the option to. # # Returns nothing. - define_method("#{option}=") do |value| + define_method(:"#{option}=") do |value| settings[option] = value end @@ -153,5 +153,6 @@ self.show_ignored = false self.ignore_paths = ['vendor/**/*.pp'] self.github_actions = ENV.key?('GITHUB_ACTION') + self.codeclimate_report_file = ENV.fetch('CODECLIMATE_REPORT_FILE', nil) end end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/data.rb puppet-lint-4.2.4/lib/puppet-lint/data.rb --- puppet-lint-3.0.1/lib/puppet-lint/data.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/data.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,24 +1,30 @@ require 'singleton' require 'set' -# Public: A singleton class storing all the information about the manifest -# being analysed. +# A singleton class storing all the information about the manifest being +# analysed. +# +# @api public class PuppetLint::Data include Singleton class << self - # Internal: Get/Set the full expanded path to the manifest file being - # checked. + # Get/Set the full expanded path to the manifest file being checked. + # + # @api private attr_reader :path, :fullpath, :filename - # Internal: Get/Set the raw manifest data, split by \n. + # Get/Set the raw manifest data, split by \n. + # + # @api private attr_accessor :manifest_lines - # Internal: Store the tokenised manifest. + # Store the tokenised manifest. # - # tokens - The Array of PuppetLint::Lexer::Token objects to store. + # @param [Array[PuppetLint::Lexer::Token]] tokens The Array of PuppetLint::Lexer::Token objects to store. + # @return [nil] # - # Returns nothing. + # @api private def tokens=(tokens) @tokens = tokens @title_tokens = nil @@ -32,14 +38,17 @@ @defaults_indexes = nil end + # @api private def ruby1? @ruby1 = RbConfig::CONFIG['MAJOR'] == '1' if @ruby1.nil? @ruby1 end - # Public: Get the tokenised manifest. + # Get the tokenised manifest. + # + # @return [Array[PuppetLint::Lexer::Token]] # - # Returns an Array of PuppetLint::Lexer::Token objects. + # @api public def tokens calling_method = if ruby1? begin @@ -62,7 +71,12 @@ end end - # Public: Add new token. + # Add new token. + # + # @param [Integer] index + # @param [PuppetLint::Lexer::Token] token + # + # @api public def insert(index, token) current_token = tokens[index - 1] token.next_token = current_token.next_token @@ -72,7 +86,7 @@ unless formatting_tokens.include?(token.type) current_token.next_token.prev_code_token = token unless current_token.next_token.nil? - next_nf_idx = tokens[index..-1].index { |r| !formatting_tokens.include?(r.type) } + next_nf_idx = tokens[index..].index { |r| !formatting_tokens.include?(r.type) } unless next_nf_idx.nil? next_nf_token = tokens[index + next_nf_idx] token.next_code_token = next_nf_token @@ -92,14 +106,16 @@ end current_token.next_token = token - unless formatting_tokens.include?(token.type) - current_token.next_code_token = token - end + current_token.next_code_token = token unless formatting_tokens.include?(token.type) tokens.insert(index, token) end - # Public: Removes a token + # Remove a token + # + # @param [PuppetLint::Lexer::Token] token + # + # @api public def delete(token) token.next_token.prev_token = token.prev_token unless token.next_token.nil? token.prev_token.next_token = token.next_token unless token.prev_token.nil? @@ -111,26 +127,29 @@ tokens.delete(token) end - # Internal: Store the path to the manifest file and populate fullpath and - # filename. + # Store the path to the manifest file and populate fullpath and filename. # - # val - The path to the file as a String. + # @param [String] val The path to the file # - # Returns nothing. + # @return [nil] + # + # @api private def path=(val) @path = val if val.nil? @fullpath = nil @filename = nil else - @fullpath = File.expand_path(val, ENV['PWD']) + @fullpath = File.expand_path(val, ENV.fetch('PWD', nil)) @filename = File.basename(val) end end - # Internal: Retrieve a list of tokens that represent resource titles + # Retrieve a list of tokens that represent resource titles + # + # @return [Array[PuppetLint::Lexer::Token]] # - # Returns an Array of PuppetLint::Lexer::Token objects. + # @api private def title_tokens @title_tokens ||= begin result = [] @@ -155,28 +174,44 @@ end end - # Internal: Calculate the positions of all resource declarations within the + # Determine if the given token contains a CLASSREF in the token chain.. + # + # @param [PuppetLint::Lexer::Token] token + # + # @api private + def classref?(token) + current_token = token + while (current_token = current_token.prev_code_token) + return true if current_token.type == :CLASSREF + return false if current_token.type == :NAME + end + end + + # Calculate the positions of all resource declarations within the # tokenised manifest. These positions only point to the content of the # resource declarations, they do not include resource types or titles. # - # Returns an Array of Hashes, each containing: - # :start - An Integer position in the `tokens` Array pointing to the - # first Token of a resource declaration. - # :end - An Integer position in the `tokens` Array pointing to the last - # Token of a resource declaration. + # @return [Array[Hash[Symbol, Integer]]] each hash contains :start and + # :end pointing to the first and last {PuppetLint::Lexer::Token} of a + # resource declaration + # + # @api private def resource_indexes @resource_indexes ||= begin marker = 0 result = [] tokens.select { |t| t.type == :COLON }.each do |colon_token| next unless colon_token.next_code_token && colon_token.next_code_token.type != :LBRACE + next if classref?(colon_token) - rel_start_idx = tokens[marker..-1].index(colon_token) + rel_start_idx = tokens[marker..].index(colon_token) break if rel_start_idx.nil? + start_idx = rel_start_idx + marker end_token = colon_token.next_token_of([:SEMIC, :RBRACE]) - rel_end_idx = tokens[start_idx..-1].index(end_token) + rel_end_idx = tokens[start_idx..].index(end_token) raise PuppetLint::SyntaxError, colon_token if rel_end_idx.nil? + marker = rel_end_idx + start_idx result << { @@ -184,19 +219,22 @@ end: marker, tokens: tokens[start_idx..marker], type: find_resource_type_token(start_idx), - param_tokens: find_resource_param_tokens(tokens[start_idx..marker]), + param_tokens: find_resource_param_tokens(tokens[start_idx..marker]) } end result end end - # Internal: Find the Token representing the type of a resource definition. + # Find the Token representing the type of a resource definition. # - # index - The Integer pointing to the start of the resource in the `tokens` - # array. + # @param [Integer] index + # The Integer pointing to the start of the resource in the `tokens` + # array. # - # Returns a Token object. + # @return [PuppetLint::Lexer::Token] + # + # @api private def find_resource_type_token(index) lbrace_idx = tokens[0..index].rindex do |token| token.type == :LBRACE && token.prev_code_token.type != :QMARK @@ -207,13 +245,15 @@ tokens[lbrace_idx].prev_code_token end - # Internal: Find all the Token objects representing the parameter names in + # Find all the Token objects representing the parameter names in # a resource definition. # - # resource_tokens - An Array of Token objects that comprise the resource - # definition. + # @param [Array[PuppetLint::Lexer::Token]] resource_tokens + # An Array of Token objects that comprise the resource definition. + # + # @return [Array[PuppetLint::Lexer::Token]] # - # Returns an Array of Token objects. + # @api private def find_resource_param_tokens(resource_tokens) param_tokens = [] @@ -224,16 +264,14 @@ break unless resource_tokens.include?(iter_token) - if iter_token && iter_token.next_code_token.type == :FARROW - param_tokens << iter_token - end + param_tokens << iter_token if iter_token && iter_token.next_code_token.type == :FARROW end param_tokens end - # Internal: Calculate the positions of all class definitions within the - # `tokens` Array. + # Calculate the positions of all class definitions within the `tokens` + # Array. # # Returns an Array of Hashes, each containing: # :start - An Integer position in the `tokens` Array pointing to the @@ -242,12 +280,14 @@ # Token of a class definition. # :tokens - An Array consisting of all the Token objects that make up the # class definition. + # + # @api private def class_indexes @class_indexes ||= definition_indexes(:CLASS) end - # Internal: Calculate the positions of all defined type definitions within - # the `tokens` Array. + # Calculate the positions of all defined type definitions within the + # `tokens` Array. # # Returns an Array of Hashes, each containing: # :start - An Integer position in the `tokens` Array pointing to the @@ -256,12 +296,14 @@ # Token of a defined type definition. # :tokens - An Array consisting of all the Token objects that make up the # defined type. + # + # @api private def defined_type_indexes @defined_type_indexes ||= definition_indexes(:DEFINE) end - # Internal: Calculate the positions of all node definitions within the - # `tokens` Array. + # Calculate the positions of all node definitions within the `tokens` + # Array. # # Returns an Array of Hashes, each containing: # :start - An Integer position in the `tokens` Array pointing to the @@ -270,12 +312,14 @@ # Token of a defined type definition. # :tokens - An Array consisting of all the Token objects that make up the # defined type. + # + # @api private def node_indexes @node_indexes ||= definition_indexes(:NODE) end - # Internal: Calculate the positions of all the specified defintion types - # within the `tokens` Array. + # Calculate the positions of all the specified defintion types within the + # `tokens` Array. # # Returns an Array of Hashes, each containing: # :start - An Integer position in the `tokens` Array pointing to the @@ -284,6 +328,8 @@ # Token of a definition. # :tokens - An Array consisting of all the Token objects that make up the # definition. + # + # @api private def definition_indexes(type) result = [] tokens.each_with_index do |token, i| @@ -293,7 +339,7 @@ paren_depth = 0 in_params = false inherited_class = nil - tokens[i + 1..-1].each_with_index do |definition_token, j| + tokens[i + 1..].each_with_index do |definition_token, j| case definition_token.type when :INHERITS inherited_class = definition_token.next_code_token @@ -307,19 +353,17 @@ brace_depth += 1 when :RBRACE brace_depth -= 1 - if brace_depth.zero? && !in_params - if token.next_code_token.type != :LBRACE - result << { - start: i, - end: i + j + 1, - tokens: tokens[i..(i + j + 1)], - param_tokens: param_tokens(tokens[i..(i + j + 1)]), - type: type, - name_token: token.next_code_token, - inherited_token: inherited_class, - } - break - end + if brace_depth.zero? && !in_params && (token.next_code_token.type != :LBRACE) + result << { + start: i, + end: i + j + 1, + tokens: tokens[i..(i + j + 1)], + param_tokens: param_tokens(tokens[i..(i + j + 1)]), + type: type, + name_token: token.next_code_token, + inherited_token: inherited_class + } + break end end end @@ -327,8 +371,7 @@ result end - # Internal: Calculate the positions of all function calls within - # `tokens` Array. + # Calculate the positions of all function calls within `tokens` Array. # # Returns an Array of Hashes, each containing: # :start - An Integer position in the `tokens` Array pointing to the @@ -337,6 +380,8 @@ # Token of a function call # :tokens - An Array consisting of all the Token objects that make up the # function call. + # + # @api private def function_indexes @function_indexes ||= begin functions = [] @@ -354,7 +399,7 @@ level = 0 real_idx = 0 in_paren = false - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| break if level.zero? && in_paren break if level.zero? && cur_token.type == :NEWLINE @@ -369,15 +414,14 @@ functions << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end functions end end - # Internal: Calculate the positions of all array values within - # `tokens` Array. + # Calculate the positions of all array values within `tokens` Array. # # Returns an Array of Hashes, each containing: # :start - An Integer position in the `tokens` Array pointing to the @@ -386,6 +430,8 @@ # Token of an array value # :tokens - An Array consisting of all the Token objects that make up the # array value. + # + # @api private def array_indexes @array_indexes ||= begin arrays = [] @@ -393,7 +439,7 @@ next unless token.type == :LBRACK real_idx = 0 - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| real_idx = token_idx + 1 + cur_token_idx break if cur_token.type == :RBRACK end @@ -405,15 +451,14 @@ arrays << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end arrays end end - # Internal: Calculate the positions of all hash values within - # `tokens` Array. + # Calculate the positions of all hash values within `tokens` Array. # # Returns an Array of Hashes, each containing: # :start - An Integer position in the `tokens` Array pointing to the @@ -422,6 +467,8 @@ # Token of an hash value # :tokens - An Array consisting of all the Token objects that make up the # hash value. + # + # @api private def hash_indexes @hash_indexes ||= begin hashes = [] @@ -432,25 +479,25 @@ level = 0 real_idx = 0 - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| real_idx = token_idx + 1 + cur_token_idx level += 1 if cur_token.type == :LBRACE level -= 1 if cur_token.type == :RBRACE - break if level < 0 + break if level.negative? end hashes << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end hashes end end - # Internal: Calculate the positions of all defaults declarations within + # Calculate the positions of all defaults declarations within # `tokens` Array. # # Returns an Array of Hashes, each containing: @@ -460,6 +507,8 @@ # Token of the defaults declaration # :tokens - An Array consisting of all the Token objects that make up the # defaults declaration. + # + # @api private def defaults_indexes @defaults_indexes ||= begin defaults = [] @@ -469,7 +518,7 @@ real_idx = 0 - tokens[token_idx + 1..-1].each_with_index do |cur_token, cur_token_idx| + tokens[token_idx + 1..].each_with_index do |cur_token, cur_token_idx| real_idx = token_idx + 1 + cur_token_idx break if cur_token.type == :RBRACE end @@ -477,21 +526,24 @@ defaults << { start: token_idx, end: real_idx, - tokens: tokens[token_idx..real_idx], + tokens: tokens[token_idx..real_idx] } end defaults end end - # Internal: Finds all the tokens that make up the defined type or class + # Finds all the tokens that make up the defined type or class # definition parameters. # - # these_tokens - An Array of PuppetLint::Lexer::Token objects that make up - # the defined type or class definition. + # @param [Array[PuppetLint::Lexer::Token]] these_tokens + # An Array of PuppetLint::Lexer::Token objects that make up the defined + # type or class definition. + # + # @return [Array[PuppetLint::Lexer::Token], nil] objects or nil if it takes + # no parameters. # - # Returns an Array of PuppetLint::Lexer::Token objects or nil if it takes - # no parameters. + # @api private def param_tokens(these_tokens) depth = 0 lparen_idx = nil @@ -520,28 +572,34 @@ end end - # Internal: Retrieves a list of token types that are considered to be + # Retrieves a list of token types that are considered to be # formatting tokens (whitespace, newlines, etc). # - # Returns an Array of Symbols. + # @return [Array[Symbol]] + # + # @api private def formatting_tokens @formatting_tokens ||= PuppetLint::Lexer::FORMATTING_TOKENS end - # Internal: Retrieves a Hash of Sets. Each key is a check name Symbol and + # Retrieves a Hash of Sets. Each key is a check name Symbol and # the Set of Integers returned lists all the lines that the check results # should be ignored on. # - # Returns a Hash of Sets of Integers. + # @return [Hash[Symbol, Set[Integer]]] + # + # @api private def ignore_overrides @ignore_overrides ||= {} end - # Internal: Parses all COMMENT, MLCOMMENT and SLASH_COMMENT tokens looking + # Parses all COMMENT, MLCOMMENT and SLASH_COMMENT tokens looking # for control comments (comments that enable or disable checks). Builds the # contents of the `ignore_overrides` hash. # - # Returns nothing. + # @return [nil] + # + # @api private def parse_control_comments @ignore_overrides.each_key { |check| @ignore_overrides[check].clear } @@ -551,7 +609,7 @@ comment_token_types.include?(token.type) end control_comment_tokens = comment_tokens.select do |token| - token.value.strip =~ %r{\Alint\:(ignore\:[\w\d]+|endignore)} + token.value.strip =~ %r{\Alint:(ignore:[\w\d]+|endignore)} end stack = [] @@ -561,12 +619,12 @@ comment_words = token.value.strip.split(%r{\s+}) comment_words.each_with_index do |word, i| - if %r{\Alint\:(ignore|endignore)}.match?(word) + if %r{\Alint:(ignore|endignore)}.match?(word) comment_data << word else # Once we reach the first non-controlcomment word, assume the rest # of the words are the reason. - reason = comment_words[i..-1] + reason = comment_words[i..] break end end @@ -591,7 +649,7 @@ if top_override.nil? # TODO: refactor to provide a way to expose problems from # PuppetLint::Data via the normal problem reporting mechanism. - $stderr.puts "WARNING: lint:endignore comment with no opening lint:ignore: comment found on line #{token.line}" + warn "WARNING: lint:endignore comment with no opening lint:ignore: comment found on line #{token.line}" else top_override.each do |start| next if start.nil? @@ -607,7 +665,7 @@ end stack.each do |control| - $stderr.puts "WARNING: lint:ignore:#{control[0][2]} comment on line #{control[0][0]} with no closing lint:endignore comment" + warn "WARNING: lint:ignore:#{control[0][2]} comment on line #{control[0][0]} with no closing lint:endignore comment" end end end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/lexer/string_slurper.rb puppet-lint-4.2.4/lib/puppet-lint/lexer/string_slurper.rb --- puppet-lint-3.0.1/lib/puppet-lint/lexer/string_slurper.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/lexer/string_slurper.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,11 +1,10 @@ require 'strscan' +# rubocop:disable Style/ClassAndModuleChildren class PuppetLint::Lexer # Internal: A class for slurping strings from a Puppet manifest. class StringSlurper - attr_accessor :scanner - attr_accessor :results - attr_accessor :interp_stack + attr_accessor :scanner, :results, :interp_stack START_INTERP_PATTERN = %r{\$\{}.freeze END_INTERP_PATTERN = %r{\}}.freeze diff -Nru puppet-lint-3.0.1/lib/puppet-lint/lexer/token.rb puppet-lint-4.2.4/lib/puppet-lint/lexer/token.rb --- puppet-lint-3.0.1/lib/puppet-lint/lexer/token.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/lexer/token.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,3 +1,4 @@ +# rubocop:disable Style/ClassAndModuleChildren class PuppetLint::Lexer # Public: Stores a fragment of the manifest and the information about its # location in the manifest. @@ -29,7 +30,7 @@ # etc) in the manifest. attr_accessor :next_code_token - # Public: Gets/sets the previous code tokne (skips whitespace, + # Public: Gets/sets the previous code token (skips whitespace, # comments, etc) in the manifest. attr_accessor :prev_code_token @@ -175,12 +176,10 @@ token_iter = send("#{direction}_token".to_sym) until token_iter.nil? - if to_find.include?(token_iter.type) - return token_iter if opts[:value].nil? || token_iter.value == opts[:value] - end + return token_iter if to_find.include?(token_iter.type) && (opts[:value].nil? || token_iter.value == opts[:value]) - opening_token = direction == :next ? 'L' : 'R' - closing_token = direction == :next ? 'R' : 'L' + opening_token = (direction == :next) ? 'L' : 'R' + closing_token = (direction == :next) ? 'R' : 'L' if opts[:skip_blocks] case token_iter.type @@ -194,6 +193,7 @@ end return nil if token_iter.nil? + token_iter = token_iter.send("#{direction}_token".to_sym) end nil @@ -202,6 +202,7 @@ def interpolated_variable? return false if type == :TYPE && value != 'type' return true if type == :NAME + PuppetLint::Lexer::KEYWORDS.include?(type.to_s.downcase) end end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/lexer.rb puppet-lint-4.2.4/lib/puppet-lint/lexer.rb --- puppet-lint-3.0.1/lib/puppet-lint/lexer.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/lexer.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,6 +1,3 @@ -# encoding: utf-8 - -require 'pp' require 'strscan' require 'set' require 'puppet-lint/lexer/token' @@ -53,42 +50,42 @@ # Internal: A Hash whose keys are Strings representing reserved keywords in # the Puppet DSL. - # From https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/parser/lexer2.rb#L116-L137 + # From https://github.com/puppetlabs/puppet/blob/main/lib/puppet/pops/parser/lexer2.rb#L116-L137 # or thereabouts KEYWORDS = { - 'case' => true, - 'class' => true, - 'default' => true, - 'define' => true, - 'import' => true, - 'if' => true, - 'elsif' => true, - 'else' => true, + 'case' => true, + 'class' => true, + 'default' => true, + 'define' => true, + 'import' => true, + 'if' => true, + 'elsif' => true, + 'else' => true, 'inherits' => true, - 'node' => true, - 'and' => true, - 'or' => true, - 'undef' => true, - 'false' => true, - 'true' => true, - 'in' => true, - 'unless' => true, + 'node' => true, + 'and' => true, + 'or' => true, + 'undef' => true, + 'false' => true, + 'true' => true, + 'in' => true, + 'unless' => true, 'function' => true, - 'type' => true, - 'attr' => true, - 'private' => true, + 'type' => true, + 'attr' => true, + 'private' => true }.freeze # Internal: A Hash whose keys are Strings representing reserved keywords in # the Puppet DSL when Application Management is enabled - # From https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/parser/lexer2.rb#L142-L159 + # From https://github.com/puppetlabs/puppet/blob/main/lib/puppet/pops/parser/lexer2.rb#L142-L159 # or therabouts # Currently unused APP_MANAGEMENT_TOKENS = { 'application' => true, - 'consumes' => true, - 'produces' => true, - 'site' => true, + 'consumes' => true, + 'produces' => true, + 'site' => true }.freeze # Internal: A Hash whose keys are Symbols representing token types which @@ -104,7 +101,7 @@ IF: true, ELSIF: true, LPAREN: true, - EQUALS: true, + EQUALS: true }.freeze # Internal: some commonly used regular expressions @@ -112,7 +109,7 @@ # \v == vertical tab # \f == form feed # \p{Zs} == ASCII + Unicode non-linebreaking whitespace - WHITESPACE_RE = RUBY_VERSION == '1.8.7' ? %r{[\t\v\f ]} : %r{[\t\v\f\p{Zs}]} + WHITESPACE_RE = (RUBY_VERSION == '1.8.7') ? %r{[\t\v\f ]} : %r{[\t\v\f\p{Zs}]} LINE_END_RE = %r{(?:\r\n|\r|\n)}.freeze @@ -182,7 +179,7 @@ COMMENT: true, MLCOMMENT: true, SLASH_COMMENT: true, - INDENT: true, + INDENT: true }.freeze # Internal: Access the internal token storage. @@ -203,7 +200,7 @@ i = 0 while i < code.size - chunk = code[i..-1] + chunk = code[i..] found = false @@ -233,12 +230,12 @@ tokens << new_token(:VARIABLE, var_name, opts) elsif %r{\A'.*?'}m.match?(chunk) - str_content = StringScanner.new(code[i + 1..-1]).scan_until(%r{(\A|[^\\])(\\\\)*'}m) + str_content = StringScanner.new(code[i + 1..]).scan_until(%r{(\A|[^\\])(\\\\)*'}m) length = str_content.size + 1 tokens << new_token(:SSTRING, str_content[0..-2]) elsif chunk.start_with?('"') - slurper = PuppetLint::Lexer::StringSlurper.new(code[i + 1..-1]) + slurper = PuppetLint::Lexer::StringSlurper.new(code[i + 1..]) begin string_segments = slurper.parse process_string_segments(string_segments) @@ -271,7 +268,7 @@ tokens << new_token(:MLCOMMENT, mlcomment, raw: mlcomment_raw) elsif chunk.match(%r{\A/.*?/}m) && possible_regex? - str_content = StringScanner.new(code[i + 1..-1]).scan_until(%r{(\A|[^\\])(\\\\)*/}m) + str_content = StringScanner.new(code[i + 1..]).scan_until(%r{(\A|[^\\])(\\\\)*/}m) length = str_content.size + 1 tokens << new_token(:REGEX, str_content[0..-2]) @@ -286,7 +283,7 @@ length += indent.size else heredoc_tag = heredoc_queue.shift - slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..-1]) + slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..]) heredoc_segments = slurper.parse_heredoc(heredoc_tag) process_heredoc_segments(heredoc_segments) length += slurper.consumed_chars @@ -298,7 +295,7 @@ unless heredoc_queue.empty? heredoc_tag = heredoc_queue.shift - slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..-1]) + slurper = PuppetLint::Lexer::StringSlurper.new(code[i + length..]) heredoc_segments = slurper.parse_heredoc(heredoc_tag) process_heredoc_segments(heredoc_segments) length += slurper.consumed_chars @@ -419,11 +416,11 @@ lexer = PuppetLint::Lexer.new lexer.tokenise(segment[1]) lexer.tokens.each_with_index do |t, i| - type = i.zero? && t.interpolated_variable? ? :VARIABLE : t.type + type = (i.zero? && t.interpolated_variable?) ? :VARIABLE : t.type tokens << new_token(type, t.value, raw: t.raw) end when :UNENC_VAR - tokens << new_token(:UNENC_VARIABLE, segment[1].gsub(%r{\A\$}, '')) + tokens << new_token(:UNENC_VARIABLE, segment[1].delete_prefix('$')) else tokens << new_token(:DQMID, segment[1]) end @@ -451,11 +448,11 @@ lexer = PuppetLint::Lexer.new lexer.tokenise(segment[1]) lexer.tokens.each_with_index do |t, i| - type = i.zero? && t.interpolated_variable? ? :VARIABLE : t.type + type = (i.zero? && t.interpolated_variable?) ? :VARIABLE : t.type tokens << new_token(type, t.value, raw: t.raw) end when :UNENC_VAR - tokens << new_token(:UNENC_VARIABLE, segment[1].gsub(%r{\A\$}, '')) + tokens << new_token(:UNENC_VARIABLE, segment[1].delete_prefix('$')) else tokens << new_token(:HEREDOC_MID, segment[1]) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/monkeypatches.rb puppet-lint-4.2.4/lib/puppet-lint/monkeypatches.rb --- puppet-lint-3.0.1/lib/puppet-lint/monkeypatches.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/monkeypatches.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,9 +1,9 @@ begin '%{test}' % { test: 'replaced' } == 'replaced' -rescue +rescue StandardError # monkeypatch String#% into Ruby 1.8.7 class String - Percent = instance_method('%') unless defined?(Percent) + Percent = instance_method(:%) unless defined?(Percent) def %(*a, &b) a.flatten! @@ -18,7 +18,7 @@ if a.empty? string else - Percent.bind(string).call(a, &b) + Percent.bind_call(string, a, &b) end end @@ -28,7 +28,7 @@ vars.each do |var, value| var = var.to_s var.gsub!(%r{[^a-zA-Z0-9_]}, '') - changed = gsub!(%r{\%\{#{var}\}}, value.to_s) + changed = gsub!(%r{%\{#{var}\}}, value.to_s) end break unless changed end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/optparser.rb puppet-lint-4.2.4/lib/puppet-lint/optparser.rb --- puppet-lint-3.0.1/lib/puppet-lint/optparser.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/optparser.rb 2024-02-12 13:18:23.000000000 +0000 @@ -102,6 +102,10 @@ PuppetLint.configuration.sarif = true end + opts.on('--codeclimate-report-file FILE', 'Save a code climate compatible report to this file') do |file| + PuppetLint.configuration.codeclimate_report_file = file + end + opts.on('--list-checks', 'List available check names.') do PuppetLint.configuration.list_checks = true end @@ -113,9 +117,9 @@ enable_checks = checks.split(',').map(&:to_sym) PuppetLint.configuration.checks.each do |check| if enable_checks.include?(check) - PuppetLint.configuration.send("enable_#{check}") + PuppetLint.configuration.send(:"enable_#{check}") else - PuppetLint.configuration.send("disable_#{check}") + PuppetLint.configuration.send(:"disable_#{check}") end end end @@ -126,20 +130,20 @@ PuppetLint.configuration.checks.each do |check| opts.on("--no-#{check}-check", "Skip the #{check} check.") do - PuppetLint.configuration.send("disable_#{check}") + PuppetLint.configuration.send(:"disable_#{check}") end - next if PuppetLint.configuration.send("#{check}_enabled?") + next if PuppetLint.configuration.send(:"#{check}_enabled?") opts.on("--#{check}-check", "Enable the #{check} check.") do - PuppetLint.configuration.send("enable_#{check}") + PuppetLint.configuration.send(:"enable_#{check}") end end end unless args.include?('--no-config') opt_parser.load('/etc/puppet-lint.rc') - if ENV.key?('HOME') && File.readable?(ENV['HOME']) + if File.readable?(Dir.home) home_dotfile_path = File.expand_path('~/.puppet-lint.rc') opt_parser.load(home_dotfile_path) if File.readable?(home_dotfile_path) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb 2024-02-12 13:18:23.000000000 +0000 @@ -35,6 +35,7 @@ # Remove trailing whitespace after left operand (if it exists) return unless left_operand_token.next_token.type == :WHITESPACE + trailing_whitespace_token = left_operand_token.next_token remove_token(trailing_whitespace_token) if [:NEWLINE, :WHITESPACE].include?(trailing_whitespace_token.next_token.type) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb 2024-02-12 13:18:23.000000000 +0000 @@ -12,14 +12,12 @@ split_title = title_token.value.split('::') mod = split_title.first expected_path = if split_title.length > 1 - "/#{mod}/manifests/#{split_title[1..-1].join('/')}.pp" + "/#{mod}/manifests/#{split_title[1..].join('/')}.pp" else "/#{title_token.value}/manifests/init.pp" end - if PuppetLint.configuration.relative - expected_path = expected_path.gsub(%r{^/}, '').split('/')[1..-1].join('/') - end + expected_path = expected_path.gsub(%r{^/}, '').split('/')[1..].join('/') if PuppetLint.configuration.relative next if fullpath.end_with?(expected_path) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb 2024-02-12 13:18:23.000000000 +0000 @@ -5,7 +5,7 @@ PuppetLint.new_check(:class_inherits_from_params_class) do def check class_indexes.each do |class_idx| - next unless class_idx[:inherited_token] && class_idx[:inherited_token]&.value&.end_with?('::params') + next unless class_idx[:inherited_token]&.value&.end_with?('::params') notify( :warning, @@ -18,4 +18,4 @@ end end end -PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send(:disable_class_inherits_from_params_class) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb 2024-02-12 13:18:23.000000000 +0000 @@ -20,4 +20,4 @@ end end end -PuppetLint.configuration.send('disable_code_on_top_scope') +PuppetLint.configuration.send(:disable_code_on_top_scope) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb 2024-02-12 13:18:23.000000000 +0000 @@ -2,18 +2,18 @@ # defined inside another class. # # https://puppet.com/docs/puppet/latest/style_guide.html#nested-classes-or-defined-types +CLASS_DEFINE_TOKENS = Set[:CLASS, :DEFINE] PuppetLint.new_check(:nested_classes_or_defines) do - TOKENS = Set[:CLASS, :DEFINE] - def check class_indexes.each do |class_idx| # Skip the first token so that we don't pick up the first :CLASS - class_tokens = class_idx[:tokens][1..-1] + class_tokens = class_idx[:tokens][1..] class_tokens.each do |token| - next unless TOKENS.include?(token.type) + next unless CLASS_DEFINE_TOKENS.include?(token.type) next if token.next_code_token.type == :LBRACE - type = token.type == :CLASS ? 'class' : 'defined type' + + type = (token.type == :CLASS) ? 'class' : 'defined type' notify( :warning, diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/parameter_order.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/parameter_order.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/parameter_order.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/parameter_order.rb 2024-02-12 13:18:23.000000000 +0000 @@ -11,13 +11,14 @@ paren_stack = [] hash_or_array_stack = [] class_idx[:param_tokens].each_with_index do |token, i| - if token.type == :LPAREN + case token.type + when :LPAREN paren_stack.push(true) - elsif token.type == :RPAREN + when :RPAREN paren_stack.pop - elsif token.type == :LBRACE || token.type == :LBRACK + when :LBRACE, :LBRACK hash_or_array_stack.push(true) - elsif token.type == :RBRACE || token.type == :RBRACK + when :RBRACE, :RBRACK hash_or_array_stack.pop end @@ -34,9 +35,9 @@ message: msg, line: token.line, column: token.column, - description: 'Test the manifest tokens for any parameterised classes or defined types that take '\ - 'parameters and record a warning if there are any optional parameters listed before required parameters.', - help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#display-order-of-parameters', + description: 'Test the manifest tokens for any parameterised classes or defined types that take ' \ + 'parameters and record a warning if there are any optional parameters listed before required parameters.', + help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#params-display-order', ) end end @@ -47,20 +48,16 @@ return false unless token.prev_code_token [ - :LPAREN, # First parameter, no type specification - :COMMA, # Subsequent parameter, no type specification - :TYPE, # Parameter with simple type specification - :RBRACK, # Parameter with complex type specification + :LPAREN, # First parameter, no type specification + :COMMA, # Subsequent parameter, no type specification + :TYPE, # Parameter with simple type specification + :RBRACK, # Parameter with complex type specification + :CLASSREF, # Parameter with custom type specification ].include?(token.prev_code_token.type) end def required_parameter?(token) - data_type = token.prev_token_of(:TYPE, skip_blocks: true) - return false if data_type && data_type.value == 'Optional' - - if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type) - return !(token.prev_code_token && token.prev_code_token.type == :EQUALS) - end + return !(token.prev_code_token && token.prev_code_token.type == :EQUALS) if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type) false end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/variable_scope.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/variable_scope.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_classes/variable_scope.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_classes/variable_scope.rb 2024-02-12 13:18:23.000000000 +0000 @@ -5,35 +5,35 @@ # not. # # https://puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables -PuppetLint.new_check(:variable_scope) do - DEFAULT_SCOPE_VARS = Set[ - 'name', - 'title', - 'module_name', - 'environment', - 'clientcert', - 'clientversion', - 'servername', - 'serverip', - 'serverversion', - 'caller_module_name', - 'alias', - 'audit', - 'before', - 'loglevel', - 'noop', - 'notify', - 'require', - 'schedule', - 'stage', - 'subscribe', - 'tag', - 'facts', - 'trusted', - 'server_facts', - ] - POST_VAR_TOKENS = Set[:COMMA, :EQUALS, :RPAREN] +DEFAULT_SCOPE_VARS = Set[ + 'name', + 'title', + 'module_name', + 'environment', + 'clientcert', + 'clientversion', + 'servername', + 'serverip', + 'serverversion', + 'caller_module_name', + 'alias', + 'audit', + 'before', + 'loglevel', + 'noop', + 'notify', + 'require', + 'schedule', + 'stage', + 'subscribe', + 'tag', + 'facts', + 'trusted', + 'server_facts', +] +POST_VAR_TOKENS = Set[:COMMA, :EQUALS, :RPAREN] +PuppetLint.new_check(:variable_scope) do def check variables_in_scope = DEFAULT_SCOPE_VARS.clone @@ -93,7 +93,7 @@ end_token = nil brace_depth = 0 - tokens[start_idx..-1].each do |sub_token| + tokens[start_idx..].each do |sub_token| case sub_token.type when :LBRACE brace_depth += 1 @@ -117,9 +117,7 @@ msg = 'top-scope variable being used without an explicit namespace' referenced_variables.each do |token| - unless future_parser_scopes[token.line].nil? - next if future_parser_scopes[token.line].include?(token.value.gsub(%r{\[.+\]\Z}, '')) - end + next if !future_parser_scopes[token.line].nil? && future_parser_scopes[token.line].include?(token.value.gsub(%r{\[.+\]\Z}, '')) next if token.value.include?('::') next if %r{^(facts|trusted)\[.+\]}.match?(token.value) @@ -132,8 +130,8 @@ line: token.line, column: token.column, description: 'Test the manifest tokens for any variables that are referenced in the manifest. ' \ - 'If the variables are not fully qualified or one of the variables automatically created in the scope, ' \ - 'check that they have been defined in the local scope and record a warning for each variable that has not.', + 'If the variables are not fully qualified or one of the variables automatically created in the scope, ' \ + 'check that they have been defined in the local scope and record a warning for each variable that has not.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#namespacing-variables', ) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb 2024-02-12 13:18:23.000000000 +0000 @@ -10,7 +10,7 @@ next unless tokens[token_idx].type == :CASE depth = 0 - tokens[(token_idx + 1)..-1].each_index do |case_token_idx| + tokens[(token_idx + 1)..].each_index do |case_token_idx| idx = case_token_idx + token_idx + 1 if tokens[idx].type == :LBRACE depth += 1 @@ -27,7 +27,7 @@ case_indexes.each_with_index do |kase, kase_index| case_tokens = tokens[kase[:start]..kase[:end]] - case_indexes[(kase_index + 1)..-1].each do |successor_kase| + case_indexes[(kase_index + 1)..].each do |successor_kase| case_tokens -= tokens[successor_kase[:start]..successor_kase[:end]] end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_documentation/documentation.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_documentation/documentation.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_documentation/documentation.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_documentation/documentation.rb 2024-02-12 13:18:23.000000000 +0000 @@ -3,10 +3,10 @@ # record a warning for each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private -PuppetLint.new_check(:documentation) do - COMMENT_TOKENS = Set[:COMMENT, :MLCOMMENT, :SLASH_COMMENT] - WHITESPACE_TOKENS = Set[:WHITESPACE, :NEWLINE, :INDENT] +COMMENT_TOKENS = Set[:COMMENT, :MLCOMMENT, :SLASH_COMMENT] +WHITESPACE_TOKENS = Set[:WHITESPACE, :NEWLINE, :INDENT] +PuppetLint.new_check(:documentation) do def check (class_indexes + defined_type_indexes).each do |item_idx| comment_token = find_comment_token(item_idx[:tokens].first) @@ -25,9 +25,9 @@ message: "#{type} not documented", line: first_token.line, column: first_token.column, - description: 'Check the manifest tokens for any class or defined type that does not '\ - 'have a comment directly above it (hopefully, explaining the usage of it) and record '\ - 'a warning for each instance found.', + description: 'Check the manifest tokens for any class or defined type that does not ' \ + 'have a comment directly above it (hopefully, explaining the usage of it) and record ' \ + 'a warning for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#public-and-private', ) end @@ -40,6 +40,7 @@ while !prev_token.nil? && WHITESPACE_TOKENS.include?(prev_token.type) newlines += 1 if prev_token.type == :NEWLINE break if newlines > 1 + prev_token = prev_token.prev_token end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ node_tokens = tokens.select { |token| token.type == :NODE } node_tokens.each do |node| node_token_idx = tokens.index(node) - node_lbrace_tok = tokens[node_token_idx..-1].find { |token| token.type == :LBRACE } + node_lbrace_tok = tokens[node_token_idx..].find { |token| token.type == :LBRACE } if node_lbrace_tok.nil? notify( :error, diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb 2024-02-12 13:18:23.000000000 +0000 @@ -21,8 +21,8 @@ line: ensure_token.line, column: ensure_token.column, resource: resource, - description: 'Check the tokens of each resource instance for an ensure parameter and if '\ - 'found, check that it is the first parameter listed. If it is not the first parameter, record a warning.', + description: 'Check the tokens of each resource instance for an ensure parameter and if ' \ + 'found, check that it is the first parameter listed. If it is not the first parameter, record a warning.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#attribute-ordering', ) end @@ -37,9 +37,7 @@ ensure_param_comma_token = ensure_param_name_token.next_token_of([:COMMA, :SEMIC]) - if first_param_name_token.nil? || first_param_comma_token.nil? || ensure_param_comma_token.nil? - raise PuppetLint::NoFix - end + raise PuppetLint::NoFix if first_param_name_token.nil? || first_param_comma_token.nil? || ensure_param_comma_token.nil? first_param_name_idx = tokens.index(first_param_name_token) first_param_comma_idx = tokens.index(first_param_comma_token) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb 2024-02-12 13:18:23.000000000 +0000 @@ -21,8 +21,8 @@ column: value_token.column, param_token: ensure_token, value_token: value_token, - description: 'Check the tokens of each File resource instance for an ensure parameter and '\ - 'record a warning if the value of that parameter looks like a symlink target (starts with a \'/\').', + description: 'Check the tokens of each File resource instance for an ensure parameter and ' \ + 'record a warning if the value of that parameter looks like a symlink target (starts with a \'/\').', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#symbolic-links', ) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/file_mode.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/file_mode.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/file_mode.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/file_mode.rb 2024-02-12 13:18:23.000000000 +0000 @@ -3,12 +3,12 @@ # not a 4 digit octal value (0755) or a symbolic mode ('o=rwx,g+r'). # # https://puppet.com/docs/puppet/latest/style_guide.html#file-modes -PuppetLint.new_check(:file_mode) do - MSG = 'mode should be represented as a 4 digit octal value or symbolic mode'.freeze - SYM_RE = '([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze - IGNORE_TYPES = Set[:VARIABLE, :UNDEF, :FUNCTION_NAME] - MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze +MSG = 'mode should be represented as a 4 digit octal value or symbolic mode'.freeze +SYM_RE = '([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*'.freeze +IGNORE_TYPES = Set[:VARIABLE, :UNDEF, :FUNCTION_NAME] +MODE_RE = %r{\A([0-7]{4}|#{SYM_RE})\Z}.freeze +PuppetLint.new_check(:file_mode) do def check resource_indexes.each do |resource| next unless resource[:type].value == 'file' || resource[:type].value == 'concat' @@ -30,7 +30,7 @@ column: value_token.column, token: value_token, description: 'Check the tokens of each File resource instance for a mode parameter and if found, ' \ - 'record a warning if the value of that parameter is not a 4 digit octal value (0755) or a symbolic mode (\'o=rwx,g\+r\').', + 'record a warning if the value of that parameter is not a 4 digit octal value (0755) or a symbolic mode (\'o=rwx,g\+r\').', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes', ) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb 2024-02-12 13:18:23.000000000 +0000 @@ -3,9 +3,9 @@ # not a quoted string. # # https://puppet.com/docs/puppet/latest/style_guide.html#file-modes -PuppetLint.new_check(:unquoted_file_mode) do - TOKEN_TYPES = Set[:NAME, :NUMBER] +TOKEN_TYPES = Set[:NAME, :NUMBER] +PuppetLint.new_check(:unquoted_file_mode) do def check resource_indexes.each do |resource| next unless resource[:type].value == 'file' || resource[:type].value == 'concat' @@ -23,8 +23,8 @@ line: value_token.line, column: value_token.column, token: value_token, - description: 'Check the tokens of each File resource instance for a mode parameter '\ - 'and if found, record a warning if the value of that parameter is not a quoted string.', + description: 'Check the tokens of each File resource instance for a mode parameter ' \ + 'and if found, record a warning if the value of that parameter is not a quoted string.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#file-modes', ) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb 2024-02-12 13:18:23.000000000 +0000 @@ -3,9 +3,9 @@ # each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#quoting -PuppetLint.new_check(:double_quoted_strings) do - ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze +ESCAPE_CHAR_RE = %r{(\\\$|\\"|\\'|'|\r|\t|\\t|\\s|\n|\\n|\\\\)}.freeze +PuppetLint.new_check(:double_quoted_strings) do def check invalid_tokens = tokens.select do |token| token.type == :STRING && @@ -19,8 +19,8 @@ line: token.line, column: token.column, token: token, - description: 'Check the manifest tokens for any double quoted strings that don\'t '\ - 'contain any variables or common escape characters and record a warning for each instance found.', + description: 'Check the manifest tokens for any double quoted strings that don\'t ' \ + 'contain any variables or common escape characters and record a warning for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting', ) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/only_variable_string.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/only_variable_string.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/only_variable_string.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/only_variable_string.rb 2024-02-12 13:18:23.000000000 +0000 @@ -2,9 +2,9 @@ # a single variable only and record a warning for each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#quoting -PuppetLint.new_check(:only_variable_string) do - VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +PuppetLint.new_check(:only_variable_string) do def check tokens.each_with_index do |start_token, start_token_idx| next unless start_token.type == :DQPRE && start_token.value == '' @@ -20,9 +20,8 @@ eos_offset += 3 when :DQPOST if eos_token.value == '' - if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW - break - end + break if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW + notify( :warning, message: 'string containing only a variable', diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb 2024-02-12 13:18:23.000000000 +0000 @@ -3,10 +3,10 @@ # found. # # No style guide reference -PuppetLint.new_check(:quoted_booleans) do - STRING_TYPES = Set[:STRING, :SSTRING] - BOOLEANS = Set['true', 'false'] +STRING_TYPES = Set[:STRING, :SSTRING] +BOOLEANS = Set['true', 'false'] +PuppetLint.new_check(:quoted_booleans) do def check invalid_tokens = tokens.select do |token| STRING_TYPES.include?(token.type) && BOOLEANS.include?(token.value) @@ -29,4 +29,4 @@ problem[:token].type = problem[:token].value.upcase.to_sym end end -PuppetLint.configuration.send('disable_quoted_booleans') +PuppetLint.configuration.send(:disable_quoted_booleans) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb 2024-02-12 13:18:23.000000000 +0000 @@ -14,8 +14,8 @@ message: 'single quoted string containing a variable found', line: token.line, column: token.column, - description: 'Check the manifest tokens for any single quoted strings containing '\ - 'a enclosed variable and record an error for each instance found.', + description: 'Check the manifest tokens for any single quoted strings containing ' \ + 'a enclosed variable and record an error for each instance found.', help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#quoting', ) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb 2024-02-12 13:18:23.000000000 +0000 @@ -6,14 +6,14 @@ # found. # # https://puppet.com/docs/puppet/latest/style_guide.html#quoting -PuppetLint.new_check(:variables_not_enclosed) do - STRING_TOKEN_TYPES = Set[ - :DQMID, - :DQPOST, - :HEREDOC_MID, - :HEREDOC_POST, - ] +STRING_TOKEN_TYPES = Set[ + :DQMID, + :DQPOST, + :HEREDOC_MID, + :HEREDOC_POST, +] +PuppetLint.new_check(:variables_not_enclosed) do def check invalid_tokens = tokens.select do |token| token.type == :UNENC_VARIABLE @@ -74,6 +74,7 @@ var_token.value = var_name return if str_token.nil? + str_token.value = "-#{text}#{str_token.value}" end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb 2024-02-12 13:18:23.000000000 +0000 @@ -2,16 +2,16 @@ # record a warning for each instance found. # # No style guide reference -PuppetLint.new_check(:variable_contains_dash) do - VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +PuppetLint.new_check(:variable_contains_dash) do def check invalid_tokens = tokens.select do |token| VARIABLE_DASH_TYPES.include?(token.type) end invalid_tokens.each do |token| - next unless %r{-}.match?(token.value.gsub(%r{\[.+?\]}, '')) + next unless token.value.gsub(%r{\[.+?\]}, '').include?('-') notify( :warning, diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb 2024-02-12 13:18:23.000000000 +0000 @@ -2,9 +2,9 @@ # letter and record a warning for each instance found. # # No style guide reference -PuppetLint.new_check(:variable_is_lowercase) do - VARIABLE_LOWERCASE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +VARIABLE_LOWERCASE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] +PuppetLint.new_check(:variable_is_lowercase) do def check invalid_tokens = tokens.select do |token| VARIABLE_LOWERCASE_TYPES.include?(token.type) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/140chars.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/140chars.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/140chars.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/140chars.rb 2024-02-12 13:18:23.000000000 +0000 @@ -10,6 +10,7 @@ result = PuppetLint::LineLengthCheck.check(idx + 1, line, 140) next if result.nil? + notify(*result) end end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/80chars.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/80chars.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/80chars.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/80chars.rb 2024-02-12 13:18:23.000000000 +0000 @@ -9,8 +9,9 @@ result = PuppetLint::LineLengthCheck.check(idx + 1, line, 80) next if result.nil? + notify(*result) end end end -PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send(:disable_80chars) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb 2024-02-12 13:18:23.000000000 +0000 @@ -2,9 +2,9 @@ # are not aligned with other arrows in that grouping. # # https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace -PuppetLint.new_check(:arrow_alignment) do - COMMENT_TYPES = Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT] +COMMENT_TYPES = Set[:COMMENT, :SLASH_COMMENT, :MLCOMMENT] +PuppetLint.new_check(:arrow_alignment) do def check resource_indexes.each do |res_idx| arrow_column = [0] @@ -24,7 +24,8 @@ next if resource_tokens[first_arrow].line == resource_tokens[last_arrow].line resource_tokens.each do |token| - if token.type == :FARROW + case token.type + when :FARROW param_token = token.prev_code_token if param_token.type == :DQPOST @@ -54,17 +55,15 @@ this_arrow_column += 1 end - if arrow_column[level_idx] < this_arrow_column - arrow_column[level_idx] = this_arrow_column - end + arrow_column[level_idx] = this_arrow_column if arrow_column[level_idx] < this_arrow_column (level_tokens[level_idx] ||= []) << token - elsif token.type == :LBRACE + when :LBRACE level_idx += 1 arrow_column << 0 level_tokens[level_idx] ||= [] param_column << nil - elsif token.type == :RBRACE || token.type == :SEMIC + when :RBRACE, :SEMIC if (level_tokens[level_idx] ||= []).map(&:line).uniq.length > 1 level_tokens[level_idx].each do |arrow_tok| next if arrow_tok.column == arrow_column[level_idx] || level_tokens[level_idx].size == 1 @@ -117,7 +116,8 @@ new_ws_len += (problem[:arrow_column] - problem[:token].column) end - raise PuppetLint::NoFix if new_ws_len < 0 + raise PuppetLint::NoFix if new_ws_len.negative? + new_ws = ' ' * new_ws_len if problem[:token].prev_token.type == :WHITESPACE diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb 2024-02-12 13:18:23.000000000 +0000 @@ -2,9 +2,9 @@ # characters and record an error for each instance found. # # https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace -PuppetLint.new_check(:hard_tabs) do - WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE] +WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE] +PuppetLint.new_check(:hard_tabs) do def check invalid_tokens = tokens.select do |token| WHITESPACE_TYPES.include?(token.type) && token.value.include?("\t") diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/line_length.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/line_length.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/line_length.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/line_length.rb 2024-02-12 13:18:23.000000000 +0000 @@ -9,7 +9,7 @@ # @param content [String] The content of the current line. # @param character_count [Integer] The maximum number of characters allowed # - # @return problem [Array] An array containing a description of the problem. + # @return [Array] An array containing a description of the problem. # Can be passed directly to notify.. def self.check(line_number, content, character_count) return if content.include? '://' @@ -18,12 +18,12 @@ [ :warning, - message: "line has more than #{character_count} characters", - line: line_number, - column: character_count, - description: 'Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. '\ - 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', - help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace', + { message: "line has more than #{character_count} characters", + line: line_number, + column: character_count, + description: "Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. " \ + 'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.', + help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace' }, ] end end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb 2024-02-12 13:18:23.000000000 +0000 @@ -30,7 +30,7 @@ prev_token = problem[:token].prev_token next_token = problem[:token].next_token - prev_token.next_token = next_token + prev_token.next_token = next_token unless prev_token.nil? next_token.prev_token = prev_token unless next_token.nil? tokens.delete(problem[:token]) end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb 1970-01-01 00:00:00.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb 2024-02-12 13:18:23.000000000 +0000 @@ -0,0 +1,191 @@ +# Public: A puppet-lint custom check to detect legacy facts. +# +# This check will optionally convert from legacy facts like $::operatingsystem +# or legacy hashed facts like $facts['operatingsystem'] to the +# new structured facts like $facts['os']['name']. +# +# This plugin was adopted in to puppet-lint from https://github.com/mmckinst/puppet-lint-legacy_facts-check +# Thanks to @mmckinst, @seanmil, @rodjek, @baurmatt, @bart2 and @joshcooper for the original work. +LEGACY_FACTS_VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] + +# These facts that can't be converted to new facts. +UNCONVERTIBLE_FACTS = ['memoryfree_mb', 'memorysize_mb', 'swapfree_mb', + 'swapsize_mb', 'blockdevices', 'interfaces', 'zones', + 'sshfp_dsa', 'sshfp_ecdsa', 'sshfp_ed25519', + 'sshfp_rsa'].freeze + +# These facts will depend on how a system is set up and can't just be +# enumerated like the EASY_FACTS below. +# +# For example a server might have two block devices named 'sda' and 'sdb' so +# there would be a $blockdeivce_sda_vendor and $blockdeivce_sdb_vendor fact +# for each device. Or it could have 26 block devices going all the way up to +# 'sdz'. There is no way to know what the possibilities are so we have to use +# a regex to match them. +REGEX_FACTS = [%r{^blockdevice_(?.*)_(?model|size|vendor)$}, + %r{^(?ipaddress|ipaddress6|macaddress|mtu|netmask|netmask6|network|network6)_(?.*)$}, + %r{^processor(?[0-9]+)$}, + %r{^sp_(?.*)$}, + %r{^ssh(?dsa|ecdsa|ed25519|rsa)key$}, + %r{^ldom_(?.*)$}, + %r{^zone_(?.*)_(?brand|iptype|name|uuid|id|path|status)$}].freeze + +# These facts have a one to one correlation between a legacy fact and a new +# structured fact. +EASY_FACTS = { + 'architecture' => "facts['os']['architecture']", + 'augeasversion' => "facts['augeas']['version']", + 'bios_release_date' => "facts['dmi']['bios']['release_date']", + 'bios_vendor' => "facts['dmi']['bios']['vendor']", + 'bios_version' => "facts['dmi']['bios']['version']", + 'boardassettag' => "facts['dmi']['board']['asset_tag']", + 'boardmanufacturer' => "facts['dmi']['board']['manufacturer']", + 'boardproductname' => "facts['dmi']['board']['product']", + 'boardserialnumber' => "facts['dmi']['board']['serial_number']", + 'chassisassettag' => "facts['dmi']['chassis']['asset_tag']", + 'chassistype' => "facts['dmi']['chassis']['type']", + 'domain' => "facts['networking']['domain']", + 'fqdn' => "facts['networking']['fqdn']", + 'gid' => "facts['identity']['group']", + 'hardwareisa' => "facts['processors']['isa']", + 'hardwaremodel' => "facts['os']['hardware']", + 'hostname' => "facts['networking']['hostname']", + 'id' => "facts['identity']['user']", + 'ipaddress' => "facts['networking']['ip']", + 'ipaddress6' => "facts['networking']['ip6']", + 'lsbdistcodename' => "facts['os']['distro']['codename']", + 'lsbdistdescription' => "facts['os']['distro']['description']", + 'lsbdistid' => "facts['os']['distro']['id']", + 'lsbdistrelease' => "facts['os']['distro']['release']['full']", + 'lsbmajdistrelease' => "facts['os']['distro']['release']['major']", + 'lsbminordistrelease' => "facts['os']['distro']['release']['minor']", + 'lsbrelease' => "facts['os']['distro']['release']['specification']", + 'macaddress' => "facts['networking']['mac']", + 'macosx_buildversion' => "facts['os']['macosx']['build']", + 'macosx_productname' => "facts['os']['macosx']['product']", + 'macosx_productversion' => "facts['os']['macosx']['version']['full']", + 'macosx_productversion_major' => "facts['os']['macosx']['version']['major']", + 'macosx_productversion_minor' => "facts['os']['macosx']['version']['minor']", + 'manufacturer' => "facts['dmi']['manufacturer']", + 'memoryfree' => "facts['memory']['system']['available']", + 'memorysize' => "facts['memory']['system']['total']", + 'netmask' => "facts['networking']['netmask']", + 'netmask6' => "facts['networking']['netmask6']", + 'network' => "facts['networking']['network']", + 'network6' => "facts['networking']['network6']", + 'operatingsystem' => "facts['os']['name']", + 'operatingsystemmajrelease' => "facts['os']['release']['major']", + 'operatingsystemrelease' => "facts['os']['release']['full']", + 'osfamily' => "facts['os']['family']", + 'physicalprocessorcount' => "facts['processors']['physicalcount']", + 'processorcount' => "facts['processors']['count']", + 'productname' => "facts['dmi']['product']['name']", + 'rubyplatform' => "facts['ruby']['platform']", + 'rubysitedir' => "facts['ruby']['sitedir']", + 'rubyversion' => "facts['ruby']['version']", + 'selinux' => "facts['os']['selinux']['enabled']", + 'selinux_config_mode' => "facts['os']['selinux']['config_mode']", + 'selinux_config_policy' => "facts['os']['selinux']['config_policy']", + 'selinux_current_mode' => "facts['os']['selinux']['current_mode']", + 'selinux_enforced' => "facts['os']['selinux']['enforced']", + 'selinux_policyversion' => "facts['os']['selinux']['policy_version']", + 'serialnumber' => "facts['dmi']['product']['serial_number']", + 'swapencrypted' => "facts['memory']['swap']['encrypted']", + 'swapfree' => "facts['memory']['swap']['available']", + 'swapsize' => "facts['memory']['swap']['total']", + 'system32' => "facts['os']['windows']['system32']", + 'uptime' => "facts['system_uptime']['uptime']", + 'uptime_days' => "facts['system_uptime']['days']", + 'uptime_hours' => "facts['system_uptime']['hours']", + 'uptime_seconds' => "facts['system_uptime']['seconds']", + 'uuid' => "facts['dmi']['product']['uuid']", + 'xendomains' => "facts['xen']['domains']", + 'zonename' => "facts['solaris_zones']['current']" +}.freeze + +# A list of valid hash key token types +HASH_KEY_TYPES = Set[ + :STRING, # Double quoted string + :SSTRING, # Single quoted string + :NAME, # Unquoted single word +].freeze + +PuppetLint.new_check(:legacy_facts) do + def check + tokens.select { |x| LEGACY_FACTS_VAR_TYPES.include?(x.type) }.each do |token| + fact_name = '' + + # This matches legacy facts defined in the fact hash. + if (match = token.value.match(%r{^(?:::)?facts\[(?'?)(?.+)\k\]$})) + fact_name = match[:value] + + # This matches using legacy facts in a the new structured fact. For + # example this would match 'uuid' in $facts['uuid'] so it can be converted + # to facts['dmi']['product']['uuid']" + elsif token.value == 'facts' + fact_name = hash_key_for(token) + + # Now we can get rid of top scopes. We don't need to + # preserve it because it won't work with the new structured facts. + elsif token.value.start_with?('::') + fact_name = token.value.sub(%r{^::}, '') + end + + next unless EASY_FACTS.include?(fact_name) || UNCONVERTIBLE_FACTS.include?(fact_name) || fact_name.match(Regexp.union(REGEX_FACTS)) + + notify :warning, { + message: "legacy fact '#{fact_name}'", + line: token.line, + column: token.column, + token: token, + fact_name: fact_name + } + end + end + + # If the variable is using the $facts hash represented internally by multiple + # tokens, this helper simplifies accessing the hash key. + def hash_key_for(token) + lbrack_token = token.next_code_token + return '' unless lbrack_token && lbrack_token.type == :LBRACK + + key_token = lbrack_token.next_code_token + return '' unless key_token && HASH_KEY_TYPES.include?(key_token.type) + + key_token.value + end + + def fix(problem) + fact_name = problem[:fact_name] + + # Check if the variable is using the $facts hash represented internally by + # multiple tokens and remove the tokens for the old legacy key if so. + if problem[:token].value == 'facts' + loop do + t = problem[:token].next_token + remove_token(t) + break if t.type == :RBRACK + end + end + + if EASY_FACTS.include?(fact_name) + problem[:token].value = EASY_FACTS[fact_name] + elsif fact_name.match(Regexp.union(REGEX_FACTS)) + if (m = fact_name.match(%r{^blockdevice_(?.*)_(?model|size|vendor)$})) + problem[:token].value = "facts['disks']['" << m['devicename'] << "']['" << m['attribute'] << "']" + elsif (m = fact_name.match(%r{^(?ipaddress|ipaddress6|macaddress|mtu|netmask|netmask6|network|network6)_(?.*)$})) + problem[:token].value = "facts['networking']['interfaces']['" << m['interface'] << "']['" << m['attribute'].sub('address', '') << "']" + elsif (m = fact_name.match(%r{^processor(?[0-9]+)$})) + problem[:token].value = "facts['processors']['models'][" << m['id'] << ']' + elsif (m = fact_name.match(%r{^sp_(?.*)$})) + problem[:token].value = "facts['system_profiler']['" << m['name'] << "']" + elsif (m = fact_name.match(%r{^ssh(?dsa|ecdsa|ed25519|rsa)key$})) + problem[:token].value = "facts['ssh']['" << m['algorithm'] << "']['key']" + elsif (m = fact_name.match(%r{^ldom_(?.*)$})) + problem[:token].value = "facts['ldom']['" << m['name'] << "']" + elsif (m = fact_name.match(%r{^zone_(?.*)_(?brand|iptype|name|uuid|id|path|status)$})) + problem[:token].value = "facts['solaris_zones']['zones']['" << m['name'] << "']['" << m['attribute'] << "']" + end + end + end +end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb puppet-lint-4.2.4/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb 1970-01-01 00:00:00.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb 2024-02-12 13:18:23.000000000 +0000 @@ -0,0 +1,57 @@ +# Public: A puppet-lint plugin that will check for the use of top scope facts. +# For example, the fact `$facts['kernel']` should be used over +# `$::kernel`. +# +# The check only finds facts using the top-scope: ie it will find $::operatingsystem +# but not $operatingsystem. It also all top scope variables are facts. +# If you have top scope variables that aren't facts you should configure the +# linter to ignore them. +# +# You can allowlist top scope variables to ignore via the Rake task. +# You should insert the following line to your Rakefile. +# `PuppetLint.configuration.top_scope_variables = ['location', 'role']` +# +# This plugin was adopted in to puppet-lint from https://github.com/mmckinst/puppet-lint-top_scope_facts-check +# Thanks to @mmckinst, @seanmil and @alexjfisher for the original work. +TOP_SCOPE_FACTS_VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE] + +PuppetLint.new_check(:top_scope_facts) do + def check + allowlist = ['trusted', 'facts', 'architecture', 'augeasversion', 'bios_release_date', 'bios_vendor', 'bios_version', + 'boardassettag', 'boardmanufacturer', 'boardproductname', 'boardserialnumber', 'chassisassettag', 'chassistype', 'domain', + 'fqdn', 'gid', 'hardwareisa', 'hardwaremodel', 'hostname', 'id', 'ipaddress', 'ipaddress6', 'lsbdistcodename', + 'lsbdistdescription', 'lsbdistid', 'lsbdistrelease', 'lsbmajdistrelease', 'lsbminordistrelease', 'lsbrelease', + 'macaddress', 'macosx_buildversion', 'macosx_productname', 'macosx_productversion', 'macosx_productversion_major', + 'macosx_productversion_minor', 'manufacturer', 'memoryfree', 'memorysize', 'netmask', 'netmask6', 'network', 'network6', + 'operatingsystem', 'operatingsystemmajrelease', 'operatingsystemrelease', 'osfamily', 'physicalprocessorcount', + 'processorcount', 'productname', 'rubyplatform', 'rubysitedir', 'rubyversion', 'selinux', 'selinux_config_mode', + 'selinux_config_policy', 'selinux_current_mode', 'selinux_enforced', 'selinux_policyversion', 'serialnumber', + 'swapencrypted', 'swapfree', 'swapsize', 'system32', 'uptime', 'uptime_days', 'uptime_hours', 'uptime_seconds', + 'uuid', 'xendomains', 'zonename'] + (PuppetLint.configuration.top_scope_variables || []) + allowlist = allowlist.join('|') + tokens.select { |x| TOP_SCOPE_FACTS_VAR_TYPES.include?(x.type) }.each do |token| + next unless %r{^::}.match?(token.value) + next if %r{^::(#{allowlist})\[?}.match?(token.value) + next if %r{^::[a-z0-9_][a-zA-Z0-9_]+::}.match?(token.value) + + notify :warning, { + message: 'top scope fact instead of facts hash', + line: token.line, + column: token.column, + token: token + } + end + end + + def fix(problem) + problem[:token].value.sub!(%r{^::}, '') + # checks if the fact is a top level structured fact e.g. ::my_structured_fact['foo']['bar'] + if %r{\[.*}.match?(problem[:token].value) + fact_name = problem[:token].value.sub(%r{\[.*}, '') + nested_facts = problem[:token].value.scan(%r{\[.*}).first + problem[:token].value = "facts['" + fact_name + "']" + nested_facts + else + problem[:token].value = "facts['" + problem[:token].value + "']" + end + end +end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/plugins.rb puppet-lint-4.2.4/lib/puppet-lint/plugins.rb --- puppet-lint-3.0.1/lib/puppet-lint/plugins.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/plugins.rb 2024-02-12 13:18:23.000000000 +0000 @@ -55,9 +55,8 @@ def load_prerelease_plugins? # Load prerelease plugins (which ruby defines as any gem which has a letter in its version number). # Can't use puppet-lint configuration object here because this code executes before the command line is parsed. - if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'] - return ['true', 'yes'].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase) - end + return ['true', 'yes'].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase) if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'] + false end @@ -76,7 +75,7 @@ end end -Dir[File.expand_path('plugins/**/*.rb', File.dirname(__FILE__))].each do |file| +Dir[File.expand_path('plugins/**/*.rb', File.dirname(__FILE__))].sort.each do |file| require file end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/report/codeclimate.rb puppet-lint-4.2.4/lib/puppet-lint/report/codeclimate.rb --- puppet-lint-3.0.1/lib/puppet-lint/report/codeclimate.rb 1970-01-01 00:00:00.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/report/codeclimate.rb 2024-02-12 13:18:23.000000000 +0000 @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'digest' +require 'json' + +# rubocop:disable Style/ClassAndModuleChildren +class PuppetLint::Report + # Formats problems and writes them to a file as a code climate compatible report. + class CodeClimateReporter + def self.write_report_file(problems, report_file) + report = [] + problems.each do |messages| + messages.each do |message| + case message[:kind] + when :warning + severity = 'minor' + when :error + severity = 'major' + else + next + end + + issue = { + type: :issue, + check_name: message[:check], + description: message[:message], + categories: [:Style], + severity: severity, + location: { + path: message[:path], + lines: { + begin: message[:line], + end: message[:line] + } + } + } + + issue[:fingerprint] = Digest::MD5.hexdigest(Marshal.dump(issue)) + + if message.key?(:description) && message.key?(:help_uri) + issue[:content] = "#{message[:description].chomp('.')}. See [this page](#{message[:help_uri]}) for more information about the `#{message[:check]}` check." + end + report << issue + end + end + File.write(report_file, "#{JSON.pretty_generate(report)}\n") + end + end +end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/report/github.rb puppet-lint-4.2.4/lib/puppet-lint/report/github.rb --- puppet-lint-3.0.1/lib/puppet-lint/report/github.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/report/github.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Style/ClassAndModuleChildren class PuppetLint::Report # This formatter formats report data as GitHub Workflow commands resulting # in GitHub check annotations when run within GitHub Actions. diff -Nru puppet-lint-3.0.1/lib/puppet-lint/tasks/puppet-lint.rb puppet-lint-4.2.4/lib/puppet-lint/tasks/puppet-lint.rb --- puppet-lint-3.0.1/lib/puppet-lint/tasks/puppet-lint.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/tasks/puppet-lint.rb 2024-02-12 13:18:23.000000000 +0000 @@ -4,6 +4,7 @@ require 'puppet-lint/optparser' require 'rake' require 'rake/tasklib' +require 'puppet-lint/report/codeclimate' # Public: A Rake task that can be loaded and used with everything you need. # @@ -11,24 +12,12 @@ # # require 'puppet-lint' # PuppetLint::RakeTask.new -class PuppetLint::RakeTask < ::Rake::TaskLib +class PuppetLint::RakeTask < Rake::TaskLib include ::Rake::DSL if defined?(::Rake::DSL) DEFAULT_PATTERN = '**/*.pp'.freeze - attr_accessor :name - attr_accessor :pattern - attr_accessor :ignore_paths - attr_accessor :with_filename - attr_accessor :disable_checks - attr_accessor :only_checks - attr_accessor :fail_on_warnings - attr_accessor :error_level - attr_accessor :log_format - attr_accessor :with_context - attr_accessor :fix - attr_accessor :show_ignored - attr_accessor :relative + attr_accessor :name, :pattern, :ignore_paths, :with_filename, :disable_checks, :only_checks, :fail_on_warnings, :error_level, :log_format, :with_context, :fix, :show_ignored, :relative # Public: Initialise a new PuppetLint::RakeTask. # @@ -63,46 +52,45 @@ enable_checks = Array(@only_checks).map(&:to_sym) PuppetLint.configuration.checks.each do |check| if enable_checks.include?(check) - PuppetLint.configuration.send("enable_#{check}") + PuppetLint.configuration.send(:"enable_#{check}") else - PuppetLint.configuration.send("disable_#{check}") + PuppetLint.configuration.send(:"disable_#{check}") end end end Array(@disable_checks).each do |check| - PuppetLint.configuration.send("disable_#{check}") + PuppetLint.configuration.send(:"disable_#{check}") end ['with_filename', 'fail_on_warnings', 'error_level', 'log_format', 'with_context', 'fix', 'show_ignored', 'relative'].each do |config| - value = instance_variable_get("@#{config}") + value = instance_variable_get(:"@#{config}") PuppetLint.configuration.send("#{config}=".to_sym, value) unless value.nil? end - if PuppetLint.configuration.ignore_paths && @ignore_paths.empty? - @ignore_paths = PuppetLint.configuration.ignore_paths - end + @ignore_paths = PuppetLint.configuration.ignore_paths if PuppetLint.configuration.ignore_paths && @ignore_paths.empty? - if PuppetLint.configuration.pattern - @pattern = PuppetLint.configuration.pattern - end + @pattern = PuppetLint.configuration.pattern if PuppetLint.configuration.pattern RakeFileUtils.send(:verbose, true) do linter = PuppetLint.new matched_files = FileList[@pattern] + all_problems = [] matched_files = matched_files.exclude(*@ignore_paths) matched_files.to_a.each do |puppet_file| next unless File.file?(puppet_file) + linter.file = puppet_file linter.run - linter.print_problems + all_problems << linter.print_problems - if PuppetLint.configuration.fix && linter.problems.none? { |e| e[:check] == :syntax } - IO.write(puppet_file, linter.manifest) - end + File.write(puppet_file, linter.manifest) if PuppetLint.configuration.fix && linter.problems.none? { |e| e[:check] == :syntax } end + + PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) if PuppetLint.configuration.codeclimate_report_file + abort if linter.errors? || ( linter.warnings? && PuppetLint.configuration.fail_on_warnings ) diff -Nru puppet-lint-3.0.1/lib/puppet-lint/tasks/release_test.rb puppet-lint-4.2.4/lib/puppet-lint/tasks/release_test.rb --- puppet-lint-3.0.1/lib/puppet-lint/tasks/release_test.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/tasks/release_test.rb 2024-02-12 13:18:23.000000000 +0000 @@ -27,7 +27,7 @@ [output.strip, status.success?] end -def with_puppet_lint_head +def with_puppet_lint_head(&block) print(' Updating Gemfile to use puppet-lint HEAD... ') buffer = Parser::Source::Buffer.new('Gemfile') @@ -49,7 +49,7 @@ puts 'Done' - Bundler.with_clean_env { yield } + Bundler.with_clean_env(&block) run_cmd('Restoring Gemfile', 'git', 'checkout', '--', 'Gemfile') end @@ -58,9 +58,9 @@ branch = if ENV['GITHUB_REF'] ENV['GITHUB_REF'] elsif ENV['APPVEYOR'] - ENV['APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH'] + ENV.fetch('APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH', nil) elsif ENV['TRAVIS'] - ENV['TRAVIS_PULL_REQUEST_BRANCH'] + ENV.fetch('TRAVIS_PULL_REQUEST_BRANCH', nil) else false end diff -Nru puppet-lint-3.0.1/lib/puppet-lint/version.rb puppet-lint-4.2.4/lib/puppet-lint/version.rb --- puppet-lint-3.0.1/lib/puppet-lint/version.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint/version.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,3 +1,3 @@ class PuppetLint - VERSION = '3.0.1'.freeze + VERSION = '4.2.4'.freeze end diff -Nru puppet-lint-3.0.1/lib/puppet-lint.rb puppet-lint-4.2.4/lib/puppet-lint.rb --- puppet-lint-3.0.1/lib/puppet-lint.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/lib/puppet-lint.rb 2024-02-12 13:18:23.000000000 +0000 @@ -95,7 +95,7 @@ # Check if the input is an SE Linux policy package file (which also use # the .pp extension), which all have the first 4 bytes 0xf97cff8f. - @code = '' if @code[0..3].unpack('V').first == 0xf97cff8f + @code = '' if @code[0..3].unpack1('V') == 0xf97cff8f end # Internal: Retrieve the format string to be used when writing problems to @@ -124,6 +124,7 @@ puts format % message puts " #{message[:reason]}" if message[:kind] == :ignored && !message[:reason].nil? + print_context(message) end # Internal: Format a problem message and print it to STDOUT so GitHub Actions @@ -154,7 +155,10 @@ def print_context(message) return if message[:check] == 'documentation' return if message[:kind] == :fixed - line = get_context(message) + + line = message[:context] + return unless line + offset = line.index(%r{\S}) || 1 puts "\n #{line.strip}" printf("%#{message[:column] + 2 - offset}s\n\n", '^') @@ -168,6 +172,8 @@ # Returns array of problem. def report(problems) json = [] + print_stdout = !(configuration.json || configuration.sarif) + problems.each do |message| next if message[:kind] == :ignored && !PuppetLint.configuration.show_ignored @@ -175,16 +181,16 @@ next unless message[:kind] == :fixed || [message[:kind], :all].include?(configuration.error_level) - if configuration.json || configuration.sarif - message['context'] = get_context(message) if configuration.with_context - json << message - else + message[:context] = get_context(message) if configuration.with_context + + json << message + + if print_stdout format_message(message) - print_context(message) if configuration.with_context print_github_annotation(message) if configuration.github_actions end end - $stderr.puts 'Try running `puppet parser validate `' if problems.any? { |p| p[:check] == :syntax } + warn 'Try running `puppet parser validate `' if problems.any? { |p| p[:check] == :syntax } json end @@ -225,7 +231,7 @@ # Public: Print any problems that were found out to stdout. # - # Returns nothing. + # Returns an array of problems. def print_problems report(@problems) end @@ -246,8 +252,8 @@ # end def self.new_check(name, &block) class_name = name.to_s.split('_').map(&:capitalize).join - klass = PuppetLint.const_set("Check#{class_name}", Class.new(PuppetLint::CheckPlugin)) - klass.const_set('NAME', name) + klass = PuppetLint.const_set(:"Check#{class_name}", Class.new(PuppetLint::CheckPlugin)) + klass.const_set(:NAME, name) klass.class_exec(&block) PuppetLint.configuration.add_check(name, klass) PuppetLint::Data.ignore_overrides[name] ||= {} diff -Nru puppet-lint-3.0.1/puppet-lint.gemspec puppet-lint-4.2.4/puppet-lint.gemspec --- puppet-lint-3.0.1/puppet-lint.gemspec 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/puppet-lint.gemspec 2024-02-12 13:18:23.000000000 +0000 @@ -2,23 +2,23 @@ # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- -# stub: puppet-lint 3.0.1 ruby lib +# stub: puppet-lint 4.2.4 ruby lib Gem::Specification.new do |s| s.name = "puppet-lint".freeze - s.version = "3.0.1" + s.version = "4.2.4" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Tim Sharpe".freeze, "Puppet, Inc.".freeze, "Community Contributors".freeze] - s.date = "2022-10-20" - s.description = " Checks your Puppet manifests against the Puppetlabs style guide and alerts you to any discrepancies.'\n".freeze + s.date = "2024-02-09" + s.description = " Checks your Puppet manifests against the Puppetlabs style guide and alerts you to any discrepancies.\n".freeze s.email = ["tim@sharpe.id.au".freeze, "modules-team@puppet.com".freeze] s.executables = ["puppet-lint".freeze] - s.files = [".rubocop.yml".freeze, "LICENSE".freeze, "README.md".freeze, "bin/puppet-lint".freeze, "lib/puppet-lint.rb".freeze, "lib/puppet-lint/bin.rb".freeze, "lib/puppet-lint/checkplugin.rb".freeze, "lib/puppet-lint/checks.rb".freeze, "lib/puppet-lint/configuration.rb".freeze, "lib/puppet-lint/data.rb".freeze, "lib/puppet-lint/lexer.rb".freeze, "lib/puppet-lint/lexer/string_slurper.rb".freeze, "lib/puppet-lint/lexer/token.rb".freeze, "lib/puppet-lint/monkeypatches.rb".freeze, "lib/puppet-lint/optparser.rb".freeze, "lib/puppet-lint/plugins.rb".freeze, "lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb".freeze, "lib/puppet-lint/plugins/check_classes/autoloader_layout.rb".freeze, "lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb".freeze, "lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb".freeze, "lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb".freeze, "lib/puppet-lint/plugins/check_classes/names_containing_dash.rb".freeze, "lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb".freeze, "lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb".freeze, "lib/puppet-lint/plugins/check_classes/parameter_order.rb".freeze, "lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb".freeze, "lib/puppet-lint/plugins/check_classes/variable_scope.rb".freeze, "lib/puppet-lint/plugins/check_comments/slash_comments.rb".freeze, "lib/puppet-lint/plugins/check_comments/star_comments.rb".freeze, "lib/puppet-lint/plugins/check_conditionals/case_without_default.rb".freeze, "lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb".freeze, "lib/puppet-lint/plugins/check_documentation/documentation.rb".freeze, "lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb".freeze, "lib/puppet-lint/plugins/check_resources/duplicate_params.rb".freeze, "lib/puppet-lint/plugins/check_resources/ensure_first_param.rb".freeze, "lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb".freeze, "lib/puppet-lint/plugins/check_resources/file_mode.rb".freeze, "lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb".freeze, "lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb".freeze, "lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb".freeze, "lib/puppet-lint/plugins/check_strings/only_variable_string.rb".freeze, "lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb".freeze, "lib/puppet-lint/plugins/check_strings/quoted_booleans.rb".freeze, "lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb".freeze, "lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb".freeze, "lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb".freeze, "lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/140chars.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/80chars.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/line_length.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb".freeze, "lib/puppet-lint/report/github.rb".freeze, "lib/puppet-lint/report/sarif_template.json".freeze, "lib/puppet-lint/tasks/gemfile_rewrite.rb".freeze, "lib/puppet-lint/tasks/puppet-lint.rb".freeze, "lib/puppet-lint/tasks/release_test.rb".freeze, "lib/puppet-lint/version.rb".freeze, "spec/acceptance/puppet_lint_spec.rb".freeze, "spec/fixtures/test/manifests/fail.pp".freeze, "spec/fixtures/test/manifests/ignore.pp".freeze, "spec/fixtures/test/manifests/ignore_multiple_block.pp".freeze, "spec/fixtures/test/manifests/ignore_multiple_line.pp".freeze, "spec/fixtures/test/manifests/ignore_reason.pp".freeze, "spec/fixtures/test/manifests/init.pp".freeze, "spec/fixtures/test/manifests/malformed.pp".freeze, "spec/fixtures/test/manifests/mismatched_control_comment.pp".freeze, "spec/fixtures/test/manifests/two_warnings.pp".freeze, "spec/fixtures/test/manifests/unterminated_control_comment.pp".freeze, "spec/fixtures/test/manifests/url_interpolation.pp".freeze, "spec/fixtures/test/manifests/warning.pp".freeze, "spec/spec_helper.rb".freeze, "spec/spec_helper_acceptance.rb".freeze, "spec/spec_helper_acceptance_local.rb".freeze, "spec/unit/puppet-lint/bin_spec.rb".freeze, "spec/unit/puppet-lint/checks_spec.rb".freeze, "spec/unit/puppet-lint/configuration_spec.rb".freeze, "spec/unit/puppet-lint/data_spec.rb".freeze, "spec/unit/puppet-lint/ignore_overrides_spec.rb".freeze, "spec/unit/puppet-lint/lexer/string_slurper_spec.rb".freeze, "spec/unit/puppet-lint/lexer/token_spec.rb".freeze, "spec/unit/puppet-lint/lexer_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb".freeze, "spec/unit/puppet-lint/puppet-lint_spec.rb".freeze] + s.files = ["LICENSE".freeze, "README.md".freeze, "bin/puppet-lint".freeze, "lib/puppet-lint.rb".freeze, "lib/puppet-lint/bin.rb".freeze, "lib/puppet-lint/checkplugin.rb".freeze, "lib/puppet-lint/checks.rb".freeze, "lib/puppet-lint/configuration.rb".freeze, "lib/puppet-lint/data.rb".freeze, "lib/puppet-lint/lexer.rb".freeze, "lib/puppet-lint/lexer/string_slurper.rb".freeze, "lib/puppet-lint/lexer/token.rb".freeze, "lib/puppet-lint/monkeypatches.rb".freeze, "lib/puppet-lint/optparser.rb".freeze, "lib/puppet-lint/plugins.rb".freeze, "lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb".freeze, "lib/puppet-lint/plugins/check_classes/autoloader_layout.rb".freeze, "lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb".freeze, "lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb".freeze, "lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb".freeze, "lib/puppet-lint/plugins/check_classes/names_containing_dash.rb".freeze, "lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb".freeze, "lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb".freeze, "lib/puppet-lint/plugins/check_classes/parameter_order.rb".freeze, "lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb".freeze, "lib/puppet-lint/plugins/check_classes/variable_scope.rb".freeze, "lib/puppet-lint/plugins/check_comments/slash_comments.rb".freeze, "lib/puppet-lint/plugins/check_comments/star_comments.rb".freeze, "lib/puppet-lint/plugins/check_conditionals/case_without_default.rb".freeze, "lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb".freeze, "lib/puppet-lint/plugins/check_documentation/documentation.rb".freeze, "lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb".freeze, "lib/puppet-lint/plugins/check_resources/duplicate_params.rb".freeze, "lib/puppet-lint/plugins/check_resources/ensure_first_param.rb".freeze, "lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb".freeze, "lib/puppet-lint/plugins/check_resources/file_mode.rb".freeze, "lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb".freeze, "lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb".freeze, "lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb".freeze, "lib/puppet-lint/plugins/check_strings/only_variable_string.rb".freeze, "lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb".freeze, "lib/puppet-lint/plugins/check_strings/quoted_booleans.rb".freeze, "lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb".freeze, "lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb".freeze, "lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb".freeze, "lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/140chars.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/80chars.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/line_length.rb".freeze, "lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb".freeze, "lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb".freeze, "lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb".freeze, "lib/puppet-lint/report/codeclimate.rb".freeze, "lib/puppet-lint/report/github.rb".freeze, "lib/puppet-lint/report/sarif_template.json".freeze, "lib/puppet-lint/tasks/gemfile_rewrite.rb".freeze, "lib/puppet-lint/tasks/puppet-lint.rb".freeze, "lib/puppet-lint/tasks/release_test.rb".freeze, "lib/puppet-lint/version.rb".freeze, "rubocop_baseline.yml".freeze, "spec/acceptance/puppet_lint_spec.rb".freeze, "spec/fixtures/test/manifests/fail.pp".freeze, "spec/fixtures/test/manifests/ignore.pp".freeze, "spec/fixtures/test/manifests/ignore_multiple_block.pp".freeze, "spec/fixtures/test/manifests/ignore_multiple_line.pp".freeze, "spec/fixtures/test/manifests/ignore_reason.pp".freeze, "spec/fixtures/test/manifests/init.pp".freeze, "spec/fixtures/test/manifests/malformed.pp".freeze, "spec/fixtures/test/manifests/mismatched_control_comment.pp".freeze, "spec/fixtures/test/manifests/two_warnings.pp".freeze, "spec/fixtures/test/manifests/unterminated_control_comment.pp".freeze, "spec/fixtures/test/manifests/url_interpolation.pp".freeze, "spec/fixtures/test/manifests/warning.pp".freeze, "spec/fixtures/test/reports/code_climate.json".freeze, "spec/spec_helper.rb".freeze, "spec/spec_helper_acceptance.rb".freeze, "spec/spec_helper_acceptance_local.rb".freeze, "spec/unit/puppet-lint/bin_spec.rb".freeze, "spec/unit/puppet-lint/checks_spec.rb".freeze, "spec/unit/puppet-lint/configuration_spec.rb".freeze, "spec/unit/puppet-lint/data_spec.rb".freeze, "spec/unit/puppet-lint/ignore_overrides_spec.rb".freeze, "spec/unit/puppet-lint/lexer/string_slurper_spec.rb".freeze, "spec/unit/puppet-lint/lexer/token_spec.rb".freeze, "spec/unit/puppet-lint/lexer_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb".freeze, "spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb".freeze, "spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb".freeze, "spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb".freeze, "spec/unit/puppet-lint/puppet-lint_spec.rb".freeze] s.homepage = "https://github.com/puppetlabs/puppet-lint/".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.7".freeze) - s.rubygems_version = "3.2.5".freeze + s.rubygems_version = "3.3.15".freeze s.summary = "Ensure your Puppet manifests conform with the Puppetlabs style guide".freeze end diff -Nru puppet-lint-3.0.1/rubocop_baseline.yml puppet-lint-4.2.4/rubocop_baseline.yml --- puppet-lint-3.0.1/rubocop_baseline.yml 1970-01-01 00:00:00.000000000 +0000 +++ puppet-lint-4.2.4/rubocop_baseline.yml 2024-02-12 13:18:23.000000000 +0000 @@ -0,0 +1,90 @@ +--- +require: + - rubocop-performance + - rubocop-rspec +AllCops: + NewCops: enable + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' + DisplayCopNames: true + SuggestExtensions: false + Exclude: + - "bin/*" + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - "pkg/**/*" + - "spec/fixtures/**/*" + - "vendor/**/*" + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +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 +RSpec/DescribeSymbol: + Exclude: + - spec/unit/facter/**/*.rb +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +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: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +#################################################### +# Cops below here due for deprecation +#################################################### +# ``Rspec/FilePath`` is going to be deprecated in the next major release of rubocop >=3.0.0: see +# As the new cops are already present, e.g., Rspec/SpecFilePathPathFormat, then disabling this in preparation +RSpec/FilePath: + Enabled: false diff -Nru puppet-lint-3.0.1/spec/fixtures/test/reports/code_climate.json puppet-lint-4.2.4/spec/fixtures/test/reports/code_climate.json --- puppet-lint-3.0.1/spec/fixtures/test/reports/code_climate.json 1970-01-01 00:00:00.000000000 +0000 +++ puppet-lint-4.2.4/spec/fixtures/test/reports/code_climate.json 2024-02-12 13:18:23.000000000 +0000 @@ -0,0 +1,38 @@ +[ + { + "type": "issue", + "check_name": "autoloader_layout", + "description": "test::foo not in autoload module layout", + "categories": [ + "Style" + ], + "severity": "major", + "location": { + "path": "spec/fixtures/test/manifests/fail.pp", + "lines": { + "begin": 2, + "end": 2 + } + }, + "fingerprint": "f12bce7a776454ab9ffac2d20dcc34ba", + "content": "Test the manifest tokens for any classes or defined types that are not in an appropriately named file for the autoloader to detect and record an error of each instance found. See [this page](https://puppet.com/docs/puppet/latest/style_guide.html#separate-files) for more information about the `autoloader_layout` check." + }, + { + "type": "issue", + "check_name": "parameter_order", + "description": "optional parameter listed before required parameter", + "categories": [ + "Style" + ], + "severity": "minor", + "location": { + "path": "spec/fixtures/test/manifests/warning.pp", + "lines": { + "begin": 2, + "end": 2 + } + }, + "fingerprint": "e34cf289e008446b633d1be7cf58120e", + "content": "Test the manifest tokens for any parameterised classes or defined types that take parameters and record a warning if there are any optional parameters listed before required parameters. See [this page](https://puppet.com/docs/puppet/latest/style_guide.html#params-display-order) for more information about the `parameter_order` check." + } +] diff -Nru puppet-lint-3.0.1/spec/spec_helper.rb puppet-lint-4.2.4/spec/spec_helper.rb --- puppet-lint-3.0.1/spec/spec_helper.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/spec_helper.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,18 +1,27 @@ # Disable GitHub Actions reporting since it breaks the test suite ENV.delete('GITHUB_ACTION') -if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.7.') - require 'simplecov' - SimpleCov.start do - add_filter('/spec/') - add_filter('/vendor/') - add_group('Checks', 'lib/puppet-lint/plugins') +if ENV['COVERAGE'] == 'yes' + begin + require 'simplecov' + require 'simplecov-console' + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, + ] + + SimpleCov.start do + add_filter('/spec/') + add_filter('/vendor/') + add_group('Checks', 'lib/puppet-lint/plugins') + end + rescue LoadError + raise 'Add the simplecov & simplecov-console gems to Gemfile to enable this task' end end require 'puppet-lint' require 'rspec/its' -require 'rspec/collection_matchers' begin require 'rspec/json_expectations' rescue LoadError, SyntaxError @@ -23,8 +32,8 @@ class HaveProblem def initialize(method, message) @expected_problem = { - kind: method.to_s.gsub(%r{\Acontain_}, '').to_sym, - message: message, + kind: method.to_s.delete_prefix('contain_').to_sym, + message: message } @description = ["contain a #{@expected_problem[:kind]}"] end @@ -100,6 +109,7 @@ def method_missing(method, *args, &block) return HaveProblem.new(method, args.first) if method.to_s.start_with?('contain_') + super end diff -Nru puppet-lint-3.0.1/spec/spec_helper_acceptance_local.rb puppet-lint-4.2.4/spec/spec_helper_acceptance_local.rb --- puppet-lint-3.0.1/spec/spec_helper_acceptance_local.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/spec_helper_acceptance_local.rb 2024-02-12 13:18:23.000000000 +0000 @@ -17,7 +17,7 @@ { stdout: stdout.chomp, stderr: stderr.chomp, - exit_code: status.exitstatus, + exit_code: status.exitstatus } end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/bin_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/bin_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/bin_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/bin_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -89,6 +89,7 @@ end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do is_expected.to eq( [ @@ -145,6 +146,7 @@ end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do is_expected.to match(%r{WARNING}) is_expected.not_to match(%r{ERROR}) @@ -162,13 +164,14 @@ end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.not_to match(%r{ERROR}) is_expected.to match(%r{WARNING}) end end - context 'when asked to display filenames ' do + context 'when asked to display filenames' do let(:args) do [ '--with-filename', @@ -200,6 +203,7 @@ end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq( [ @@ -294,8 +298,9 @@ end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do - is_expected.to match(%r{^(/|[A-Za-z]\:).+/spec/fixtures/test/manifests/fail\.pp$}) + is_expected.to match(%r{^(/|[A-Za-z]:).+/spec/fixtures/test/manifests/fail\.pp$}) end end @@ -374,11 +379,12 @@ end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do if respond_to?(:include_json) is_expected.to include_json([[{ 'KIND' => 'WARNING' }]]) else - is_expected.to match(%r{\[\n \{}) + is_expected.to match(%r{\[\n \[\n \{}) end end end @@ -393,11 +399,12 @@ end its(:exitstatus) { is_expected.to eq(1) } + its(:stdout) do if respond_to?(:include_json) is_expected.to include_json([[{ 'KIND' => 'ERROR' }], [{ 'KIND' => 'WARNING' }]]) else - is_expected.to match(%r{\[\n \{}) + is_expected.to match(%r{\[\n \[\n \{}) end end end @@ -437,6 +444,30 @@ end end + context 'when outputting code climate report' do + let(:report_file) do + Tempfile.new('report_file.json') + end + + let(:args) do + [ + '--codeclimate-report-file', + report_file.path, + 'spec/fixtures/test/manifests/fail.pp', + 'spec/fixtures/test/manifests/warning.pp', + ] + end + + after(:each) do + report_file.unlink + end + + it 'creates a code climate report' do + expect(bin.exitstatus).to eq(1) + expect(FileUtils.compare_file(report_file.path, 'spec/fixtures/test/reports/code_climate.json')).to be_truthy + end + end + context 'when hiding ignored problems' do let(:args) do [ @@ -469,6 +500,7 @@ end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq( [ @@ -591,6 +623,7 @@ end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq('WARNING: variable contains a dash on line 3 (check: variable_contains_dash)') end @@ -605,6 +638,7 @@ end its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) do is_expected.to eq('WARNING: variable contains an uppercase letter on line 4 (check: variable_is_lowercase)') end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/checks_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/checks_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/checks_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/checks_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -31,7 +31,7 @@ end it 'creates a syntax error problem for the file' do - expect(instance.problems).to have(1).problem + expect(instance.problems.size).to eq(1) expect(instance.problems.first).to include( kind: :error, check: :syntax, @@ -53,7 +53,7 @@ end it 'creates a syntax error problem for the file' do - expect(instance.problems).to have(1).problem + expect(instance.problems.size).to eq(1) expect(instance.problems.first).to include( kind: :error, check: :syntax, @@ -148,9 +148,14 @@ it 'prints out information about the puppet-lint version and ruby environment' do expected_info = [ + 'Whoops! It looks like puppet-lint has encountered an error that it doesn\'t', + 'know how to handle. Please open an issue at https://github.com/puppetlabs/puppet-lint', + 'and paste the following output into the issue description.', + '---', "puppet-lint version: #{PuppetLint::VERSION}", "ruby version: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}", "platform: #{RUBY_PLATFORM}", + "file path: #{fileinfo}", ] pattern = expected_info.map { |r| Regexp.escape(r) }.join('\s+') expect($stdout).to receive(:puts).with(a_string_matching(%r{#{pattern}}m)) diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/configuration_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/configuration_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/configuration_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/configuration_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -14,11 +14,11 @@ config.disable_foo expect(config.settings['foo_disabled']).to be_truthy - expect(config.foo_enabled?).to be_falsey + expect(config).not_to be_foo_enabled config.enable_foo expect(config.settings['foo_disabled']).to be_falsey - expect(config.foo_enabled?).to be_truthy + expect(config).to be_foo_enabled end it 'knows what checks have been added' do @@ -41,7 +41,7 @@ end it 'is able to add options on the fly' do - expect(config.test_option).to eq(nil) + expect(config.test_option).to be_nil config.test_option = 'test' @@ -55,17 +55,18 @@ end expect(config.settings).to eq( - 'with_filename' => false, + 'with_filename' => false, 'fail_on_warnings' => false, - 'error_level' => :all, - 'log_format' => '', - 'sarif' => false, - 'with_context' => false, - 'fix' => false, - 'github_actions' => false, - 'show_ignored' => false, - 'json' => false, - 'ignore_paths' => ['vendor/**/*.pp'], + 'codeclimate_report_file' => nil, + 'error_level' => :all, + 'log_format' => '', + 'sarif' => false, + 'with_context' => false, + 'fix' => false, + 'github_actions' => false, + 'show_ignored' => false, + 'json' => false, + 'ignore_paths' => ['vendor/**/*.pp'], ) end @@ -78,6 +79,15 @@ expect(config.settings['github_actions']).to be(true) end + it 'defaults codeclimate_report_file to the CODECLIMATE_REPORT_FILE environment variable' do + override_env do + ENV['CODECLIMATE_REPORT_FILE'] = '/path/to/report.json' + config.defaults + end + + expect(config.settings['codeclimate_report_file']).to eq('/path/to/report.json') + end + def override_env old_env = ENV.to_h yield diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/data_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/data_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/data_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/data_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -33,6 +33,42 @@ } end end + + context 'when given a defaults declaration' do + let(:manifest) { "Service { 'foo': }" } + + it 'returns an empty array' do + expect(data.resource_indexes).to eq([]) + end + end + + context 'when given a set of resource declarations' do + let(:manifest) { <<-MANIFEST } + service { + 'foo': + ensure => running, + } + + service { + 'bar': + ensure => running; + 'foobar': + ensure => stopped; + } + + service { ['first', 'second']: + ensure => running, + } + + service { 'third': + ensure => running, + } + MANIFEST + + it 'returns an array of resource indexes' do + expect(data.resource_indexes.length).to eq(5) + end + end end describe '.insert' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/ignore_overrides_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/ignore_overrides_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/ignore_overrides_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/ignore_overrides_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -13,7 +13,7 @@ end it 'detects three problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'has two warnings' do @@ -36,7 +36,7 @@ end it 'detects three problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'has two warnings' do @@ -62,7 +62,7 @@ end it 'detects four problems' do - expect(problems).to have(4).problems + expect(problems.size).to eq(4) end it 'has two warnings' do @@ -89,7 +89,7 @@ end it 'detects four problems' do - expect(problems).to have(4).problems + expect(problems.size).to eq(4) end it 'has two warnings' do @@ -107,7 +107,7 @@ let(:code) { '"true" # lint:ignore:quoted_booleans lint:ignore:double_quoted_string a reason' } it 'detects 1 problems' do - expect(problems).to have(1).problems + expect(problems.size).to eq(1) end it 'has one ignored problems' do @@ -129,7 +129,7 @@ end it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'ignores both problems' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/lexer/string_slurper_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/lexer/string_slurper_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/lexer/string_slurper_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/lexer/string_slurper_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe PuppetLint::Lexer::StringSlurper do @@ -452,13 +450,13 @@ end describe '#consumed_chars' do - subject { described_class.new(string).tap(&:parse).consumed_chars } + subject(:consumed_chars) { described_class.new(string).tap(&:parse).consumed_chars } context 'when slurping a string containing multibyte characters' do let(:string) { 'accentués"' } it 'counts the multibyte character as a single consumed character' do - is_expected.to eq(10) + expect(consumed_chars).to eq(10) end end @@ -466,7 +464,7 @@ let(:string) { '"' } it 'consumes only the closing quote' do - is_expected.to eq(1) + expect(consumed_chars).to eq(1) end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/lexer_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/lexer_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/lexer_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/lexer_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe PuppetLint::Lexer do @@ -13,7 +11,7 @@ end end - context '#new_token' do + describe '#new_token' do it 'calculates the line number for an empty string' do token = lexer.new_token(:TEST, 'test') expect(token.line).to eq(1) @@ -55,19 +53,19 @@ end it 'calculates the column number for a multi line string' do - lexer.instance_variable_set('@line_no', 4) - lexer.instance_variable_set('@column', 5) + lexer.instance_variable_set(:@line_no, 4) + lexer.instance_variable_set(:@column, 5) lexer.new_token(:SSTRING, "test\ntest") token = lexer.new_token(:TEST, 'test') expect(token.column).to eq(6) end end - context '#process_string_segments' do - subject(:tokens) { lexer.tokens } - + describe '#process_string_segments' do subject(:manifest) { lexer.tokens.map(&:to_manifest).join } + let(:tokens) { lexer.tokens } + before(:each) do lexer.process_string_segments(segments) end @@ -80,12 +78,13 @@ end it 'creates a :STRING token' do - expect(tokens).to have(1).token - expect(tokens[0]).to have_attributes( - type: :STRING, - value: '', - line: 1, - column: 1, + expect(tokens).to contain_exactly( + have_attributes( + type: :STRING, + value: '', + line: 1, + column: 1, + ), ) end @@ -104,24 +103,25 @@ end it 'creates a tokenised string with an interpolated variable' do - expect(tokens).to have(3).tokens - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'foo', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: 'bar', - line: 1, - column: 7, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'foo', + line: 1, + column: 4, + ), + have_attributes( + type: :DQPOST, + value: 'bar', + line: 1, + column: 7, + ), ) end @@ -140,24 +140,25 @@ end it 'creates a tokenised string with an interpolated variable' do - expect(tokens).to have(3).tokens - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: 'foo', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'bar', - line: 1, - column: 7, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: 'baz', - line: 1, - column: 10, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: 'foo', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'bar', + line: 1, + column: 7, + ), + have_attributes( + type: :DQPOST, + value: 'baz', + line: 1, + column: 10, + ), ) end @@ -178,37 +179,37 @@ end it 'creates a tokenised string with the interpolated variables' do - expect(tokens).to have(5).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: 'foo', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'bar', - line: 1, - column: 7, - ) - expect(tokens[2]).to have_attributes( - type: :DQMID, - value: 'baz', - line: 1, - column: 10, - ) - expect(tokens[3]).to have_attributes( - type: :VARIABLE, - value: 'gronk', - line: 1, - column: 16, - ) - expect(tokens[4]).to have_attributes( - type: :DQPOST, - value: 'meh', - line: 1, - column: 21, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: 'foo', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'bar', + line: 1, + column: 7, + ), + have_attributes( + type: :DQMID, + value: 'baz', + line: 1, + column: 10, + ), + have_attributes( + type: :VARIABLE, + value: 'gronk', + line: 1, + column: 16, + ), + have_attributes( + type: :DQPOST, + value: 'meh', + line: 1, + column: 21, + ), ) end @@ -227,25 +228,25 @@ end it 'creates a tokenised string' do - expect(tokens).to have(3).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'foo', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 7, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'foo', + line: 1, + column: 4, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 7, + ), ) end @@ -266,25 +267,25 @@ end it 'creates a tokenised string' do - expect(tokens).to have(3).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: keyword, - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: keyword.size + 4, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: keyword, + line: 1, + column: 4, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: keyword.size + 4, + ), ) end @@ -305,25 +306,25 @@ end it 'creates a tokenised string' do - expect(tokens).to have(3).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'bar', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 8, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'bar', + line: 1, + column: 4, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 8, + ), ) end @@ -342,61 +343,61 @@ end it 'creates a tokenised string' do - expect(tokens).to have(9).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'foo', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :LBRACK, - value: '[', - line: 1, - column: 7, - ) - expect(tokens[3]).to have_attributes( - type: :NAME, - value: 'bar', - line: 1, - column: 8, - ) - expect(tokens[4]).to have_attributes( - type: :RBRACK, - value: ']', - line: 1, - column: 11, - ) - expect(tokens[5]).to have_attributes( - type: :LBRACK, - value: '[', - line: 1, - column: 12, - ) - expect(tokens[6]).to have_attributes( - type: :NAME, - value: 'baz', - line: 1, - column: 13, - ) - expect(tokens[7]).to have_attributes( - type: :RBRACK, - value: ']', - line: 1, - column: 16, - ) - expect(tokens[8]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 17, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'foo', + line: 1, + column: 4, + ), + have_attributes( + type: :LBRACK, + value: '[', + line: 1, + column: 7, + ), + have_attributes( + type: :NAME, + value: 'bar', + line: 1, + column: 8, + ), + have_attributes( + type: :RBRACK, + value: ']', + line: 1, + column: 11, + ), + have_attributes( + type: :LBRACK, + value: '[', + line: 1, + column: 12, + ), + have_attributes( + type: :NAME, + value: 'baz', + line: 1, + column: 13, + ), + have_attributes( + type: :RBRACK, + value: ']', + line: 1, + column: 16, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 17, + ), ) end @@ -417,37 +418,37 @@ end it 'creates a tokenised string' do - expect(tokens).to have(5).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'foo', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :DQMID, - value: '', - line: 1, - column: 7, - ) - expect(tokens[3]).to have_attributes( - type: :VARIABLE, - value: 'bar', - line: 1, - column: 10, - ) - expect(tokens[4]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 13, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'foo', + line: 1, + column: 4, + ), + have_attributes( + type: :DQMID, + value: '', + line: 1, + column: 7, + ), + have_attributes( + type: :VARIABLE, + value: 'bar', + line: 1, + column: 10, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 13, + ), ) end @@ -466,25 +467,25 @@ end it 'creates a tokenised string' do - expect(tokens).to have(3).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :UNENC_VARIABLE, - value: 'foo', - line: 1, - column: 2, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 6, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :UNENC_VARIABLE, + value: 'foo', + line: 1, + column: 2, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 6, + ), ) end @@ -503,25 +504,25 @@ end it 'creates a tokenised string' do - expect(tokens).to have(3).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: 'string with ', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :SSTRING, - value: 'a nested single quoted string', - line: 1, - column: 16, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: ' inside it', - line: 1, - column: 47, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: 'string with ', + line: 1, + column: 1, + ), + have_attributes( + type: :SSTRING, + value: 'a nested single quoted string', + line: 1, + column: 16, + ), + have_attributes( + type: :DQPOST, + value: ' inside it', + line: 1, + column: 47, + ), ) end @@ -540,61 +541,61 @@ end it 'creates a tokenised string' do - expect(tokens).to have(9).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: 'string with ', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :LPAREN, - value: '(', - line: 1, - column: 16, - ) - expect(tokens[2]).to have_attributes( - type: :NUMBER, - value: '3', - line: 1, - column: 17, - ) - expect(tokens[3]).to have_attributes( - type: :PLUS, - value: '+', - line: 1, - column: 18, - ) - expect(tokens[4]).to have_attributes( - type: :NUMBER, - value: '5', - line: 1, - column: 19, - ) - expect(tokens[5]).to have_attributes( - type: :RPAREN, - value: ')', - line: 1, - column: 20, - ) - expect(tokens[6]).to have_attributes( - type: :DIV, - value: '/', - line: 1, - column: 21, - ) - expect(tokens[7]).to have_attributes( - type: :NUMBER, - value: '4', - line: 1, - column: 22, - ) - expect(tokens[8]).to have_attributes( - type: :DQPOST, - value: ' nested math', - line: 1, - column: 23, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: 'string with ', + line: 1, + column: 1, + ), + have_attributes( + type: :LPAREN, + value: '(', + line: 1, + column: 16, + ), + have_attributes( + type: :NUMBER, + value: '3', + line: 1, + column: 17, + ), + have_attributes( + type: :PLUS, + value: '+', + line: 1, + column: 18, + ), + have_attributes( + type: :NUMBER, + value: '5', + line: 1, + column: 19, + ), + have_attributes( + type: :RPAREN, + value: ')', + line: 1, + column: 20, + ), + have_attributes( + type: :DIV, + value: '/', + line: 1, + column: 21, + ), + have_attributes( + type: :NUMBER, + value: '4', + line: 1, + column: 22, + ), + have_attributes( + type: :DQPOST, + value: ' nested math', + line: 1, + column: 23, + ), ) end @@ -613,55 +614,55 @@ end it 'creates a tokenised string' do - expect(tokens).to have(8).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: 'string with ', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :LBRACK, - value: '[', - line: 1, - column: 16, - ) - expect(tokens[2]).to have_attributes( - type: :SSTRING, - value: 'an array ', - line: 1, - column: 17, - ) - expect(tokens[3]).to have_attributes( - type: :COMMA, - value: ',', - line: 1, - column: 28, - ) - expect(tokens[4]).to have_attributes( - type: :WHITESPACE, - value: ' ', - line: 1, - column: 29, - ) - expect(tokens[5]).to have_attributes( - type: :VARIABLE, - value: 'v2', - line: 1, - column: 30, - ) - expect(tokens[6]).to have_attributes( - type: :RBRACK, - value: ']', - line: 1, - column: 33, - ) - expect(tokens[7]).to have_attributes( - type: :DQPOST, - value: ' in it', - line: 1, - column: 34, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: 'string with ', + line: 1, + column: 1, + ), + have_attributes( + type: :LBRACK, + value: '[', + line: 1, + column: 16, + ), + have_attributes( + type: :SSTRING, + value: 'an array ', + line: 1, + column: 17, + ), + have_attributes( + type: :COMMA, + value: ',', + line: 1, + column: 28, + ), + have_attributes( + type: :WHITESPACE, + value: ' ', + line: 1, + column: 29, + ), + have_attributes( + type: :VARIABLE, + value: 'v2', + line: 1, + column: 30, + ), + have_attributes( + type: :RBRACK, + value: ']', + line: 1, + column: 33, + ), + have_attributes( + type: :DQPOST, + value: ' in it', + line: 1, + column: 34, + ), ) end @@ -682,37 +683,37 @@ end it 'creates a tokenised string' do - expect(tokens).to have(5).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :UNENC_VARIABLE, - value: 'foo', - line: 1, - column: 2, - ) - expect(tokens[2]).to have_attributes( - type: :DQMID, - value: '', - line: 1, - column: 6, - ) - expect(tokens[3]).to have_attributes( - type: :UNENC_VARIABLE, - value: 'bar', - line: 1, - column: 6, - ) - expect(tokens[4]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 10, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :UNENC_VARIABLE, + value: 'foo', + line: 1, + column: 2, + ), + have_attributes( + type: :DQMID, + value: '', + line: 1, + column: 6, + ), + have_attributes( + type: :UNENC_VARIABLE, + value: 'bar', + line: 1, + column: 6, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 10, + ), ) end @@ -731,25 +732,25 @@ end it 'creates a tokenised string' do - expect(tokens).to have(3).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: 'foo', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :UNENC_VARIABLE, - value: 'bar', - line: 1, - column: 5, - ) - expect(tokens[2]).to have_attributes( - type: :DQPOST, - value: '$', - line: 1, - column: 9, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: 'foo', + line: 1, + column: 1, + ), + have_attributes( + type: :UNENC_VARIABLE, + value: 'bar', + line: 1, + column: 5, + ), + have_attributes( + type: :DQPOST, + value: '$', + line: 1, + column: 9, + ), ) end @@ -770,97 +771,97 @@ end it 'creates a tokenised string' do - expect(tokens).to have(15).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'key', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :DQMID, - value: ' ', - line: 1, - column: 7, - ) - expect(tokens[3]).to have_attributes( - type: :FUNCTION_NAME, - value: 'flatten', - line: 1, - column: 11, - ) - expect(tokens[4]).to have_attributes( - type: :LPAREN, - value: '(', - line: 1, - column: 18, - ) - expect(tokens[5]).to have_attributes( - type: :LBRACK, - value: '[', - line: 1, - column: 19, - ) - expect(tokens[6]).to have_attributes( - type: :VARIABLE, - value: 'value', - line: 1, - column: 20, - ) - expect(tokens[7]).to have_attributes( - type: :RBRACK, - value: ']', - line: 1, - column: 26, - ) - expect(tokens[8]).to have_attributes( - type: :RPAREN, - value: ')', - line: 1, - column: 27, - ) - expect(tokens[9]).to have_attributes( - type: :DOT, - value: '.', - line: 1, - column: 28, - ) - expect(tokens[10]).to have_attributes( - type: :FUNCTION_NAME, - value: 'join', - line: 1, - column: 29, - ) - expect(tokens[11]).to have_attributes( - type: :LPAREN, - value: '(', - line: 1, - column: 33, - ) - expect(tokens[12]).to have_attributes( - type: :STRING, - value: '\nkey ', - line: 1, - column: 34, - ) - expect(tokens[13]).to have_attributes( - type: :RPAREN, - value: ')', - line: 1, - column: 42, - ) - expect(tokens[14]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 43, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'key', + line: 1, + column: 4, + ), + have_attributes( + type: :DQMID, + value: ' ', + line: 1, + column: 7, + ), + have_attributes( + type: :FUNCTION_NAME, + value: 'flatten', + line: 1, + column: 11, + ), + have_attributes( + type: :LPAREN, + value: '(', + line: 1, + column: 18, + ), + have_attributes( + type: :LBRACK, + value: '[', + line: 1, + column: 19, + ), + have_attributes( + type: :VARIABLE, + value: 'value', + line: 1, + column: 20, + ), + have_attributes( + type: :RBRACK, + value: ']', + line: 1, + column: 26, + ), + have_attributes( + type: :RPAREN, + value: ')', + line: 1, + column: 27, + ), + have_attributes( + type: :DOT, + value: '.', + line: 1, + column: 28, + ), + have_attributes( + type: :FUNCTION_NAME, + value: 'join', + line: 1, + column: 29, + ), + have_attributes( + type: :LPAREN, + value: '(', + line: 1, + column: 33, + ), + have_attributes( + type: :STRING, + value: '\nkey ', + line: 1, + column: 34, + ), + have_attributes( + type: :RPAREN, + value: ')', + line: 1, + column: 42, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 43, + ), ) end @@ -881,97 +882,97 @@ end it 'creates a tokenised string' do - expect(tokens).to have(15).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'facts', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :LBRACK, - value: '[', - line: 1, - column: 9, - ) - expect(tokens[3]).to have_attributes( - type: :DQPRE, - value: 'network_', - line: 1, - column: 10, - ) - expect(tokens[4]).to have_attributes( - type: :VARIABLE, - value: 'iface', - line: 1, - column: 21, - ) - expect(tokens[5]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 26, - ) - expect(tokens[6]).to have_attributes( - type: :RBRACK, - value: ']', - line: 1, - column: 28, - ) - expect(tokens[7]).to have_attributes( - type: :DQMID, - value: '/', - line: 1, - column: 29, - ) - expect(tokens[8]).to have_attributes( - type: :VARIABLE, - value: 'facts', - line: 1, - column: 33, - ) - expect(tokens[9]).to have_attributes( - type: :LBRACK, - value: '[', - line: 1, - column: 38, - ) - expect(tokens[10]).to have_attributes( - type: :DQPRE, - value: 'netmask_', - line: 1, - column: 39, - ) - expect(tokens[11]).to have_attributes( - type: :VARIABLE, - value: 'iface', - line: 1, - column: 50, - ) - expect(tokens[12]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 55, - ) - expect(tokens[13]).to have_attributes( - type: :RBRACK, - value: ']', - line: 1, - column: 57, - ) - expect(tokens[14]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 58, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'facts', + line: 1, + column: 4, + ), + have_attributes( + type: :LBRACK, + value: '[', + line: 1, + column: 9, + ), + have_attributes( + type: :DQPRE, + value: 'network_', + line: 1, + column: 10, + ), + have_attributes( + type: :VARIABLE, + value: 'iface', + line: 1, + column: 21, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 26, + ), + have_attributes( + type: :RBRACK, + value: ']', + line: 1, + column: 28, + ), + have_attributes( + type: :DQMID, + value: '/', + line: 1, + column: 29, + ), + have_attributes( + type: :VARIABLE, + value: 'facts', + line: 1, + column: 33, + ), + have_attributes( + type: :LBRACK, + value: '[', + line: 1, + column: 38, + ), + have_attributes( + type: :DQPRE, + value: 'netmask_', + line: 1, + column: 39, + ), + have_attributes( + type: :VARIABLE, + value: 'iface', + line: 1, + column: 50, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 55, + ), + have_attributes( + type: :RBRACK, + value: ']', + line: 1, + column: 57, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 58, + ), ) end @@ -990,115 +991,115 @@ end it 'creates a tokenised string' do - expect(tokens).to have(18).tokens - - expect(tokens[0]).to have_attributes( - type: :DQPRE, - value: '', - line: 1, - column: 1, - ) - expect(tokens[1]).to have_attributes( - type: :VARIABLE, - value: 'foo', - line: 1, - column: 4, - ) - expect(tokens[2]).to have_attributes( - type: :DOT, - value: '.', - line: 1, - column: 8, - ) - expect(tokens[3]).to have_attributes( - type: :NAME, - value: 'map', - line: 1, - column: 9, - ) - expect(tokens[4]).to have_attributes( - type: :WHITESPACE, - value: ' ', - line: 1, - column: 12, - ) - expect(tokens[5]).to have_attributes( - type: :PIPE, - value: '|', - line: 1, - column: 13, - ) - expect(tokens[6]).to have_attributes( - type: :VARIABLE, - value: 'bar', - line: 1, - column: 14, - ) - expect(tokens[7]).to have_attributes( - type: :PIPE, - value: '|', - line: 1, - column: 18, - ) - expect(tokens[8]).to have_attributes( - type: :WHITESPACE, - value: ' ', - line: 1, - column: 19, - ) - expect(tokens[9]).to have_attributes( - type: :LBRACE, - value: '{', - line: 1, - column: 20, - ) - expect(tokens[10]).to have_attributes( - type: :WHITESPACE, - value: ' ', - line: 1, - column: 21, - ) - expect(tokens[11]).to have_attributes( - type: :FUNCTION_NAME, - value: 'something', - line: 1, - column: 22, - ) - expect(tokens[12]).to have_attributes( - type: :LPAREN, - value: '(', - line: 1, - column: 31, - ) - expect(tokens[13]).to have_attributes( - type: :VARIABLE, - value: 'bar', - line: 1, - column: 32, - ) - expect(tokens[14]).to have_attributes( - type: :RPAREN, - value: ')', - line: 1, - column: 36, - ) - expect(tokens[15]).to have_attributes( - type: :WHITESPACE, - value: ' ', - line: 1, - column: 37, - ) - expect(tokens[16]).to have_attributes( - type: :RBRACE, - value: '}', - line: 1, - column: 38, - ) - expect(tokens[17]).to have_attributes( - type: :DQPOST, - value: '', - line: 1, - column: 39, + expect(tokens).to contain_exactly( + have_attributes( + type: :DQPRE, + value: '', + line: 1, + column: 1, + ), + have_attributes( + type: :VARIABLE, + value: 'foo', + line: 1, + column: 4, + ), + have_attributes( + type: :DOT, + value: '.', + line: 1, + column: 8, + ), + have_attributes( + type: :NAME, + value: 'map', + line: 1, + column: 9, + ), + have_attributes( + type: :WHITESPACE, + value: ' ', + line: 1, + column: 12, + ), + have_attributes( + type: :PIPE, + value: '|', + line: 1, + column: 13, + ), + have_attributes( + type: :VARIABLE, + value: 'bar', + line: 1, + column: 14, + ), + have_attributes( + type: :PIPE, + value: '|', + line: 1, + column: 18, + ), + have_attributes( + type: :WHITESPACE, + value: ' ', + line: 1, + column: 19, + ), + have_attributes( + type: :LBRACE, + value: '{', + line: 1, + column: 20, + ), + have_attributes( + type: :WHITESPACE, + value: ' ', + line: 1, + column: 21, + ), + have_attributes( + type: :FUNCTION_NAME, + value: 'something', + line: 1, + column: 22, + ), + have_attributes( + type: :LPAREN, + value: '(', + line: 1, + column: 31, + ), + have_attributes( + type: :VARIABLE, + value: 'bar', + line: 1, + column: 32, + ), + have_attributes( + type: :RPAREN, + value: ')', + line: 1, + column: 36, + ), + have_attributes( + type: :WHITESPACE, + value: ' ', + line: 1, + column: 37, + ), + have_attributes( + type: :RBRACE, + value: '}', + line: 1, + column: 38, + ), + have_attributes( + type: :DQPOST, + value: '', + line: 1, + column: 39, + ), ) end @@ -1291,7 +1292,7 @@ it 'does not enclose variable with a chained function call' do manifest = '"This is ${a.test}"' tokens = lexer.tokenise(manifest) - expect(tokens.map(&:to_manifest).join('')).to eq(manifest) + expect(tokens.map(&:to_manifest).join).to eq(manifest) end end @@ -1382,6 +1383,7 @@ expect(token.type).to eq(:TYPE) expect(token.value).to eq('Callable') end + it 'matches Sensitive' do token = lexer.tokenise('Sensitive').first expect(token.type).to eq(:TYPE) @@ -1689,7 +1691,7 @@ END tokens = lexer.tokenise(manifest) - expect(tokens.map(&:to_manifest).join('')).to eq(manifest) + expect(tokens.map(&:to_manifest).join).to eq(manifest) expect(tokens[0].type).to eq(:VARIABLE) expect(tokens[0].value).to eq('str') @@ -1756,7 +1758,7 @@ expect(tokens[7].raw).to eq('$myvar') expect(tokens[7].to_manifest).to eq('$myvar') - expect(tokens.map(&:to_manifest).join('')).to eq(manifest) + expect(tokens.map(&:to_manifest).join).to eq(manifest) end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -13,7 +13,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -26,7 +26,7 @@ end it 'detects a problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -68,7 +68,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -84,7 +84,7 @@ end it 'detects a problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -129,7 +129,7 @@ end it 'detects a problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -6,7 +6,7 @@ let(:path) { 'foo/manifests/bar.pp' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -15,7 +15,7 @@ let(:path) { 'foo/manifests/bar/baz.pp' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -24,7 +24,7 @@ let(:path) { 'foo/manifests/init.pp' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -34,7 +34,7 @@ let(:msg) { 'foo::bar not in autoload module layout' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -56,7 +56,7 @@ let(:path) { 'bar/manifests/init.pp' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -65,7 +65,7 @@ let(:path) { 'puppet-foo/manifests/init.pp' } it 'detects a single problem' do - expect(problems).to have(1).problems + expect(problems.size).to eq(1) end end @@ -82,7 +82,7 @@ let(:path) { 'puppet-foo/manifests/bar.pp' } it 'detects a single problem' do - expect(problems).to have(1).problems + expect(problems.size).to eq(1) end end @@ -99,7 +99,7 @@ let(:path) { 'puppet-foo/manifests/init.pp' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -12,7 +12,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -33,7 +33,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -40,9 +40,10 @@ END end + it { expect(problems.size).to eq(4) } + its(:problems) do is_expected.to contain_warning('code outside of class or define block - include') - is_expected.to have(4).problems end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ let(:code) { 'class foo::bar inherits foo { }' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -15,7 +15,7 @@ let(:code) { 'class foo::bar inherits foo::baz { }' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -23,7 +23,7 @@ let(:code) { 'class foo::bar inherits baz { }' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ let(:class_msg) { "defined type 'FooBar' contains illegal uppercase" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -21,7 +21,7 @@ let(:class_msg) { "class 'FooBar' contains illegal uppercase" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -35,7 +35,7 @@ let(:class_msg) { "class 'Foo::BarFoo' contains illegal uppercase" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -9,7 +9,7 @@ let(:path) { 'foo-bar/manifests/init.pp' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -22,7 +22,7 @@ let(:path) { 'foo/manifests/foo-bar.pp' } it 'only detect a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -35,7 +35,7 @@ let(:path) { 'foo/manifests/bar-foo.pp' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { 'class foo { }' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -23,7 +23,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -43,7 +43,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -59,7 +59,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -74,7 +74,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problems + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/parameter_order_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "#{type} foo($bar, $baz='gronk') { }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -16,7 +16,7 @@ let(:code) { "#{type} foo($bar=extlookup($name)) {}" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -24,10 +24,10 @@ let(:code) { "#{type} foo($bar='baz', $gronk) { }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end - col = (type == 'class' ? 23 : 24) + col = ((type == 'class') ? 23 : 24) it 'creates a warning' do expect(problems).to contain_warning(msg).on_line(1).in_column(col) end @@ -42,7 +42,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -55,10 +55,10 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end - col = (type == 'class' ? 35 : 36) + col = ((type == 'class') ? 35 : 36) it 'creates a warning' do expect(problems).to contain_warning(msg).on_line(1).in_column(col) end @@ -76,7 +76,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -98,7 +98,7 @@ END end - it { expect(problems).to have(0).problem } + it { expect(problems.size).to eq(0) } end context "#{type} parameter w/a hash containing a variable followed by an optional parameter" do @@ -132,20 +132,7 @@ END end - it { expect(problems).to have(0).problem } - end - - context "#{type} parameter with Optional data type" do - let(:code) do - <<-END - #{type} test( - String $test = 'value', - Optional[String] $optional, - ) { } - END - end - - it { expect(problems).to have(0).problems } + it { expect(problems.size).to eq(0) } end context "#{type} parameter with array operation" do @@ -163,7 +150,74 @@ END end - it { expect(problems).to have(0).problems } + it { expect(problems).to be_empty } + end + + context "#{type} parameters of Optional type are just regular parameters" do + let(:code) do + <<-END + #{type} test ( + String $param1 = '', + Optional[Boolean] $param2, + ) { } + END + end + + it { expect(problems.size).to eq(1) } + end + + [['Custom::Type1', 'Custom::Type2'], ['Custom::Type1', 'String'], ['String', 'Custom::Type2']].each_with_index do |testtypes, i| # rubocop:disable Performance/CollectionLiteralInLoop + context "#{type} parameters of custom type - no values - #{i}" do + let(:code) do + <<-END + #{type} test ( + #{testtypes[0]} $param1, + #{testtypes[0]} $param2, + ) { } + END + end + + it { expect(problems).to be_empty } + end + + context "#{type} parameters of custom type - two values - #{i}" do + let(:code) do + <<-END + #{type} test ( + #{testtypes[0]} $param1 = 'foo', + #{testtypes[1]} $param2 = 'bar', + ) { } + END + end + + it { expect(problems).to be_empty } + end + + context "#{type} parameters of custom type - one value, wrong order - #{i}" do + let(:code) do + <<-END + #{type} test ( + #{testtypes[0]} $param1 = 'foo', + #{testtypes[1]} $param2, + ) { } + END + end + + it { expect(problems.size).to eq(1) } + end + + context "#{type} parameters of custom type - one value, right order - #{i}" do + let(:code) do + <<-END + #{type} test ( + #{testtypes[0]} $param1, + #{testtypes[1]} $param2 = 'bar', + ) { } + END + end + + it { expect(problems).to be_empty } + end end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ let(:code) { 'Class[foo] -> Class[bar]' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -15,7 +15,7 @@ let(:code) { 'Class[foo] <- Class[bar]' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_classes/variable_scope_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -13,7 +13,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -31,7 +31,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -46,7 +46,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -65,7 +65,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -80,7 +80,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -94,7 +94,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -108,7 +108,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -126,7 +126,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -143,7 +143,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -159,7 +159,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -181,7 +181,7 @@ end it 'only detects two problems' do - expect(problems).to have(2).problem + expect(problems.size).to eq(2) end it 'creates two warnings' do @@ -213,7 +213,7 @@ end it 'only detects three problems' do - expect(problems).to have(3).problem + expect(problems.size).to eq(3) end it 'creates three warnings' do @@ -234,16 +234,16 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end - context 'support the use of facts and trusted facts for Puppet 3.5 onwards' do + context 'support the use of facts and trusted facts' do let(:code) do <<-END class foo() { - if $facts['osfamily'] == 'redhat' or $trusted['osfamily'] == 'redhat' { + if $facts['os']['family'] == 'redhat' or $trusted['os']['family'] == 'redhat' { $redhat = true } } @@ -251,7 +251,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -265,7 +265,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -279,7 +279,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -294,7 +294,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -309,7 +309,7 @@ end it 'only detects one problem' do - expect(problems).to have(1).problems + expect(problems.size).to eq(1) end it 'creates one warning' do @@ -327,7 +327,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_comments/slash_comments_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { '// foo' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -30,7 +30,7 @@ let(:code) { '// foo' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_comments/star_comments_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -13,7 +13,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -49,7 +49,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -76,7 +76,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -109,7 +109,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -14,7 +14,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -29,7 +29,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -50,7 +50,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -74,7 +74,7 @@ end it 'detects two problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'creates two warnings' do @@ -87,22 +87,22 @@ let(:code) do <<-END $mem = inline_template('<% - mem,unit = scope.lookupvar(\'::memorysize\').split + mem,unit = scope.lookupvar('::memorysize').split mem = mem.to_f # Normalize mem to bytes case unit when nil: mem *= (1<<0) - when \'kB\': mem *= (1<<10) - when \'MB\': mem *= (1<<20) - when \'GB\': mem *= (1<<30) - when \'TB\': mem *= (1<<40) + when 'kB': mem *= (1<<10) + when 'MB': mem *= (1<<20) + when 'GB': mem *= (1<<30) + when 'TB': mem *= (1<<40) end %><%= mem.to_i %>') END end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -141,7 +141,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -16,7 +16,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -34,7 +34,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_documentation/documentation_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { 'class test {}' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -25,7 +25,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -39,7 +39,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -51,7 +51,7 @@ let(:code) { 'define test {}' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -68,7 +68,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { 'node foo { }' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -20,7 +20,7 @@ let(:code) { 'node default { }' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -28,7 +28,7 @@ let(:code) { "node 'foo' { }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -36,7 +36,7 @@ let(:code) { 'node /foo/ { }' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -44,7 +44,7 @@ let(:code) { 'node foo, bar, baz { }' } it 'detects 3 problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'creates 3 warnings' do @@ -58,7 +58,7 @@ let(:code) { "node foo, 'bar', baz { }" } it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'creates 2 warnings' do @@ -71,7 +71,7 @@ let(:code) { 'node foo { } node bar { }' } it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'creates 2 warnings' do @@ -84,7 +84,7 @@ let(:code) { 'node foo' } it 'detects a problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates 1 error' do @@ -106,7 +106,7 @@ let(:code) { 'node foo { }' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -123,7 +123,7 @@ let(:fixed) { "node 'foo', 'bar', 'baz' { }" } it 'detects 3 problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'fixes the 3 problems' do @@ -142,7 +142,7 @@ let(:fixed) { "node 'foo', 'bar', 'baz' { }" } it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'fixes the 2 problems' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/duplicate_params_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -16,7 +16,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -37,7 +37,7 @@ end it 'does not detect any errors' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -54,7 +54,7 @@ end it 'only detects a single error' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -77,7 +77,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -96,7 +96,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -104,7 +104,7 @@ let(:code) { '}:' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "file { 'foo': ensure => present }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -22,7 +22,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -37,7 +37,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -56,7 +56,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -77,7 +77,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -93,7 +93,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end @@ -111,7 +111,7 @@ let(:code) { "file { 'foo': ensure => present }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -125,7 +125,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -149,7 +149,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -172,7 +172,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -193,7 +193,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -229,7 +229,7 @@ end it 'detects a problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the problem' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -15,7 +15,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -29,7 +29,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -58,7 +58,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end it 'does not modify the manifest' do @@ -85,7 +85,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the problem' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "file { 'foo': mode => '777' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -20,7 +20,7 @@ let(:code) { "file { 'foo': mode => '0777' }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -28,7 +28,7 @@ let(:code) { "file { 'foo': mode => $file_mode }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -36,7 +36,7 @@ let(:code) { "file { 'foo': mode => 'u=rw,og=r' }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -44,7 +44,7 @@ let(:code) { "file { 'foo': mode => undef }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -52,7 +52,7 @@ let(:code) { "file { 'foo': mode => 'undef' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -64,7 +64,7 @@ let(:code) { "file { '/etc/passwd': audit => [ owner, mode ], }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -72,7 +72,7 @@ let(:code) { "concat { 'foo': mode => '777' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -84,7 +84,7 @@ let(:code) { "concat { 'foo': mode => '0777' }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -92,7 +92,7 @@ let(:code) { "concat { 'foo': mode => $concat_mode }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -100,7 +100,7 @@ let(:code) { "concat { 'foo': mode => 'u=rw,og=r' }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -108,7 +108,7 @@ let(:code) { "concat { 'foo': mode => undef }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -116,7 +116,7 @@ let(:code) { "concat { 'foo': mode => 'undef' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -128,7 +128,7 @@ let(:code) { "concat { '/etc/passwd': audit => [ owner, mode ], }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -136,7 +136,7 @@ let(:code) { "file { 'foo': mode => lookup('bar'), }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -156,7 +156,7 @@ end it 'detects 3 problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'creates three warnings' do @@ -180,7 +180,7 @@ let(:code) { "file { 'foo': mode => '777' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -196,7 +196,7 @@ let(:code) { "file { 'foo': mode => 'undef' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -212,7 +212,7 @@ let(:code) { "concat { 'foo': mode => '777' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -228,7 +228,7 @@ let(:code) { "concat { 'foo': mode => 'undef' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -244,7 +244,7 @@ let(:code) { "file { 'foo': mode => lookup('bar'), }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end it 'does not change the manifest' do @@ -282,7 +282,7 @@ end it 'detects 3 problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'fixes 3 problems' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "file { 'foo': mode => 0777 }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -20,7 +20,7 @@ let(:code) { "concat { 'foo': mode => 0777 }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -32,7 +32,7 @@ let(:code) { "file { 'foo': mode => lookup('bar'), }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -52,7 +52,7 @@ end it 'detects 3 problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'creates three warnings' do @@ -76,7 +76,7 @@ let(:code) { "file { 'foo': mode => 0777 }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -92,7 +92,7 @@ let(:code) { "concat { 'foo': mode => 0777 }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -108,7 +108,7 @@ let(:code) { "file { 'foo': mode => lookup('bar'), }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end it 'does not change the manifest' do @@ -146,7 +146,7 @@ end it 'detects 3 problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'fixes 3 problems' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "file { 'foo': }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -16,7 +16,7 @@ let(:code) { 'file { foo: }' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -33,7 +33,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -46,7 +46,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -65,7 +65,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -80,7 +80,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -92,7 +92,7 @@ let(:code) { "file { ['foo', 'bar']: }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -110,7 +110,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -125,7 +125,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -147,7 +147,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end @@ -165,7 +165,7 @@ let(:code) { 'file { foo: }' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -193,7 +193,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -225,7 +225,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -16,7 +16,7 @@ let(:code) { "\"aoeu\" '${foo}'" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -28,7 +28,7 @@ let(:code) { "'grep \"status=sent\" /var/log/mail.log'" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -36,7 +36,7 @@ let(:code) { "service { 'foo': } # \"bar\"" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -44,16 +44,16 @@ let(:code) { %("foo\n") } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end context 'double quoted string with backslash for continuation' do let(:code) do <<-END - class puppet::master::maintenance ( + class puppet::server::maintenance ( ) { - cron { 'puppet_master_reports_cleanup': + cron { 'puppet_server_reports_cleanup': command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \ -delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \ -empty -type d -delete", @@ -65,7 +65,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -73,7 +73,7 @@ let(:code) { "class { 'foo': boolFlag => \"true\" }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -85,7 +85,7 @@ let(:code) { "class { 'foo': boolFlag => \"false\" }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -98,7 +98,7 @@ <<-END $string1 = "this string contains \n newline" $string2 = "this string contains \t tab" - $string3 = "this string contains \${escaped} var" + $string3 = "this string contains ${escaped} var" $string4 = "this string contains \\"escaped \\" double quotes" $string5 = "this string contains \\'escaped \\' single quotes" $string6 = "this string contains \r carriage return" @@ -108,7 +108,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -116,7 +116,7 @@ let(:code) { %( $ztring = "this string contains \l random escape" ) } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -128,7 +128,7 @@ let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -136,7 +136,7 @@ let(:code) { %(notify { "'foo'": }) } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end @@ -154,7 +154,7 @@ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end it 'does not modify the manifest' do @@ -166,7 +166,7 @@ let(:code) { "\"sed -i 's/^;*[[:space:]]*${name}[[:space:]]*=.*$/${name} = ${value}/g' file\"" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end it 'does not modify the manifest' do @@ -178,7 +178,7 @@ let(:code) { "\"aoeu\" '${foo}'" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -194,7 +194,7 @@ let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end it 'does not modify the manifest' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/only_variable_string_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { '"${foo}"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -20,7 +20,7 @@ let(:code) { '"${foo[0]}"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -32,7 +32,7 @@ let(:code) { '"${foo[0][aoeuaoeu][bar][999]}"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -45,7 +45,7 @@ <<-END $bar = 'key' $foo = { - \"$bar\" => 1, + "$bar" => 1, } END end @@ -69,7 +69,7 @@ let(:code) { '"${foo}"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -85,7 +85,7 @@ let(:code) { '"${foo[0]}"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -101,7 +101,7 @@ let(:code) { '"${foo[0][aoeuaoeu][bar][999]}"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ let(:code) { "'puppet:///modules/foo'" } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -16,7 +16,7 @@ let(:code) { "'puppet:///foo'" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -38,7 +38,7 @@ let(:code) { "'puppet:///foo'" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -55,7 +55,7 @@ let(:code) { File.read('spec/fixtures/test/manifests/url_interpolation.pp') } it 'detects several problems' do - expect(problems).to have(4).problem + expect(problems.size).to eq(4) end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "class { 'foo': boolFlag => 'false' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -20,7 +20,7 @@ let(:code) { "class { 'foo': boolFlag => 'true' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -32,7 +32,7 @@ let(:code) { "class { 'foo': boolFlag => \"true\" }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -44,7 +44,7 @@ let(:code) { "class { 'foo': boolFlag => \"false\" }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -66,7 +66,7 @@ let(:code) { "class { 'foo': boolFlag => 'false' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -82,7 +82,7 @@ let(:code) { "class { 'foo': boolFlag => 'true' }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -98,7 +98,7 @@ let(:code) { "class { 'foo': boolFlag => \"true\" }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -114,7 +114,7 @@ let(:code) { "class { 'foo': boolFlag => \"false\" }" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ let(:code) { "\"aoeu\" '${foo}'" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -26,7 +26,7 @@ END end - it { expect(problems).to have(0).problem } + it { expect(problems.size).to eq(0) } end context 'single quoted inline epp with dollar signs has no problems' do @@ -40,6 +40,6 @@ END end - it { expect(problems).to have(0).problem } + it { expect(problems.size).to eq(0) } end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { '" $gronk"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -20,7 +20,7 @@ let(:code) { ("'groovy'\n" * 20) + '" $gronk"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -42,7 +42,7 @@ let(:code) { '" $gronk"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -58,7 +58,7 @@ let(:code) { ("'groovy'\n" * 20) + '" $gronk"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -74,7 +74,7 @@ let(:code) { '"$foo-$bar"' } it 'only detects two problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'fixes the manifest' do @@ -91,7 +91,7 @@ let(:code) { %("$foo['bar'][2]something") } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -107,7 +107,7 @@ let(:code) { '"$hostname-keystore"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ let(:code) { '$foo-bar' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -19,7 +19,7 @@ let(:code) { '" $foo-bar"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -7,7 +7,7 @@ let(:code) { '$fooBar' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -19,7 +19,7 @@ let(:code) { '$foobar' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -27,7 +27,7 @@ let(:code) { %("${Integer(fact('memory.system.total_bytes'))}") } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -35,7 +35,7 @@ let(:code) { '"${fooBar}"' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -47,7 +47,7 @@ let(:code) { '"${foobar}"' } it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/140chars_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe '140chars' do @@ -15,7 +13,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -29,7 +27,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -43,7 +41,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -51,7 +49,7 @@ let(:code) { 'a' * 141 } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -13,7 +13,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/80chars_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -1,10 +1,8 @@ -# encoding: utf-8 - require 'spec_helper' describe '80chars' do before(:each) do - PuppetLint.configuration.send('enable_80chars') + PuppetLint.configuration.send(:enable_80chars) end let(:msg) { 'line has more than 80 characters' } @@ -19,7 +17,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -33,7 +31,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -47,7 +45,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -55,7 +53,7 @@ let(:code) { 'a' * 81 } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -19,7 +19,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -37,7 +37,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -55,7 +55,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -76,7 +76,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -111,7 +111,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -129,7 +129,7 @@ end it 'detects four problems' do - expect(problems).to have(4).problems + expect(problems.size).to eq(4) end it 'creates four warnings' do @@ -154,7 +154,7 @@ end it 'detects four problems' do - expect(problems).to have(4).problems + expect(problems.size).to eq(4) end it 'creates four warnings' do @@ -181,7 +181,7 @@ end it 'detects three problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'creates three warnings' do @@ -206,7 +206,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates a warning' do @@ -233,7 +233,7 @@ end it 'only detects a single problem' do - expect(problems).to have(4).problem + expect(problems.size).to eq(4) end it 'creates a warning' do @@ -253,7 +253,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -268,7 +268,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -282,7 +282,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -296,7 +296,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -311,7 +311,7 @@ end it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'creates 2 warnings' do @@ -332,7 +332,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -347,7 +347,7 @@ end it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'creates 2 warnings' do @@ -367,7 +367,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -384,7 +384,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -401,7 +401,7 @@ end it 'detects one problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates one warning' do @@ -423,7 +423,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end @@ -441,7 +441,7 @@ end it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'creates 2 warnings' do @@ -470,14 +470,14 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end context 'where the top level of the block has no parameters' do let(:code) do <<-END - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { $datadir = $::operatingsystem ? { 'Amazon' => pick($datadir, 'value'), @@ -489,7 +489,7 @@ end it 'does not detect any problems' do - expect(problems).to have(0).problems + expect(problems).to be_empty end end end @@ -529,7 +529,7 @@ end it 'detects four problems' do - expect(problems).to have(4).problems + expect(problems.size).to eq(4) end it 'fixes the manifest' do @@ -574,7 +574,7 @@ end it 'detects three problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'fixes the manifest' do @@ -616,7 +616,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -648,7 +648,7 @@ end it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'creates 2 warnings' do @@ -681,7 +681,7 @@ end it 'detects 1 problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the problem' do @@ -714,7 +714,7 @@ end it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'fixes 2 problems' do @@ -748,7 +748,7 @@ end it 'detects 2 problems' do - expect(problems).to have(3).problems + expect(problems.size).to eq(3) end it 'fixes 2 problems' do @@ -788,7 +788,7 @@ end it 'detects 2 problems' do - expect(problems).to have(2).problems + expect(problems.size).to eq(2) end it 'fixes 2 problems' do @@ -839,7 +839,7 @@ end it 'detects 1 problem' do - expect(problems).to have(1).problems + expect(problems.size).to eq(1) end it 'fixes 1 problem' do @@ -897,7 +897,7 @@ end it 'detects 5 problems' do - expect(problems).to have(5).problems + expect(problems.size).to eq(5) end it 'fixes 5 problems' do @@ -949,7 +949,7 @@ end it 'detects 8 problems' do - expect(problems).to have(8).problems + expect(problems.size).to eq(8) end it 'fixes 8 problems' do @@ -993,7 +993,7 @@ end it 'detects a problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the problems' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { "\tfoo => bar," } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -30,7 +30,7 @@ let(:code) { "\tfoo => bar," } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb 2022-10-23 14:31:34.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -8,7 +8,7 @@ let(:code) { 'foo ' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -26,7 +26,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -48,7 +48,7 @@ let(:code) { 'foo ' } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -64,7 +64,7 @@ let(:code) { "foo \nbar" } it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'fixes the manifest' do @@ -94,7 +94,7 @@ end it 'only detects a single problem' do - expect(problems).to have(1).problem + expect(problems.size).to eq(1) end it 'creates an error' do @@ -105,5 +105,17 @@ expect(manifest).to eq(fixed) end end + + context 'empty lines with nothing but whitespace' do + let(:code) { " \n " } + + it 'detects problems with both empty lines' do + expect(problems.size).to eq(2) + end + + it 'fixes the manifest' do + expect(manifest).to eq("\n") + end + end end end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -0,0 +1,479 @@ +require 'spec_helper' + +describe 'legacy_facts' do + context 'with fix disabled' do + context "fact variable using modern $facts['os']['family'] hash" do + let(:code) { "$facts['os']['family']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context "fact variable using modern $facts['ssh']['rsa']['key'] hash" do + let(:code) { "$facts['ssh']['rsa']['key']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'fact variable using legacy $osfamily' do + let(:code) { '$osfamily' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context "fact variable using legacy $facts['osfamily']" do + let(:code) { "$facts['osfamily']" } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy $::osfamily' do + let(:code) { '$::osfamily' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy $::blockdevice_sda_model' do + let(:code) { '$::blockdevice_sda_model' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context "fact variable using legacy $facts['ipaddress6_em2']" do + let(:code) { "$facts['ipaddress6_em2']" } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy $::zone_foobar_uuid' do + let(:code) { '$::zone_foobar_uuid' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy $::processor314' do + let(:code) { '$::processor314' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy $::sp_l3_cache' do + let(:code) { '$::sp_l3_cache' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy $::sshrsakey' do + let(:code) { '$::sshrsakey' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable in interpolated string "${::osfamily}"' do + let(:code) { '"start ${::osfamily} end"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy variable in double quotes "$::osfamily"' do + let(:code) { '"$::osfamily"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'fact variable using legacy facts hash variable in interpolation' do + let(:code) { %("${facts['osfamily']}") } + + it 'detects a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'top scoped fact variable using legacy facts hash variable in interpolation' do + let(:code) { "$::facts['osfamily']" } + + it 'detects a single problem' do + expect(problems.size).to eq(1) + end + end + + context 'top scoped fact variable using unquoted legacy facts hash variable in interpolation' do + let(:code) { '$::facts[osfamily]' } + + it 'detects a single problem' do + expect(problems.size).to eq(1) + end + end + end + + context 'with fix enabled' do + before(:each) do + PuppetLint.configuration.fix = true + end + + after(:each) do + PuppetLint.configuration.fix = false + end + + context "fact variable using modern $facts['os']['family'] hash" do + let(:code) { "$facts['os']['family']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context "fact variable using modern $facts['ssh']['rsa']['key'] hash" do + let(:code) { "$facts['ssh']['rsa']['key']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'fact variable using legacy $osfamily' do + let(:code) { '$osfamily' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context "fact variable using legacy $facts['osfamily']" do + let(:code) { "$facts['osfamily']" } + let(:msg) { "legacy fact 'osfamily'" } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'fixes the problem' do + expect(problems).to contain_fixed(msg).on_line(1).in_column(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['os']['family']") + end + end + + context 'fact variable using top scope $::facts hash' do + let(:code) { "$::facts['os']['family']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context "fact variable using legacy top scope $::facts['osfamily']" do + let(:code) { "$::facts['osfamily']" } + let(:msg) { "legacy fact 'osfamily'" } + + it 'only detects a single problem' do + expect(problems.size).to eq(1) + end + + it 'fixes the problem' do + expect(problems).to contain_fixed(msg).on_line(1).in_column(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['os']['family']") + end + end + + context 'fact variable using legacy $::osfamily' do + let(:code) { '$::osfamily' } + let(:msg) { "legacy fact 'osfamily'" } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'fixes the problem' do + expect(problems).to contain_fixed(msg).on_line(1).in_column(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['os']['family']") + end + end + + context 'fact variable using legacy $::sshrsakey' do + let(:code) { '$::sshrsakey' } + let(:msg) { "legacy fact 'sshrsakey'" } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'fixes the problem' do + expect(problems).to contain_fixed(msg).on_line(1).in_column(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['ssh']['rsa']['key']") + end + end + + context 'fact variable using legacy $::memoryfree_mb' do + let(:code) { '$::memoryfree_mb' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'continues to use the legacy fact' do + expect(manifest).to eq('$::memoryfree_mb') + end + end + + context 'fact variable using legacy $::blockdevice_sda_model' do + let(:code) { '$::blockdevice_sda_model' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['disks']['sda']['model']") + end + end + + context "fact variable using legacy $facts['ipaddress6_em2']" do + let(:code) { "$facts['ipaddress6_em2']" } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['networking']['interfaces']['em2']['ip6']") + end + end + + context 'fact variable using legacy $::zone_foobar_uuid' do + let(:code) { '$::zone_foobar_uuid' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['solaris_zones']['zones']['foobar']['uuid']") + end + end + + context 'fact variable using legacy $::processor314' do + let(:code) { '$::processor314' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['processors']['models'][314]") + end + end + + context 'fact variable using legacy $::sp_l3_cache' do + let(:code) { '$::sp_l3_cache' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['system_profiler']['l3_cache']") + end + end + + context 'fact variable using legacy $::sshrsakey' do + let(:code) { '$::sshrsakey' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("$facts['ssh']['rsa']['key']") + end + end + + context 'fact variable in interpolated string "${::osfamily}"' do + let(:code) { '"start ${::osfamily} end"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq('"start '"${facts['os']['family']}"' end"') # rubocop:disable Lint/ImplicitStringConcatenation + end + end + + context 'fact variable using legacy variable in double quotes "$::osfamily"' do + let(:code) { '"$::osfamily"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['family']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::gid"' do + let(:code) { '"$::gid"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['identity']['group']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::id"' do + let(:code) { '"$::id"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['identity']['user']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::lsbdistcodename"' do + let(:code) { '"$::lsbdistcodename"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['distro']['codename']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::lsbdistdescription"' do + let(:code) { '"$::lsbdistdescription"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['distro']['description']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::lsbdistid"' do + let(:code) { '"$::lsbdistid"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['distro']['id']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::lsbdistrelease"' do + let(:code) { '"$::lsbdistrelease"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['distro']['release']['full']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::lsbmajdistrelease"' do + let(:code) { '"$::lsbmajdistrelease"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['distro']['release']['major']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::lsbminordistrelease"' do + let(:code) { '"$::lsbminordistrelease"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['distro']['release']['minor']\"") + end + end + + context 'fact variable using legacy variable in double quotes "$::lsbrelease"' do + let(:code) { '"$::lsbrelease"' } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"$facts['os']['distro']['release']['specification']\"") + end + end + + context "fact variable using facts hash in double quotes \"$facts['lsbrelease']\"" do + let(:code) { "\"${facts['lsbrelease']}\"" } + + it 'only detect a single problem' do + expect(problems.size).to eq(1) + end + + it 'uses the facts hash' do + expect(manifest).to eq("\"${facts['os']['distro']['release']['specification']}\"") + end + end + + context 'variable ending in the word fact' do + let(:code) { "$interface_facts['netmask']" } + + it 'does not detect any problems' do + expect(problems.size).to eq(0) + end + end + end +end diff -Nru puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb --- puppet-lint-3.0.1/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ puppet-lint-4.2.4/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb 2024-02-12 13:18:23.000000000 +0000 @@ -0,0 +1,163 @@ +require 'spec_helper' + +describe 'top_scope_facts' do + let(:msg) { 'top scope fact instead of facts hash' } + + context 'with fix disabled' do + context 'fact variable using $facts hash' do + let(:code) { "$facts['operatingsystem']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'non-fact variable with two colons' do + let(:code) { '$foo::bar' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'top scope $::facts hash' do + let(:code) { "$::facts['os']['family']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'top scope $::trusted hash' do + let(:code) { "$::trusted['certname']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'fact variable using top scope' do + let(:code) { '$::fqdn' } + + it 'does not detect a single problem' do + expect(problems).to be_empty + end + end + + context 'out of scope namespaced variable with leading ::' do + let(:code) { '$::profile::foo::bar' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + + context 'inside double quotes' do + let(:code) { '"$::profile::foo::bar"' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'with curly braces in double quote' do + let(:code) { '"${::profile::foo::bar}"' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + end + end + + context 'with fix enabled' do + before(:each) do + PuppetLint.configuration.fix = true + end + + after(:each) do + PuppetLint.configuration.fix = false + end + + context 'fact variable using $facts hash' do + let(:code) { "$facts['operatingsystem']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'non-fact variable with two colons' do + let(:code) { '$foo::bar' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'top scope $::facts hash' do + let(:code) { "$::facts['os']['family']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'top scope structured fact not present on allowlist' do + let(:code) { "$::my_structured_fact['foo']['test']" } + + it 'detects a problem' do + expect(problems).to contain_fixed('top scope fact instead of facts hash').on_line(1).in_column(1) + end + + it 'fixes the problem' do + expect(manifest).to eq("$facts['my_structured_fact']['foo']['test']") + end + end + + context 'top scope $::trusted hash' do + let(:code) { "$::trusted['certname']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'with custom top scope fact variables' do + before(:each) do + PuppetLint.configuration.top_scope_variables = ['location', 'role'] + end + + context 'fact variable using $facts hash' do + let(:code) { "$facts['operatingsystem']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'fact variable using $trusted hash' do + let(:code) { "$trusted['certname']" } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'allowlisted top scope variable $::location' do + let(:code) { '$::location' } + + it 'does not detect any problems' do + expect(problems).to be_empty + end + end + + context 'non-allowlisted top scope variable $::application' do + let(:code) { '$::application' } + + it 'detects a problem' do + expect(problems).to contain_fixed('top scope fact instead of facts hash').on_line(1).in_column(1) + end + end + end + end +end