onceover-codequality 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d002a389642fbd94ce6014ecff04a722df6fc11b839f1b89da4af142a45939b
4
- data.tar.gz: 85a5ed0c78832166281dad179ce1dcec6ee635f6a34738444273e3da263c7fba
3
+ metadata.gz: 539deb30ea7e0a162926b170e8adf94de19e7e469eb1212801daedc20b994318
4
+ data.tar.gz: ed7c7de7e391a6faac5e78e66b4edd6ed38868311a299a19e197bba873939471
5
5
  SHA512:
6
- metadata.gz: 63a2b200eec20907c736b91a5bb853f362c5de63ae8b49f4bbef02f26ba06f1a71c3e362f1cb4d6901578a3948da3474c979863a4798d9876f2a4de410e2e06e
7
- data.tar.gz: 8ad26cf6dbc73ab8915719af1fe1a421faf348dd1dadf995d9915602763608132a57b0b6e7e7c5555125f88296ee606fb8261a1f1544002c58d1a1d8fd90ab60
6
+ metadata.gz: 70ea401197ac110b5f53fbd3e4d433889d6171181e88c790ca2eabb5b8fb88163c5427b097875355c296aea3f595650ecf64b8dc1bacb5ef7ffe0f5e2ab75930
7
+ data.tar.gz: 14532de430f9523b8519fca0fe1b3a9aabb27f117446668eeed95ca1b5b4df1c2b70aa2bf0902cff8b930f830d0185dd2990d90524a5e6ba5bf20946a713a0df
@@ -29,36 +29,20 @@ class Onceover
29
29
  html_docs = opts[:html_docs] || false
30
30
  status = true
31
31
 
32
- if ! no_syntax
33
- logger.info "Checking syntax..."
34
- if ! Onceover::CodeQuality::Syntax.puppet
35
- status = false
36
- logger.error "Syntax test failed, see previous errors"
37
- end
32
+ if ! no_puppetfile
33
+ status &= Onceover::CodeQuality::Puppetfile.puppetfile
38
34
  end
39
35
 
40
- if ! no_lint
41
- logger.info "Checking for lint..."
42
- if ! Onceover::CodeQuality::Lint.puppet
43
- status = false
44
- logger.error "Lint test failed, see previous errors"
45
- end
36
+ if ! no_syntax
37
+ status &= Onceover::CodeQuality::Syntax.puppet
46
38
  end
47
39
 
48
- if ! no_puppetfile
49
- logger.info "Checking Puppetfile"
50
- if ! Onceover::CodeQuality::Puppetfile.puppetfile
51
- status = false
52
- logger.error "puppetfile syntax failed, see previous errors"
53
- end
40
+ if ! no_lint
41
+ status &= Onceover::CodeQuality::Lint.puppet
54
42
  end
55
43
 
56
44
  if ! no_docs
57
- logger.info "Generating documentation..."
58
- if ! Onceover::CodeQuality::Docs.puppet_strings(html_docs)
59
- status = false
60
- logger.error "Documentation generation failed, see previous errors"
61
- end
45
+ status &= Onceover::CodeQuality::Docs.puppet_strings(html_docs)
62
46
  end
63
47
 
64
48
  if status
@@ -6,12 +6,18 @@ class Onceover
6
6
  LOCAL_MOD_DIR = "site"
7
7
 
8
8
  def self.puppet_strings(html_docs)
9
+ logger.info "Generating documentation..."
9
10
  status = true
10
11
  format = html_docs ? "html" : "markdown"
11
12
  if Dir.exist?(LOCAL_MOD_DIR)
12
13
  Dir.glob("#{LOCAL_MOD_DIR}/*/") { |dir|
13
14
  Dir.chdir(dir) {
14
- status &= system("puppet strings generate --format #{format}")
15
+ # puppet strings prints useful metrics so don't swallow its output
16
+ s = system("puppet strings generate --format #{format}")
17
+ if ! s
18
+ logger.error("Error running puppet strings - see previous output")
19
+ end
20
+ status &= s
15
21
  }
16
22
  }
17
23
  end
@@ -25,10 +25,13 @@ class Onceover
25
25
  status = true
26
26
  LINT_PATHS.each { |p|
27
27
  if Dir.exists?(p)
28
- logger.info("checking #{p}")
28
+ logger.info("checking lint in #{p}...")
29
29
  if ! system("puppet-lint #{LINT_OPTIONS.join ' '} #{p}")
30
30
  status = false
31
+ else
32
+ logger.info("...ok")
31
33
  end
34
+
32
35
  end
33
36
  }
34
37
 
@@ -4,11 +4,20 @@ class Onceover
4
4
  module Puppetfile
5
5
 
6
6
  def self.puppetfile
7
- if File.exists? "Puppetfile"
8
- status = system("bundle exec r10k puppetfile check")
7
+ status = true
8
+ if File.exist?("Puppetfile")
9
+ logger.info("Checking Puppetfile...")
10
+ output, s = Open3.capture2e("r10k puppetfile check")
11
+ ok = s.exitstatus.zero?
12
+ status &= ok
13
+
14
+ if ok
15
+ logger.info("...ok")
16
+ else
17
+ logger.error("Puppetfile validation failed: #{output}")
18
+ end
9
19
  else
10
- puts "No Puppetfile found!"
11
- status = false
20
+ logger.warn("No Puppetfile found... continuing")
12
21
  end
13
22
 
14
23
  status
@@ -1,23 +1,61 @@
1
- # puppet-syntax does everything we want so we just need a handy way to run
2
- # it and check the result
1
+ require 'open3'
3
2
  class Onceover
4
3
  module CodeQuality
5
4
  module Syntax
5
+
6
6
  def self.puppet
7
7
  status = true
8
- if File.exist?("Puppetfile")
9
- status &= system("r10k puppetfile check")
8
+
9
+ #
10
+ # puppet-lint
11
+ #
12
+
13
+ logger.info("Checking syntax using puppet-syntax rake task...")
14
+ # puppet-syntax seems to assign $stdout/$stderr internally in ways that
15
+ # prevent capturing output. As a nasty hack, run it as inline ruby and
16
+ # capture the output from the process...
17
+ inline_ruby = "require 'puppet-syntax/tasks/puppet-syntax' ; Rake::Task['syntax'].invoke"
18
+ output, s = Open3.capture2e("ruby", "-e", inline_ruby)
19
+ ok = s.exitstatus.zero?
20
+ status &= ok
21
+
22
+ if ok
23
+ logger.info("...ok")
10
24
  else
11
- logger.warn("No Puppetfile found... continuing")
25
+ logger.error("puppet-syntax validation failed: #{output}")
12
26
  end
13
27
 
14
- require 'puppet-syntax/tasks/puppet-syntax'
15
- begin
16
- Rake::Task['syntax'].invoke
17
- rescue SystemExit => e
18
- logger.error("Invalid syntax")
19
- status &= e.status
28
+ #
29
+ # python yaml
30
+ #
31
+
32
+ # Python gives us "better" validation of YAML data then ruby, eg:
33
+ # ```yaml
34
+ # foo: bar
35
+ # baz: clive
36
+ # ```
37
+ #
38
+ # would parse only the foo key in ruby, throwing away the baz key due to
39
+ # a perceived negative indent, whereas python would tell you to fix the
40
+ # file and make it consistent. This is yaml implementation dependent but
41
+ # users would be advised to fix the file, so lets _also_ validate yaml
42
+ # files with python if available on our path...
43
+ if system("python --version", :err => File::NULL)
44
+ logger.info("Running additional python YAML validation")
45
+ script = File.join(File.dirname(File.expand_path(__FILE__)), "../../../res/validate_yaml.py")
46
+ output, s = Open3.capture2e("python #{script}")
47
+ ok = s.exitstatus.zero?
48
+ status &= ok
49
+
50
+ if ok
51
+ logger.info("...ok")
52
+ else
53
+ logger.error("Puppetfile validation failed: #{output}")
54
+ end
55
+ else
56
+ logger.warn("Please install python and add it to your path for enhanced YAML validation")
20
57
  end
58
+
21
59
  status
22
60
  end
23
61
  end
@@ -1,5 +1,5 @@
1
1
  class Onceover
2
2
  module CodeQuality
3
- VERSION = "0.4.2"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -0,0 +1,24 @@
1
+ import sys
2
+ import os
3
+ import re
4
+
5
+ status = 0
6
+ try:
7
+ import yaml
8
+ for root, dirs, files in os.walk("."):
9
+ for f in files:
10
+ # we want yaml files that are not in hidden (.) dirs. account for / vs \ on windows/linux
11
+ target = os.path.join(root, f)
12
+ if target.endswith(".yaml") and not re.match("^\.(/|\\\)\.", target):
13
+ try:
14
+ yaml.safe_load(open(target,"r"))
15
+ except Exception as e:
16
+ status = 1
17
+ print("YAML syntax error in %s: %s" % (target, str(e)))
18
+
19
+ except ImportError as e:
20
+ print("Please install the python-yaml library: pip install pyyaml")
21
+
22
+
23
+ sys.exit(status)
24
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onceover-codequality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Declarative Systems
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2019-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - lib/onceover/codequality/syntax.rb
133
133
  - lib/onceover/codequality/version.rb
134
134
  - onceover-codequality.gemspec
135
+ - res/validate_yaml.py
135
136
  homepage: https://github.com/declarativesystems/onceover-codequality
136
137
  licenses:
137
138
  - Apache-2.0