Module: Onceover::CodeQuality::Syntax

Defined in:
lib/onceover/codequality/syntax.rb

Class Method Summary collapse

Class Method Details

.puppetObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
47
48
49
50
51
52
53
# File 'lib/onceover/codequality/syntax.rb', line 6

def self.puppet
  status = true

  #
  # puppet-syntax
  #

  CodeQuality::Formatter.start_test("puppet-syntax rake task")
  # puppet-syntax seems to assign $stdout/$stderr internally in ways that
  # prevent capturing output. As a nasty hack, run it as inline ruby and
  # capture the output from the process...
  inline_ruby = "    require 'puppet-syntax/tasks/puppet-syntax'\n    PuppetSyntax.exclude_paths = ['vendor/**/*','spec/templates/*.erb']\n    Rake::Task['syntax'].invoke\n  RUBY_CODE\n  #output, s = Open3.capture2e(\"ruby\", \"-e\", inline_ruby)\n  output, ok = CodeQuality::Executor.run(\"ruby\", \"-e\", inline_ruby)\n  status &= ok\n  CodeQuality::Formatter.end_test(output, ok)\n\n  #\n  # python yaml\n  #\n\n  # Python gives us \"better\" validation of YAML data then ruby, eg:\n  # ```yaml\n  #  foo: bar\n  # baz: clive\n  # ```\n  #\n  # would parse only the foo key in ruby, throwing away the baz key due to\n  # a perceived negative indent, whereas python would tell you to fix the\n  # file and make it consistent. This is yaml implementation dependent but\n  # users would be advised to fix the file, so lets _also_ validate yaml\n  # files with python if available on our path...\n  if system(\"python --version && python -c 'import yaml'\", :err => File::NULL)\n    CodeQuality::Formatter.start_test(\"Additional python YAML validation\")\n    script = File.join(File.dirname(File.expand_path(__FILE__)), \"../../../res/validate_yaml.py\")\n    output, ok = CodeQuality::Executor.run(\"python \#{script}\")\n    status &= ok\n    CodeQuality::Formatter.end_test(output, ok)\n  else\n    logger.warn(\"Please install python and pyyaml for enhanced YAML validation (pip install pyyaml)\")\n  end\n\n  status\nend\n"