From 9d1e2d09c1ed90184922891fbc99426375a49c89 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Tue, 24 Oct 2017 17:02:52 -0700 Subject: [PATCH] (maint) Update puppet-lint to 2.3.3 This commit updates the vendored puppet-lint gem to 2.3.3. --- server/Rakefile | 2 +- server/vendor/README.md | 2 +- server/vendor/puppet-lint/.gitignore | 1 + server/vendor/puppet-lint/.rubocop.yml | 74 +++ server/vendor/puppet-lint/.rubocop_todo.yml | 89 ++++ server/vendor/puppet-lint/.travis.yml | 19 +- server/vendor/puppet-lint/CHANGELOG.md | 80 +++- server/vendor/puppet-lint/Gemfile | 3 + server/vendor/puppet-lint/Rakefile | 20 +- server/vendor/puppet-lint/appveyor.yml | 7 +- server/vendor/puppet-lint/bin/puppet-lint | 2 +- server/vendor/puppet-lint/lib/puppet-lint.rb | 47 +- .../vendor/puppet-lint/lib/puppet-lint/bin.rb | 34 +- .../lib/puppet-lint/checkplugin.rb | 41 +- .../puppet-lint/lib/puppet-lint/checks.rb | 73 +-- .../lib/puppet-lint/configuration.rb | 19 +- .../puppet-lint/lib/puppet-lint/data.rb | 400 +++++++++------- .../puppet-lint/lib/puppet-lint/lexer.rb | 428 +++++++++--------- .../lib/puppet-lint/lexer/token.rb | 52 ++- .../lib/puppet-lint/monkeypatches.rb | 53 ++- .../monkeypatches/string_percent.rb | 52 --- .../monkeypatches/string_prepend.rb | 13 - .../puppet-lint/lib/puppet-lint/optparser.rb | 63 +-- .../puppet-lint/lib/puppet-lint/plugins.rb | 80 ++-- .../arrow_on_right_operand_line.rb | 54 ++- .../check_classes/autoloader_layout.rb | 41 +- .../class_inherits_from_params_class.rb | 17 +- .../check_classes/code_on_top_scope.rb | 17 +- .../inherits_across_namespaces.rb | 23 +- .../check_classes/names_containing_dash.rb | 25 +- .../names_containing_uppercase.rb | 27 +- .../nested_classes_or_defines.rb | 19 +- .../plugins/check_classes/parameter_order.rb | 71 +-- .../right_to_left_relationship.rb | 7 +- .../plugins/check_classes/variable_scope.rb | 45 +- .../plugins/check_comments/slash_comments.rb | 7 +- .../plugins/check_comments/star_comments.rb | 13 +- .../case_without_default.rb | 41 +- .../selector_inside_resource.rb | 23 +- .../check_documentation/documentation.rb | 43 +- .../plugins/check_nodes/unquoted_node_name.rb | 24 +- .../check_resources/duplicate_params.rb | 9 +- .../check_resources/ensure_first_param.rb | 35 +- .../ensure_not_symlink_target.rb | 33 +- .../plugins/check_resources/file_mode.rb | 45 +- .../check_resources/unquoted_file_mode.rb | 27 +- .../unquoted_resource_title.rb | 17 +- .../check_strings/double_quoted_strings.rb | 18 +- .../check_strings/only_variable_string.rb | 71 ++- .../puppet_url_without_modules.rb | 11 +- .../plugins/check_strings/quoted_booleans.rb | 7 +- .../single_quote_string_with_variables.rb | 9 +- .../check_strings/variables_not_enclosed.rb | 7 +- .../check_variables/variable_contains_dash.rb | 17 +- .../check_variables/variable_is_lowercase.rb | 17 +- .../plugins/check_whitespace/140chars.rb | 18 +- .../plugins/check_whitespace/2sp_soft_tabs.rb | 9 +- .../plugins/check_whitespace/80chars.rb | 20 +- .../check_whitespace/arrow_alignment.rb | 45 +- .../plugins/check_whitespace/hard_tabs.rb | 7 +- .../check_whitespace/trailing_whitespace.rb | 7 +- .../lib/puppet-lint/tasks/puppet-lint.rb | 8 +- .../lib/puppet-lint/tasks/release_test.rb | 84 ++++ .../puppet-lint/lib/puppet-lint/version.rb | 2 +- server/vendor/puppet-lint/puppet-lint.gemspec | 8 +- 65 files changed, 1582 insertions(+), 1100 deletions(-) create mode 100644 server/vendor/puppet-lint/.rubocop.yml create mode 100644 server/vendor/puppet-lint/.rubocop_todo.yml delete mode 100644 server/vendor/puppet-lint/lib/puppet-lint/monkeypatches/string_percent.rb delete mode 100644 server/vendor/puppet-lint/lib/puppet-lint/monkeypatches/string_prepend.rb create mode 100644 server/vendor/puppet-lint/lib/puppet-lint/tasks/release_test.rb diff --git a/server/Rakefile b/server/Rakefile index 7d3593c9..37dbb187 100644 --- a/server/Rakefile +++ b/server/Rakefile @@ -41,7 +41,7 @@ task :gem_revendor do { :directory => 'puppet-lint', :github_repo => 'https://github.com/rodjek/puppet-lint.git', - :github_ref => '2.3.0', + :github_ref => '2.3.3', } ] diff --git a/server/vendor/README.md b/server/vendor/README.md index 6ad30739..570d9ba7 100644 --- a/server/vendor/README.md +++ b/server/vendor/README.md @@ -11,4 +11,4 @@ Note - To improve the packaging size, test files etc. were stripped from the Gem Gem List -------- -* puppet-lint (https://github.com/rodjek/puppet-lint.git ref 2.3.0) +* puppet-lint (https://github.com/rodjek/puppet-lint.git ref 2.3.3) diff --git a/server/vendor/puppet-lint/.gitignore b/server/vendor/puppet-lint/.gitignore index ef64ab04..03ba157d 100644 --- a/server/vendor/puppet-lint/.gitignore +++ b/server/vendor/puppet-lint/.gitignore @@ -9,3 +9,4 @@ coverage/ /_site/ .idea /*.pp +/tmp/ diff --git a/server/vendor/puppet-lint/.rubocop.yml b/server/vendor/puppet-lint/.rubocop.yml new file mode 100644 index 00000000..9625d507 --- /dev/null +++ b/server/vendor/puppet-lint/.rubocop.yml @@ -0,0 +1,74 @@ +--- +inherit_from: './.rubocop_todo.yml' +AllCops: + TargetRubyVersion: 1.9 + +Style/HashSyntax: + EnforcedStyle: hash_rockets + +Layout/FirstArrayElementLineBreak: + Enabled: true +Layout/FirstHashElementLineBreak: + Enabled: true +Layout/FirstMethodArgumentLineBreak: + Enabled: true +Layout/FirstMethodParameterLineBreak: + Enabled: true +Layout/IndentArray: + EnforcedStyle: consistent +Layout/MultilineArrayBraceLayout: + EnforcedStyle: new_line +Layout/MultilineAssignmentLayout: + Enabled: true + EnforcedStyle: same_line +Layout/MultilineHashBraceLayout: + EnforcedStyle: new_line +Layout/MultilineMethodDefinitionBraceLayout: + EnforcedStyle: new_line + +Style/AutoResourceCleanup: + Enabled: true +Style/BlockDelimiters: + EnforcedStyle: braces_for_chaining +Style/BracesAroundHashParameters: + EnforcedStyle: context_dependent +Style/Encoding: + Enabled: false +Style/MethodCallWithArgsParentheses: + Enabled: true + IgnoreMacros: true + IgnoredMethods: + - puts + - require + - include + - it + - context + - describe + - to + - to_not + - raise + - desc + - task + - exit + - should + - gem + - group + - attr_reader + - attr_accessor + - attr_writer + - source +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/RegexpLiteral: + EnforcedStyle: percent_r +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: no_comma +Style/TrailingCommaInLiteral: + EnforcedStyleForMultiline: comma +Style/FormatStringToken: + Enabled: false +Style/FileName: + Exclude: + - 'lib/puppet-lint.rb' + - 'lib/puppet-lint/tasks/puppet-lint.rb' + - 'spec/puppet-lint_spec.rb' diff --git a/server/vendor/puppet-lint/.rubocop_todo.yml b/server/vendor/puppet-lint/.rubocop_todo.yml new file mode 100644 index 00000000..c4446754 --- /dev/null +++ b/server/vendor/puppet-lint/.rubocop_todo.yml @@ -0,0 +1,89 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2017-08-28 12:57:58 +1000 using RuboCop version 0.49.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Configuration parameters: Include. +# Include: **/Gemfile, **/gems.rb +Bundler/DuplicatedGem: + Exclude: + - 'Gemfile' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: Include, TreatCommentsAsGroupSeparators. +# Include: **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + +# Offense count: 9 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'lib/puppet-lint/lexer.rb' + - 'lib/puppet-lint/plugins/check_classes/variable_scope.rb' + +# Offense count: 52 +Metrics/AbcSize: + Max: 153 + +# Offense count: 121 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 1136 + +# Offense count: 8 +# Configuration parameters: CountBlocks. +Metrics/BlockNesting: + Max: 5 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 383 + +# Offense count: 20 +Metrics/CyclomaticComplexity: + Max: 26 + +# Offense count: 238 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 223 + +# Offense count: 65 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 94 + +# Offense count: 18 +Metrics/PerceivedComplexity: + Max: 25 + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/RedundantBlockCall: + Exclude: + - 'lib/puppet-lint/tasks/puppet-lint.rb' + +# Offense count: 7 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'lib/puppet-lint.rb' + - 'lib/puppet-lint/bin.rb' + - 'lib/puppet-lint/checkplugin.rb' + - 'lib/puppet-lint/checks.rb' + - 'lib/puppet-lint/data.rb' + - 'lib/puppet-lint/optparser.rb' + +# Offense count: 20 +Style/MultilineBlockChain: + Enabled: false diff --git a/server/vendor/puppet-lint/.travis.yml b/server/vendor/puppet-lint/.travis.yml index 51d3210c..0b396968 100644 --- a/server/vendor/puppet-lint/.travis.yml +++ b/server/vendor/puppet-lint/.travis.yml @@ -6,16 +6,19 @@ branches: only: - master bundler_args: --without development system_tests +script: + - bundle exec rake $CHECK +env: + - CHECK=ci rvm: - 1.8.7 - 1.9.3 - 2.0.0 - - 2.1.9 - - 2.3.1 - - 2.4.0 + - 2.1.10 + - 2.2.7 + - 2.3.4 + - 2.4.1 matrix: - allow_failures: - - rvm: 1.8.7 -notifications: - email: - - tim@bombasticmonkey.com + include: + - rvm: 2.4.1 + env: CHECK=rubocop diff --git a/server/vendor/puppet-lint/CHANGELOG.md b/server/vendor/puppet-lint/CHANGELOG.md index 5ba8c408..3fc8b33d 100644 --- a/server/vendor/puppet-lint/CHANGELOG.md +++ b/server/vendor/puppet-lint/CHANGELOG.md @@ -1,5 +1,83 @@ # Change Log +## [2.3.3](https://github.com/rodjek/puppet-lint/tree/2.3.3) (2017-09-28) +[Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.3.2...2.3.3) + +**Closed issues:** + +- 2.3.2 - Rakefile's ignore\_paths not respected [\#760](https://github.com/rodjek/puppet-lint/issues/760) +- 2.3.1 - Puppet lint fails with 1.8.7-p371 and Puppet 3.8.0 [\#759](https://github.com/rodjek/puppet-lint/issues/759) +- 2.3.1: puppet-lint does not show errors/warnings --error-level option. [\#756](https://github.com/rodjek/puppet-lint/issues/756) + +**Merged pull requests:** + +- Add some basic acceptance tests [\#764](https://github.com/rodjek/puppet-lint/pull/764) ([rodjek](https://github.com/rodjek)) +- Restore Ruby 1.8.7 support [\#763](https://github.com/rodjek/puppet-lint/pull/763) ([rodjek](https://github.com/rodjek)) +- Don't override ignore\_paths set in rake task with default value [\#762](https://github.com/rodjek/puppet-lint/pull/762) ([rodjek](https://github.com/rodjek)) +- Add spec for issue raised in \#754 \#756 [\#761](https://github.com/rodjek/puppet-lint/pull/761) ([rodjek](https://github.com/rodjek)) +- Fix setup of default log\_format in PuppetLink.configuration when it is empty. [\#757](https://github.com/rodjek/puppet-lint/pull/757) ([zekefast](https://github.com/zekefast)) + +## [2.3.2](https://github.com/rodjek/puppet-lint/tree/2.3.2) (2017-09-27) +[Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.3.1...2.3.2) + +**Fixed bugs:** + +- configuration, method_missing had faulty logic [\#754](https://github.com/rodjek/puppet-lint/issues/754) + +## [2.3.1](https://github.com/rodjek/puppet-lint/tree/2.3.1) (2017-09-27) +[Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.3.0...2.3.1) + +**Fixed bugs:** + +- NoMethodError: undefined method `type' for nil:NilClass [\#732](https://github.com/rodjek/puppet-lint/issues/732) +- NoMethodError: undefined method `end\_with?' for nil:NilClass [\#727](https://github.com/rodjek/puppet-lint/issues/727) +- puppet-lint not applying some lint:ignore statements when there are more then 2 on the same line [\#726](https://github.com/rodjek/puppet-lint/issues/726) +- optional paramter warning false positve when inheriting params [\#716](https://github.com/rodjek/puppet-lint/issues/716) +- invalid byte sequence in UTF-8 in selmodule-example.pp [\#714](https://github.com/rodjek/puppet-lint/issues/714) +- puppet-lint --fix encountered an error that it doesn't know how to handle [\#706](https://github.com/rodjek/puppet-lint/issues/706) +- Mangled file after running puppet-lint due to chained function call [\#703](https://github.com/rodjek/puppet-lint/issues/703) +- `incompatible encoding regexp match` for non-printing characters in place of space [\#693](https://github.com/rodjek/puppet-lint/issues/693) +- Unhandled error case [\#691](https://github.com/rodjek/puppet-lint/issues/691) + +**Closed issues:** + +- puppet-lint has encountered an error that it doesn't know how to handle [\#750](https://github.com/rodjek/puppet-lint/issues/750) +- Variable use like "a+1 = ${$a + 1}" isn't reported but silently changed by --fix to "a+1 = ${a} + 1" [\#749](https://github.com/rodjek/puppet-lint/issues/749) +- using --fix changes line endings [\#748](https://github.com/rodjek/puppet-lint/issues/748) +- Puppet lint syntax error - puppet parser validate no issues [\#746](https://github.com/rodjek/puppet-lint/issues/746) +- Error not handled [\#745](https://github.com/rodjek/puppet-lint/issues/745) +- Whoops, not sure why. ArgumentError: bad value for range [\#742](https://github.com/rodjek/puppet-lint/issues/742) +- ArgumentError: bad value for range [\#741](https://github.com/rodjek/puppet-lint/issues/741) +- Line numbers off after multi-line strings with variables [\#736](https://github.com/rodjek/puppet-lint/issues/736) +- Whoops! It looks like puppet-lint has encountered an error [\#729](https://github.com/rodjek/puppet-lint/issues/729) +- puppet lint config log\_format not working [\#725](https://github.com/rodjek/puppet-lint/issues/725) +- Quoted booleans in Puppet5 for Enum type declarations. [\#720](https://github.com/rodjek/puppet-lint/issues/720) +- Chaining arrow syntax fix introduces trailing whitespaces [\#695](https://github.com/rodjek/puppet-lint/issues/695) +- Refactor check\_comments.rb [\#587](https://github.com/rodjek/puppet-lint/issues/587) +- Puppethack 12/2016 Issues [\#583](https://github.com/rodjek/puppet-lint/issues/583) +- Allow multiple block-level ignore comments [\#498](https://github.com/rodjek/puppet-lint/issues/498) +- puppet-lint crashes with "invalid byte sequence in UTF-8 \(ArgumentError\)" [\#458](https://github.com/rodjek/puppet-lint/issues/458) + +**Merged pull requests:** + +- Render the ${} enclosures as part of the string tokens [\#752](https://github.com/rodjek/puppet-lint/pull/752) ([rodjek](https://github.com/rodjek)) +- Open manifest as binary when writing fixed manifest [\#751](https://github.com/rodjek/puppet-lint/pull/751) ([rodjek](https://github.com/rodjek)) +- Remove monkeypatches to implement String\#% [\#744](https://github.com/rodjek/puppet-lint/pull/744) ([rodjek](https://github.com/rodjek)) +- Add unit tests for PuppetLint::Checks [\#743](https://github.com/rodjek/puppet-lint/pull/743) ([rodjek](https://github.com/rodjek)) +- Update CI configuration [\#739](https://github.com/rodjek/puppet-lint/pull/739) ([rodjek](https://github.com/rodjek)) +- Rubocop compliance [\#738](https://github.com/rodjek/puppet-lint/pull/738) ([rodjek](https://github.com/rodjek)) +- Fix line numbers being off with multi-line strings containing variables [\#737](https://github.com/rodjek/puppet-lint/pull/737) ([cbowman0](https://github.com/cbowman0)) +- Split control comments into words before parsing [\#735](https://github.com/rodjek/puppet-lint/pull/735) ([rodjek](https://github.com/rodjek)) +- Handle unicode spaces in the tokeniser [\#734](https://github.com/rodjek/puppet-lint/pull/734) ([rodjek](https://github.com/rodjek)) +- Handle SE Linux policy package files [\#733](https://github.com/rodjek/puppet-lint/pull/733) ([rodjek](https://github.com/rodjek)) +- Take into account Optional data type when checking parameter order [\#731](https://github.com/rodjek/puppet-lint/pull/731) ([rodjek](https://github.com/rodjek)) +- Read the manifest files as UTF-8 [\#730](https://github.com/rodjek/puppet-lint/pull/730) ([rodjek](https://github.com/rodjek)) +- Improve handling of unterminated double quoted strings [\#728](https://github.com/rodjek/puppet-lint/pull/728) ([rodjek](https://github.com/rodjek)) +- Chaining arrow syntax fix introduces trailing whitespaces [\#708](https://github.com/rodjek/puppet-lint/pull/708) ([rnelson0](https://github.com/rnelson0)) +- Add helper methods to add and remove tokens while maintaining the token links [\#694](https://github.com/rodjek/puppet-lint/pull/694) ([Darhazer](https://github.com/Darhazer)) +- Code style improvements [\#661](https://github.com/rodjek/puppet-lint/pull/661) ([Darhazer](https://github.com/Darhazer)) +- Plugins: Improve code readability [\#658](https://github.com/rodjek/puppet-lint/pull/658) ([Darhazer](https://github.com/Darhazer)) + ## [2.3.0](https://github.com/rodjek/puppet-lint/tree/2.3.0) (2017-07-12) [Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.2.1...2.3.0) @@ -843,4 +921,4 @@ If the additional gems you use for checks are pinned to 1.x, you should pin pupp ## [0.0.1](https://github.com/rodjek/puppet-lint/tree/0.0.1) (2011-08-15) -\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* diff --git a/server/vendor/puppet-lint/Gemfile b/server/vendor/puppet-lint/Gemfile index 917f32d8..cd905784 100644 --- a/server/vendor/puppet-lint/Gemfile +++ b/server/vendor/puppet-lint/Gemfile @@ -25,6 +25,9 @@ group :test do # requires ruby 1.9+, on 1.8 we'll fall back to the old regex parsing gem 'rspec-json_expectations', '~> 1.4' end + + gem 'rubocop', '0.49.1' if RUBY_VERSION > '2.0' + gem 'simplecov', :require => false end group :development do diff --git a/server/vendor/puppet-lint/Rakefile b/server/vendor/puppet-lint/Rakefile index 3e3d320e..a32b64be 100644 --- a/server/vendor/puppet-lint/Rakefile +++ b/server/vendor/puppet-lint/Rakefile @@ -1,6 +1,7 @@ require 'rake' require 'rspec/core/rake_task' require 'puppet-lint' +require 'puppet-lint/tasks/release_test' task :default => :test @@ -8,12 +9,25 @@ RSpec::Core::RakeTask.new(:test) begin require 'github_changelog_generator/task' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| + GitHubChangelogGenerator::RakeTask.new(:changelog) do |config| version = PuppetLint::VERSION - config.future_release = "#{version}" - config.exclude_labels = %w{duplicate question invalid wontfix release-pr} + config.future_release = version.to_s + config.exclude_labels = %w[duplicate question invalid wontfix release-pr] end rescue LoadError + $stderr.puts 'Changelog generation requires Ruby 2.0 or higher' end +begin + require 'rubocop/rake_task' + + RuboCop::RakeTask.new(:rubocop) do |task| + task.options = %w[-D -E] + end +rescue LoadError + $stderr.puts 'Rubocop is not available for this version of Ruby.' +end + +task :ci => [:test, :release_test] + # vim: syntax=ruby diff --git a/server/vendor/puppet-lint/appveyor.yml b/server/vendor/puppet-lint/appveyor.yml index 955379f7..79d4814c 100644 --- a/server/vendor/puppet-lint/appveyor.yml +++ b/server/vendor/puppet-lint/appveyor.yml @@ -12,6 +12,7 @@ environment: - RUBY_VERSION: 21 - RUBY_VERSION: 22 - RUBY_VERSION: 23-x64 + - RUBY_VERSION: 24-x64 install: - SET PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% @@ -25,8 +26,4 @@ before_test: - bundle -v test_script: - - bundle exec rake test - -notifications: - email: - - tim@bombasticmonkey.com + - bundle exec rake ci diff --git a/server/vendor/puppet-lint/bin/puppet-lint b/server/vendor/puppet-lint/bin/puppet-lint index 3e83f38d..ea05b9f5 100644 --- a/server/vendor/puppet-lint/bin/puppet-lint +++ b/server/vendor/puppet-lint/bin/puppet-lint @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'puppet-lint' diff --git a/server/vendor/puppet-lint/lib/puppet-lint.rb b/server/vendor/puppet-lint/lib/puppet-lint.rb index bf5a8a5a..b8003215 100644 --- a/server/vendor/puppet-lint/lib/puppet-lint.rb +++ b/server/vendor/puppet-lint/lib/puppet-lint.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require 'set' require 'json' require 'puppet-lint/version' @@ -47,7 +49,7 @@ class PuppetLint # Public: Initialise a new PuppetLint object. def initialize @code = nil - @statistics = {:error => 0, :warning => 0, :fixed => 0, :ignored => 0} + @statistics = { :error => 0, :warning => 0, :fixed => 0, :ignored => 0 } @manifest = '' end @@ -70,10 +72,16 @@ def configuration # # Returns nothing. def file=(path) - if File.exist? path - @path = path - @code = File.read(path) + return unless File.exist?(path) + + @path = path + File.open(path, 'r:UTF-8') do |f| + @code = f.read end + + # 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 end # Internal: Retrieve the format string to be used when writing problems to @@ -82,15 +90,14 @@ def file=(path) # # Returns a format String to be used with String#%. def log_format - if configuration.log_format == '' + if configuration.log_format.nil? || configuration.log_format.empty? ## recreate previous old log format as far as thats possible. format = '%{KIND}: %{message} on line %{line}' - if configuration.with_filename - format.prepend '%{path} - ' - end + format.prepend('%{path} - ') if configuration.with_filename configuration.log_format = format end - return configuration.log_format + + configuration.log_format end # Internal: Format a problem message and print it to STDOUT. @@ -101,9 +108,8 @@ def log_format def format_message(message) format = log_format puts format % message - if message[:kind] == :ignored && !message[:reason].nil? - puts " #{message[:reason]}" - end + + puts " #{message[:reason]}" if message[:kind] == :ignored && !message[:reason].nil? end # Internal: Get the line of the manifest on which the problem was found @@ -112,8 +118,7 @@ def format_message(message) # # Returns the problematic line as a string. def get_context(message) - line = PuppetLint::Data.manifest_lines[message[:line] - 1] - return line.strip + PuppetLint::Data.manifest_lines[message[:line] - 1].strip end # Internal: Print out the line of the manifest on which the problem was found @@ -126,9 +131,9 @@ def print_context(message) return if message[:check] == 'documentation' return if message[:kind] == :fixed line = get_context(message) - offset = line.index(/\S/) || 1 + offset = line.index(%r{\S}) || 1 puts "\n #{line.strip}" - printf "%#{message[:column] + 2 - offset}s\n\n", '^' + printf("%#{message[:column] + 2 - offset}s\n\n", '^') end # Internal: Print the reported problems with a manifest to stdout. @@ -149,12 +154,14 @@ def report(problems) message['context'] = get_context(message) if configuration.with_context json << message else - format_message message + format_message(message) print_context(message) if configuration.with_context end end end puts JSON.pretty_generate(json) if configuration.json + + $stderr.puts 'Try running `puppet parser validate `' if problems.any? { |p| p[:check] == :syntax } end # Public: Determine if PuppetLint found any errors in the manifest. @@ -177,9 +184,7 @@ def warnings? # Returns nothing. # Raises PuppetLint::NoCodeError if no manifest code has been loaded. def run - if @code.nil? - raise PuppetLint::NoCodeError - end + raise PuppetLint::NoCodeError if @code.nil? if @code.empty? @problems = [] @@ -198,7 +203,7 @@ def run # # Returns nothing. def print_problems - report @problems + report(@problems) end # Public: Define a new check. diff --git a/server/vendor/puppet-lint/lib/puppet-lint/bin.rb b/server/vendor/puppet-lint/lib/puppet-lint/bin.rb index 6c967958..73d6b8a4 100644 --- a/server/vendor/puppet-lint/lib/puppet-lint/bin.rb +++ b/server/vendor/puppet-lint/lib/puppet-lint/bin.rb @@ -23,8 +23,8 @@ def run begin opts.parse!(@args) - rescue OptionParser::InvalidOption - puts "puppet-lint: #{$!.message}" + rescue OptionParser::InvalidOption => e + puts "puppet-lint: #{e.message}" puts "puppet-lint: try 'puppet-lint --help' for more information" return 1 end @@ -35,22 +35,20 @@ def run end if @args[0].nil? - puts "puppet-lint: no file specified" + puts 'puppet-lint: no file specified' puts "puppet-lint: try 'puppet-lint --help' for more information" return 1 end begin path = @args[0] - if File.directory?(path) - path = Dir.glob("#{path}/**/*.pp") - else - path = @args - end + path = if File.directory?(path) + Dir.glob("#{path}/**/*.pp") + else + @args + end - if path.length > 1 - PuppetLint.configuration.with_filename = true - end + PuppetLint.configuration.with_filename = true if path.length > 1 return_val = 0 @@ -60,24 +58,22 @@ def run l.file = f l.run l.print_problems - puts ',' if f != path.last and PuppetLint.configuration.json + puts ',' if f != path.last && PuppetLint.configuration.json - if l.errors? or (l.warnings? and PuppetLint.configuration.fail_on_warnings) + if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings) return_val = 1 end - if PuppetLint.configuration.fix && !l.problems.any? { |e| e[:check] == :syntax } - File.open(f, 'w') do |fd| - fd.write l.manifest - end + next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax } + File.open(f, 'wb') do |fd| + fd.write(l.manifest) end end puts ']' if PuppetLint.configuration.json return return_val - rescue PuppetLint::NoCodeError - puts "puppet-lint: no file specified or specified file does not exist" + puts 'puppet-lint: no file specified or specified file does not exist' puts "puppet-lint: try 'puppet-lint --help' for more information" return 1 end diff --git a/server/vendor/puppet-lint/lib/puppet-lint/checkplugin.rb b/server/vendor/puppet-lint/lib/puppet-lint/checkplugin.rb index fb952c4b..a1fa6573 100644 --- a/server/vendor/puppet-lint/lib/puppet-lint/checkplugin.rb +++ b/server/vendor/puppet-lint/lib/puppet-lint/checkplugin.rb @@ -21,11 +21,11 @@ def run check @problems.each do |problem| - if problem[:check] != :syntax && PuppetLint::Data.ignore_overrides[problem[:check]].has_key?(problem[:line]) - problem[:kind] = :ignored - problem[:reason] = PuppetLint::Data.ignore_overrides[problem[:check]][problem[:line]] - next - end + next if problem[:check] == :syntax + next unless PuppetLint::Data.ignore_overrides[problem[:check]].key?(problem[:line]) + + problem[:kind] = :ignored + problem[:reason] = PuppetLint::Data.ignore_overrides[problem[:check]][problem[:line]] end @problems @@ -36,14 +36,13 @@ def run # Returns an Array of problem Hashes. def fix_problems @problems.reject { |problem| problem[:kind] == :ignored || problem[:check] == :syntax }.each do |problem| - if self.respond_to?(:fix) - begin - fix(problem) - rescue PuppetLint::NoFix - # noop - else - problem[:kind] = :fixed - end + next unless respond_to?(:fix) + + begin + fix(problem) + problem[:kind] = :fixed + rescue PuppetLint::NoFix # rubocop:disable Lint/HandleExceptions + # noop end end @@ -59,6 +58,14 @@ def tokens PuppetLint::Data.tokens end + def add_token(index, token) + PuppetLint::Data.insert(index, token) + end + + def remove_token(token) + PuppetLint::Data.delete(token) + end + # Public: Provides the resource titles to the check plugins. # # Returns an Array of PuppetLint::Lexer::Token objects. @@ -159,14 +166,14 @@ def default_info # Returns nothing. def notify(kind, problem) problem[:kind] = kind - problem.merge!(default_info) { |key, v1, v2| v1 } + problem.merge!(default_info) { |_key, v1, _v2| v1 } - unless [:warning, :error, :fixed].include? kind - raise ArgumentError, "unknown value passed for kind" + unless [:warning, :error, :fixed].include?(kind) + raise ArgumentError, 'unknown value passed for kind' end [:message, :line, :column, :check].each do |attr| - unless problem.has_key? attr + unless problem.key?(attr) raise ArgumentError, "problem hash must contain #{attr.inspect}" end end diff --git a/server/vendor/puppet-lint/lib/puppet-lint/checks.rb b/server/vendor/puppet-lint/lib/puppet-lint/checks.rb index 3936af16..40707631 100644 --- a/server/vendor/puppet-lint/lib/puppet-lint/checks.rb +++ b/server/vendor/puppet-lint/lib/puppet-lint/checks.rb @@ -25,10 +25,16 @@ def load_data(path, content) PuppetLint::Data.tokens = lexer.tokenise(content) PuppetLint::Data.parse_control_comments rescue PuppetLint::LexerError => e + message = if e.reason.nil? + 'Syntax error' + else + "Syntax error (#{e.reason})" + end + problems << { :kind => :error, :check => :syntax, - :message => 'Syntax error (try running `puppet parser validate `)', + :message => message, :line => e.line_no, :column => e.column, :fullpath => PuppetLint::Data.fullpath, @@ -41,20 +47,16 @@ def load_data(path, content) # Internal: Run the lint checks over the manifest code. # - # fileinfo - A Hash containing the following: - # :fullpath - The expanded path to the file as a String. - # :filename - The name of the file as a String. - # :path - The original path to the file as passed to puppet-lint as - # a String. + # fileinfo - The path to the file as passed to puppet-lint as a String. # data - The String manifest code to be checked. # # Returns an Array of problem Hashes. def run(fileinfo, data) load_data(fileinfo, data) - checks_run = [] enabled_checks.each do |check| klass = PuppetLint.configuration.check_object[check].new + # FIXME: shadowing #problems problems = klass.run if PuppetLint.configuration.fix @@ -66,25 +68,34 @@ def run(fileinfo, data) @problems rescue => e - puts <<-END -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 -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} -file contents: -``` -#{File.read(fileinfo) if File.readable?(fileinfo)} -``` -error: -``` -#{e.class}: #{e.message} -#{e.backtrace.join("\n")} -``` -END + $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 + 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} + END + + if File.readable?(fileinfo) + $stdout.puts [ + 'file contents:', + '```', + File.read(fileinfo), + '```', + ].join("\n") + end + + $stdout.puts [ + 'error:', + '```', + "#{e.class}: #{e.message}", + e.backtrace.join("\n"), + '```', + ].join("\n") + exit 1 end @@ -92,17 +103,17 @@ def run(fileinfo, data) # # Returns an Array of String check names. def enabled_checks - @enabled_checks ||= Proc.new do - PuppetLint.configuration.checks.select { |check| + @enabled_checks ||= begin + PuppetLint.configuration.checks.select do |check| PuppetLint.configuration.send("#{check}_enabled?") - } - end.call + end + end end # Internal: Render the fixed manifest. # # Returns the manifest as a String. def manifest - PuppetLint::Data.tokens.map { |t| t.to_manifest }.join('') + PuppetLint::Data.tokens.map(&:to_manifest).join('') end end diff --git a/server/vendor/puppet-lint/lib/puppet-lint/configuration.rb b/server/vendor/puppet-lint/lib/puppet-lint/configuration.rb index 0862edcd..8912ab03 100644 --- a/server/vendor/puppet-lint/lib/puppet-lint/configuration.rb +++ b/server/vendor/puppet-lint/lib/puppet-lint/configuration.rb @@ -49,14 +49,16 @@ def self.add_check(check) # Signature # #