foodcritic-junit 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12bad8bf7aa77214aa3c58bdba22412d7aeca513
4
+ data.tar.gz: 80b19ac36d383a4583695dacef4b9ace7ee2dd30
5
+ SHA512:
6
+ metadata.gz: df148e0fe16abe20fca200d0973624752c60689bc6204a316202f17f90fbb3118d6670203b0926c856297deed18530ab1d915a546ff5f9449cfcd8627d800c77
7
+ data.tar.gz: bef3a31f0a3749280daeda40f9aad58f5378e756671731fdd5ef12e4673f9408408f907d7bd7b26e3ca6387fbf634eb70dfdc2a1c128b52c9ebdb2cc77148501
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /test/reports/foodcritic-report.xml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foodcritic-junit.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 WebLinc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Foodcritic::Junit
2
+
3
+ Parses foodcritic output (with context) into a JUnit XML file.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ $ bundle exec foodcritic -C . | bundle exec foodcritic-junit
9
+ => Wrote test/reports/report.xml
10
+ ```
11
+
12
+ ## Install
13
+
14
+ ```
15
+ gem 'foodcritic-junit'
16
+ ```
17
+
18
+ ## Options
19
+
20
+ Environment Variables
21
+
22
+ ```
23
+ COOKBOOK_NAME="my_cookbook"
24
+ FOODCRITIC_JUNIT_OUTPUT_DIR="/tmp/"
25
+ FOODCRITIC_JUNIT_OUTPUT_FILE="my_junit_report.xml"
26
+ ```
27
+
28
+ ## Other
29
+
30
+ Pull requests / bug reports welcome :)
31
+
32
+ This gem is released and available under the MIT license.
33
+
34
+ Inspired by [foodcritic-junit-tee](https://github.com/clintoncwolfe/chef-ci-tools/blob/master/bin/foodcritic-junit-tee.rb)
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'foodcritic/junit'
4
+
5
+ Foodcritic::Junit::Outputter.new(ARGF).run
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foodcritic/junit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "foodcritic-junit"
8
+ spec.version = Foodcritic::Junit::VERSION
9
+ spec.authors = ["Thomas Vendetta"]
10
+ spec.email = ["tvendetta@weblinc.com"]
11
+
12
+ spec.summary = %q{Converts FoodCritic output to JUnit XML}
13
+ spec.description = %q{Converts FoodCritic output to JUnit XML}
14
+ spec.homepage = 'http://weblinc.com'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata['allowed_push_host'] = "https://gems.weblinc.com"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+
29
+ spec.bindir = "bin"
30
+ spec.executables = %w(foodcritic-junit)
31
+ spec.require_paths = %w(lib)
32
+
33
+ spec.add_dependency 'foodcritic','>= 9.0.0'
34
+
35
+ spec.add_development_dependency 'pry'
36
+ spec.add_development_dependency "bundler", "~> 1.13"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
@@ -0,0 +1,7 @@
1
+ require 'foodcritic/junit/version'
2
+ require 'foodcritic/junit/outputter'
3
+
4
+ module Foodcritic
5
+ module Junit
6
+ end
7
+ end
@@ -0,0 +1,95 @@
1
+ require 'foodcritic/junit/version'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+ require 'time'
5
+
6
+ module Foodcritic
7
+ module Junit
8
+ class Outputter
9
+
10
+ attr_reader :violations, :cookbook_name, :current_violation, :current_violation_lines,
11
+ :output_dir, :output_file, :current_file_name, :input
12
+
13
+ def initialize(input)
14
+ @input = input
15
+ @violations = []
16
+ @cookbook_name = ENV['COOKBOOK_NAME'] || File.basename(Dir.pwd)
17
+ @output_dir = Pathname.new(ENV['FOODCRITIC_JUNIT_OUTPUT_DIR'] || 'test/reports')
18
+ @output_file = ENV['FOODCRITIC_JUNIT_OUTPUT_FILE'] || 'foodcritic-report.xml'
19
+ end
20
+
21
+ def run
22
+ parse_violations
23
+ write_output
24
+ end
25
+
26
+ def parse_violations
27
+ input.each_line do |line|
28
+ line.chomp!
29
+
30
+ @current_file_name = line if File.exist?(line)
31
+
32
+ violation = line.match(/(?<rule>[A-Z]+\d+?):\s(?<message>.+?)$/)
33
+
34
+ if violation
35
+ # We got a new violation, store the current one + it's lines
36
+ if current_violation
37
+ violations.push({
38
+ rule: current_violation[:rule],
39
+ message: current_violation[:message],
40
+ file_name: current_file_name,
41
+ lines: current_violation_lines.join("\n")
42
+ })
43
+ end
44
+
45
+ @current_violation = violation
46
+ @current_violation_lines = []
47
+ else
48
+ current_violation_lines << line.encode(xml: :attr) if current_violation_lines
49
+ end
50
+ end
51
+ end
52
+
53
+ def output_file_path
54
+ output_dir.join(output_file)
55
+ end
56
+
57
+ def write_output
58
+ output_dir.mkpath
59
+ File.open(output_file_path, 'w') { |f| f.puts(xml) }
60
+ STDERR.puts("Wrote #{output_file_path}")
61
+ end
62
+
63
+ def xml
64
+ <<-EOS
65
+ <?xml version="1.0" encoding="UTF-8"?>
66
+ <testsuites>
67
+ <testsuite name="#{cookbook_name}" timestamp="#{Time.now.utc.iso8601}">
68
+ #{violations_as_xml}
69
+ </testsuite>
70
+ </testsuites>
71
+ EOS
72
+ end
73
+
74
+ def violations_as_xml
75
+ if violations.any?
76
+ violations.map { |v| xml_for_violation(v) }.join("\n")
77
+ else
78
+ '<testcase classname="foodcritic-junit" name="No Errors"/>'
79
+ end
80
+ end
81
+
82
+ def xml_for_violation(violation)
83
+ name = "#{violation[:rule]}: #{violation[:message]}"
84
+ file_name = violation[:file_name]
85
+ <<-EOS
86
+ <testcase name="#{name}" classname="#{file_name}" assertions="0" time="0">
87
+ <error type="#{name}" message="Located in #{file_name}">
88
+ #{violation[:lines]}
89
+ </error>
90
+ </testcase>
91
+ EOS
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ module Foodcritic
2
+ module Junit
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foodcritic-junit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Vendetta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: foodcritic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 9.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 9.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Converts FoodCritic output to JUnit XML
84
+ email:
85
+ - tvendetta@weblinc.com
86
+ executables:
87
+ - foodcritic-junit
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/foodcritic-junit
99
+ - foodcritic-junit.gemspec
100
+ - lib/foodcritic/junit.rb
101
+ - lib/foodcritic/junit/outputter.rb
102
+ - lib/foodcritic/junit/version.rb
103
+ homepage: http://weblinc.com
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Converts FoodCritic output to JUnit XML
126
+ test_files: []