Class: PuppetLint::Checks
- Inherits:
-
Object
- Object
- PuppetLint::Checks
- Defined in:
- lib/puppet-lint/checks.rb
Overview
Internal: Various methods that orchestrate the actions of the puppet-lint check plugins.
Instance Attribute Summary collapse
-
#problems ⇒ Object
Public: Get an Array of problem Hashes.
Instance Method Summary collapse
-
#enabled_checks ⇒ Object
Internal: Get a list of checks that have not been disabled.
-
#initialize ⇒ Checks
constructor
Public: Initialise a new PuppetLint::Checks object.
-
#load_data(path, content) ⇒ Object
Internal: Tokenise the manifest code and prepare it for checking.
-
#manifest ⇒ Object
Internal: Render the fixed manifest.
-
#run(fileinfo, data) ⇒ Object
Internal: Run the lint checks over the manifest code.
Constructor Details
#initialize ⇒ Checks
Public: Initialise a new PuppetLint::Checks object.
10 11 12 |
# File 'lib/puppet-lint/checks.rb', line 10 def initialize @problems = [] end |
Instance Attribute Details
#problems ⇒ Object
Public: Get an Array of problem Hashes.
7 8 9 |
# File 'lib/puppet-lint/checks.rb', line 7 def problems @problems end |
Instance Method Details
#enabled_checks ⇒ Object
Internal: Get a list of checks that have not been disabled.
Returns an Array of String check names.
118 119 120 121 122 123 124 |
# File 'lib/puppet-lint/checks.rb', line 118 def enabled_checks @enabled_checks ||= begin PuppetLint.configuration.checks.select do |check| PuppetLint.configuration.send("#{check}_enabled?") end end end |
#load_data(path, content) ⇒ Object
Internal: Tokenise the manifest code and prepare it for checking.
path - The path to the file as passed to puppet-lint as a String. content - The String manifest code to be checked.
Returns nothing.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet-lint/checks.rb', line 20 def load_data(path, content) lexer = PuppetLint::Lexer.new PuppetLint::Data.path = path PuppetLint::Data.manifest_lines = content.split("\n", -1) begin PuppetLint::Data.tokens = lexer.tokenise(content) PuppetLint::Data.parse_control_comments rescue PuppetLint::LexerError => e = if e.reason.nil? 'Syntax error' else "Syntax error (#{e.reason})" end problems << { :kind => :error, :check => :syntax, :message => , :line => e.line_no, :column => e.column, :fullpath => PuppetLint::Data.fullpath, :path => PuppetLint::Data.path, :filename => PuppetLint::Data.filename, } PuppetLint::Data.tokens = [] end end |
#manifest ⇒ Object
Internal: Render the fixed manifest.
Returns the manifest as a String.
129 130 131 |
# File 'lib/puppet-lint/checks.rb', line 129 def manifest PuppetLint::Data.tokens.map(&:to_manifest).join('') end |
#run(fileinfo, data) ⇒ Object
Internal: Run the lint checks over the manifest code.
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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/puppet-lint/checks.rb', line 54 def run(fileinfo, data) load_data(fileinfo, data) enabled_checks.each do |check| klass = PuppetLint.configuration.check_object[check].new # FIXME: shadowing #problems problems = klass.run if PuppetLint.configuration.fix @problems.concat(klass.fix_problems) else @problems.concat(problems) end end @problems rescue PuppetLint::SyntaxError => e @problems << { :kind => :error, :check => :syntax, :message => 'Syntax error', :fullpath => File.(fileinfo, ENV['PWD']), :filename => File.basename(fileinfo), :path => fileinfo, :line => e.token.line, :column => e.token.column, } @problems rescue => e $stdout.puts " Whoops! It looks like puppet-lint has encountered an error that it doesn't\n know how to handle. Please open an issue at https://github.com/rodjek/puppet-lint\n and paste the following output into the issue description.\n ---\n puppet-lint version: \#{PuppetLint::VERSION}\n ruby version: \#{RUBY_VERSION}-p\#{RUBY_PATCHLEVEL}\n platform: \#{RUBY_PLATFORM}\n file path: \#{fileinfo}\n END\n\n if File.readable?(fileinfo)\n $stdout.puts [\n 'file contents:',\n '```',\n File.read(fileinfo),\n '```',\n ].join(\"\\n\")\n end\n\n $stdout.puts [\n 'error:',\n '```',\n \"\#{e.class}: \#{e.message}\",\n e.backtrace.join(\"\\n\"),\n '```',\n ].join(\"\\n\")\n\n exit 1\nend\n".gsub(%r{^ {6}}, '') |