rubocop-junit_formatter 0.1

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
+ SHA256:
3
+ metadata.gz: 4576a49e7879e14885f77226dcc298974fc1a31456c02c5836430c6fdb66f21a
4
+ data.tar.gz: 8dc8d5f746439b6caab9df72f38303c8a30933dc03400dd9e8da832cece3ed88
5
+ SHA512:
6
+ metadata.gz: d2a83f7905f351449d5b5e2bf69dc13a49f926f597da59df4fd00221db970880aef34e541f670191a8bccdfb904a147818f41152e26a8d84fe2f41cb0d13471e
7
+ data.tar.gz: 1a1a5e9cc7c4e19ce470dc4f91d3fcefdc33f367f78077666d3c33cec8fdcf648a3dcdc7af239078b6a1ab881ab62f5e57ceca338939c61c59b68b4198dc3390
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
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,2 @@
1
+ # rubocop-junit_formatter
2
+ A JUnit Formatter for RuboCop
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,89 @@
1
+ require "rubocop/formatter/clang_style_formatter"
2
+ require "rexml/document"
3
+ require "pathname"
4
+
5
+ module RuboCop
6
+ module Formatter
7
+ class JUnitFormatter < ClangStyleFormatter
8
+ def initialize(output, options = {})
9
+ super
10
+ @failures = 0
11
+ end
12
+
13
+ def started(target_files)
14
+ @document = REXML::Document.new
15
+ @document << REXML::XMLDecl.new.tap do |declaration|
16
+ declaration.encoding = "UTF-8"
17
+ end
18
+
19
+ @testsuite = @document.add_element("testsuite")
20
+ @testsuite.add_attributes(
21
+ "name" => "RuboCop",
22
+ "tests" => target_files.size,
23
+ "timestamp" => DateTime.now.new_offset(0)
24
+ )
25
+ end
26
+
27
+ def file_started(file, options)
28
+ @files ||= {}
29
+ @files[file] = Time.now
30
+ end
31
+
32
+ def file_finished(file, offenses)
33
+ time = Time.now - @files[file]
34
+ @failures += 1 if offenses.any?
35
+
36
+ file_smart_path = smart_path(file)
37
+
38
+ testcase = @testsuite.add_element("testcase")
39
+ testcase.add_attributes(
40
+ "name" => file_smart_path,
41
+ "file" => file_smart_path,
42
+ "failures" => offenses.size,
43
+ "time" => time.round(6)
44
+ )
45
+
46
+ offenses.each do |offense|
47
+ failure = testcase.add_element("failure")
48
+ failure.add_attributes(
49
+ "message" => offense.message,
50
+ "type" => offense.severity.to_s
51
+ )
52
+
53
+ text = sprintf(
54
+ "%s:%d:%d: %s: %s\n",
55
+ file_smart_path,
56
+ offense.line,
57
+ offense.real_column,
58
+ offense.severity.code,
59
+ offense.message
60
+ )
61
+
62
+ begin
63
+ if valid_line?(offense)
64
+ source_line = offense.location.source_line
65
+
66
+ if offense.location.first_line == offense.location.last_line
67
+ text << "#{source_line}\n"
68
+ else
69
+ text << "#{source_line} #{yellow(ELLIPSES)}\n"
70
+ end
71
+
72
+ text << "#{' ' * offense.highlighted_area.begin_pos}" \
73
+ "#{'^' * offense.highlighted_area.size}"
74
+ end
75
+ rescue IndexError
76
+ # range is not on a valid line; perhaps the source file is empty
77
+ end
78
+
79
+ failure.add_text(text)
80
+ end
81
+ end
82
+
83
+ def finished(inspected_files)
84
+ @testsuite.add_attribute("failures", @failures)
85
+ @document.write(output)
86
+ end
87
+ end
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-junit_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Ngan Pham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ description:
28
+ email:
29
+ - nganpham@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - lib/rubocop/formatter/junit_formatter.rb
38
+ homepage: https://github.com/ngan/rubocop-junit_formatter
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.7.6
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: JUnit Formatter for RuboCop
62
+ test_files: []