danger-checkstyle_format 0.0.4 → 0.1.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
  SHA1:
3
- metadata.gz: 3cb327d641d2806aace612dc184a36b6e37f5237
4
- data.tar.gz: '073691ba3631ca7cd762b4496b6b6ab4a6483d71'
3
+ metadata.gz: 979204d1d5978fbd6d160175238a593c408585d7
4
+ data.tar.gz: 1c46f43bc1452d88c76775152b07fcca9345cfa3
5
5
  SHA512:
6
- metadata.gz: 4877e47a3d7772a5f484fea83458ca7417479cee0a8a11081d052a0495730af94c0af786cdc082312b3298aaf9b3dec79b027ff29437571f5e91ede3455daf4a
7
- data.tar.gz: b8922e625b420623837a87c9da70f45397b24f2873bdc7e75aa036a5e59869739ca3bfea73e2481715ac31e5c9567cd4522064631e6796023bce4b5e11edd2e9
6
+ metadata.gz: d679c9d8a9f5c4d52c473705d1203bb21980185340b146e244eb3e0be82041cdc0c1f52a34c5fe3dedbeed6d55279135599aef9af4b85e1e8d550f69a3331669
7
+ data.tar.gz: 2d3da84229b1764ea7637144d41f3dc36fd0eaa379ba45ae4799c17fb76746e09ecb360e39027fa2e6975c1c5b53b2145c73e83f4204bd1b21623d474573d0c1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-checkstyle_format (0.0.4)
4
+ danger-checkstyle_format (0.1.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
  ox (~> 2.0)
7
7
 
data/README.md CHANGED
@@ -16,6 +16,12 @@ checkstyle_format.base_path = Dir.pwd
16
16
  checkstyle_format.report 'app/build/reports/checkstyle/checkstyle.xml'</pre>
17
17
  </blockquote>
18
18
 
19
+ <blockquote>Parse the XML text, and let the plugin do your reporting
20
+ <pre>
21
+ checkstyle_format.base_path = Dir.pwd
22
+ checkstyle_format.report_by_text '<?xml ...'</pre>
23
+ </blockquote>
24
+
19
25
  ## Development
20
26
 
21
27
  1. Clone this repo
@@ -1,3 +1,3 @@
1
1
  module CheckstyleFormat
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
@@ -8,6 +8,11 @@ module Danger
8
8
  # checkstyle_format.base_path = Dir.pwd
9
9
  # checkstyle_format.report 'app/build/reports/checkstyle/checkstyle.xml'
10
10
  #
11
+ # @example Parse the XML text, and let the plugin do your reporting
12
+ #
13
+ # checkstyle_format.base_path = Dir.pwd
14
+ # checkstyle_format.report_by_text '<?xml ...'
15
+ #
11
16
  # @see noboru-i/danger-checkstyle_format
12
17
  # @tags lint, reporting
13
18
  #
@@ -18,26 +23,32 @@ module Danger
18
23
  attr_accessor :base_path
19
24
 
20
25
  # Report checkstyle warnings
21
- # @return [void]
22
26
  #
27
+ # @return [void]
23
28
  def report(file, inline_mode = true)
24
29
  raise "Please specify file name." if file.empty?
25
30
  raise "No checkstyle file was found at #{file}" unless File.exist? file
26
- errors = parse(file)
31
+ errors = parse(File.read(file))
27
32
 
28
- if inline_mode
29
- send_inline_comment(errors)
30
- else
31
- raise "not implemented." # TODO: not implemented.
32
- end
33
+ send_comment(errors, inline_mode)
34
+ end
35
+
36
+ # Report checkstyle warnings by XML text
37
+ #
38
+ # @return [void]
39
+ def report_by_text(text, inline_mode = true)
40
+ raise "Please specify xml text." if text.empty?
41
+ errors = parse(text)
42
+
43
+ send_comment(errors, inline_mode)
33
44
  end
34
45
 
35
46
  private
36
47
 
37
- def parse(file)
48
+ def parse(text)
38
49
  require "ox"
39
50
 
40
- doc = Ox.parse(File.read(file))
51
+ doc = Ox.parse(text)
41
52
  present_elements = doc.nodes.first.nodes.reject do |test|
42
53
  test.nodes.empty?
43
54
  end
@@ -52,6 +63,14 @@ module Danger
52
63
  elements
53
64
  end
54
65
 
66
+ def send_comment(errors, inline_mode)
67
+ if inline_mode
68
+ send_inline_comment(errors)
69
+ else
70
+ raise "not implemented." # TODO: not implemented.
71
+ end
72
+ end
73
+
55
74
  def send_inline_comment(errors)
56
75
  errors.each do |error|
57
76
  warn(error.message, file: error.file_name, line: error.line)
@@ -28,7 +28,7 @@ module Danger
28
28
  describe ".parse" do
29
29
  subject(:errors) do
30
30
  @checkstyle_format.base_path = "/path/to"
31
- @checkstyle_format.send(:parse, "spec/fixtures/checkstyle.xml")
31
+ @checkstyle_format.send(:parse, File.read("spec/fixtures/checkstyle.xml"))
32
32
  end
33
33
  it "have 4 items" do
34
34
  expect(errors.size).to be 4
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-checkstyle_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - noboru-i
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-05 00:00:00.000000000 Z
11
+ date: 2017-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api