rubocop-checkstyle_formatter 0.1.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/build.yml +20 -0
  3. data/.rubocop.yml +13 -0
  4. data/.rubocop_todo.yml +24 -0
  5. data/Appraisals +6 -10
  6. data/Gemfile +1 -0
  7. data/README.md +7 -7
  8. data/gemfiles/{rubocop_0.16.0.gemfile → rubocop_1.14.0.gemfile} +2 -2
  9. data/gemfiles/rubocop_1.14.0.gemfile.lock +64 -0
  10. data/gemfiles/{rubocop_0.14.1.gemfile → rubocop_1.15.0.gemfile} +2 -2
  11. data/gemfiles/rubocop_1.15.0.gemfile.lock +64 -0
  12. data/gemfiles/{rubocop_0.17.0.gemfile → rubocop_1.16.1.gemfile} +2 -2
  13. data/gemfiles/rubocop_1.16.1.gemfile.lock +64 -0
  14. data/gemfiles/{rubocop_0.15.0.gemfile → rubocop_1.17.0.gemfile} +2 -2
  15. data/gemfiles/rubocop_1.17.0.gemfile.lock +64 -0
  16. data/gemfiles/rubocop_1.18.4.gemfile +7 -0
  17. data/gemfiles/rubocop_1.18.4.gemfile.lock +64 -0
  18. data/gemfiles/rubocop_1.19.1.gemfile +7 -0
  19. data/gemfiles/rubocop_1.19.1.gemfile.lock +64 -0
  20. data/lib/rubocop/formatter/checkstyle_formatter.rb +19 -9
  21. data/rubocop-checkstyle_formatter.gemspec +12 -10
  22. data/spec/rubocop/formatter/checkstyle_formatter_spec.rb +36 -18
  23. data/spec/spec_helper.rb +1 -1
  24. metadata +43 -68
  25. data/.travis.yml +0 -38
  26. data/gemfiles/rubocop_0.14.1.gemfile.lock +0 -46
  27. data/gemfiles/rubocop_0.15.0.gemfile.lock +0 -46
  28. data/gemfiles/rubocop_0.16.0.gemfile.lock +0 -46
  29. data/gemfiles/rubocop_0.17.0.gemfile.lock +0 -48
  30. data/gemfiles/rubocop_0.18.1.gemfile +0 -7
  31. data/gemfiles/rubocop_0.18.1.gemfile.lock +0 -48
  32. data/gemfiles/rubocop_0.19.1.gemfile +0 -7
  33. data/gemfiles/rubocop_0.19.1.gemfile.lock +0 -50
  34. data/gemfiles/rubocop_0.20.1.gemfile +0 -7
  35. data/gemfiles/rubocop_0.20.1.gemfile.lock +0 -50
  36. data/gemfiles/rubocop_0.21.0.gemfile +0 -7
  37. data/gemfiles/rubocop_0.21.0.gemfile.lock +0 -50
  38. data/gemfiles/rubocop_0.22.0.gemfile +0 -7
  39. data/gemfiles/rubocop_0.22.0.gemfile.lock +0 -50
  40. data/gemfiles/rubocop_0.23.0.gemfile +0 -7
  41. data/gemfiles/rubocop_0.23.0.gemfile.lock +0 -50
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "1.19.1"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ rubocop-checkstyle_formatter (0.5.0)
5
+ rubocop (>= 1.14.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ appraisal (2.4.1)
11
+ bundler
12
+ rake
13
+ thor (>= 0.14.0)
14
+ ast (2.4.2)
15
+ diff-lcs (1.4.4)
16
+ parallel (1.20.1)
17
+ parser (3.0.2.0)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.0.0)
20
+ rake (13.0.6)
21
+ regexp_parser (2.1.1)
22
+ rexml (3.2.5)
23
+ rspec (3.5.0)
24
+ rspec-core (~> 3.5.0)
25
+ rspec-expectations (~> 3.5.0)
26
+ rspec-mocks (~> 3.5.0)
27
+ rspec-core (3.5.4)
28
+ rspec-support (~> 3.5.0)
29
+ rspec-expectations (3.5.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.5.0)
32
+ rspec-mocks (3.5.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.5.0)
35
+ rspec-support (3.5.0)
36
+ rubocop (1.19.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.0.0.0)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml
42
+ rubocop-ast (>= 1.9.1, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 3.0)
45
+ rubocop-ast (1.10.0)
46
+ parser (>= 3.0.1.1)
47
+ ruby-progressbar (1.11.0)
48
+ thor (1.1.0)
49
+ unicode-display_width (2.0.0)
50
+
51
+ PLATFORMS
52
+ java
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ appraisal (~> 2.4.1)
57
+ bundler (>= 2.2.10)
58
+ rake (>= 12.3.3)
59
+ rspec (~> 3.5.0)
60
+ rubocop (= 1.19.1)
61
+ rubocop-checkstyle_formatter!
62
+
63
+ BUNDLED WITH
64
+ 2.2.25
@@ -1,14 +1,16 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'rexml/document'
3
+ require 'rubocop/formatter/base_formatter'
3
4
 
4
5
  # XXX: Renamed to RuboCop since 0.23.0
5
- RuboCop = Rubocop if defined?(Rubocop) && ! defined?(RuboCop)
6
+ RuboCop = Rubocop if defined?(Rubocop) && !defined?(RuboCop)
6
7
 
7
8
  module RuboCop
8
9
  module Formatter
9
10
  # = This formatter reports in Checkstyle format.
10
11
  class CheckstyleFormatter < BaseFormatter
11
- def started(target_file)
12
+ include PathUtil if defined?(PathUtil)
13
+ def started(_target_file)
12
14
  @document = REXML::Document.new.tap do |d|
13
15
  d << REXML::XMLDecl.new
14
16
  end
@@ -17,12 +19,14 @@ module RuboCop
17
19
 
18
20
  def file_finished(file, offences)
19
21
  REXML::Element.new('file', @checkstyle).tap do |f|
20
- f.attributes['name'] = file
22
+ path_name = file
23
+ path_name = relative_path(path_name) if !ENV.has_key?('RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH') && defined?(relative_path)
24
+ f.attributes['name'] = path_name
21
25
  add_offences(f, offences)
22
26
  end
23
27
  end
24
28
 
25
- def finished(inspected_files)
29
+ def finished(_inspected_files)
26
30
  @document.write(output, 2)
27
31
  end
28
32
 
@@ -31,15 +35,21 @@ module RuboCop
31
35
  def add_offences(parent, offences)
32
36
  offences.each do |offence|
33
37
  REXML::Element.new('error', parent).tap do |e|
34
- e.attributes['line'] = offence.line
35
- e.attributes['column'] = offence.column
36
- e.attributes['severity'] = to_checkstyle_severity(offence.severity.to_s)
37
- e.attributes['message'] = offence.message
38
- e.attributes['source'] = 'com.puppycrawl.tools.checkstyle.' + offence.cop_name
38
+ e.add_attributes(offence_attributes(offence))
39
39
  end
40
40
  end
41
41
  end
42
42
 
43
+ def offence_attributes(offence)
44
+ {
45
+ 'line' => offence.line,
46
+ 'column' => offence.column,
47
+ 'severity' => to_checkstyle_severity(offence.severity.to_s),
48
+ 'message' => offence.message,
49
+ 'source' => 'com.puppycrawl.tools.checkstyle.' + offence.cop_name
50
+ }
51
+ end
52
+
43
53
  # TODO be able to configure severity mapping
44
54
  def to_checkstyle_severity(rubocop_severity)
45
55
  case rubocop_severity.to_s
@@ -1,25 +1,27 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
3
+ require 'English'
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
 
5
7
  Gem::Specification.new do |gem|
6
8
  gem.name = 'rubocop-checkstyle_formatter'
7
- gem.version = '0.1.1'
9
+ gem.version = '0.5.0'
8
10
  gem.authors = ['Eito Katagiri']
9
11
  gem.email = ['eitoball@gmail.com']
10
- gem.description = %q{A formatter for rubocop that outputs in checkstyle format}
11
- gem.summary = %q{A formatter for rubocop that outputs in checkstyle format}
12
+ gem.description = 'A formatter for rubocop that outputs in checkstyle format'
13
+ gem.summary = 'A formatter for rubocop that outputs in checkstyle format'
12
14
  gem.homepage = 'https://github.com/eitoball/rubocop-checkstyle_formatter'
13
15
  gem.license = 'MIT'
14
16
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
20
  gem.require_paths = ['lib']
19
21
 
20
- gem.add_dependency 'rubocop', '>= 0.14.0'
21
- gem.add_development_dependency 'appraisal', '~> 1.0.0'
22
- gem.add_development_dependency 'bundler', '~> 1.3'
23
- gem.add_development_dependency 'rake', '~> 10.1'
24
- gem.add_development_dependency 'rspec', '~> 2.14.0'
22
+ gem.add_dependency 'rubocop', '>= 1.14.0'
23
+ gem.add_development_dependency 'appraisal', '~> 2.4.1'
24
+ gem.add_development_dependency 'bundler', '>= 2.2.10'
25
+ gem.add_development_dependency 'rake', '>= 12.3.3'
26
+ gem.add_development_dependency 'rspec', '~> 3.5.0'
25
27
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+
2
3
  require 'spec_helper'
3
4
  require 'stringio'
4
5
  require 'rexml/document'
@@ -6,25 +7,18 @@ require 'rexml/document'
6
7
  module RuboCop
7
8
  module Formatter
8
9
  describe CheckstyleFormatter do
9
- let(:severities) { [:refactor, :convention, :warning, :error, :fatal] }
10
+ let(:severities) { %i[refactor convention warning error fatal] }
10
11
  let(:cop) do
11
12
  Cop::Cop.new.tap do |c|
13
+ c.send(:begin_investigation, RuboCop::ProcessedSource.new(file, 2.7, 'sample.rb'))
12
14
  source_buffer = Parser::Source::Buffer.new('sample.rb', 1).tap { |b| b.source = '' }
13
15
  severities.each_with_index do |severity, index|
14
- if c.respond_to?(:add_offense)
15
- c.add_offense(nil, Parser::Source::Range.new(source_buffer, 0, index), severity.to_s, severity)
16
- else
17
- begin
18
- c.add_offence(severity, nil, Parser::Source::Range.new(source_buffer, 0, index), severity.to_s)
19
- rescue
20
- c.add_offence(nil, Parser::Source::Range.new(source_buffer, 0, index), severity.to_s, severity)
21
- end
22
- end
16
+ c.add_offense(nil, location: Parser::Source::Range.new(source_buffer, 0, index), message: severity.to_s)
23
17
  end
24
18
  end
25
19
  end
26
20
  let(:output) { StringIO.new }
27
- let(:file) { 'sample.rb' }
21
+ let(:file) { File.join(Dir.pwd, 'sample.rb') }
28
22
 
29
23
  before do
30
24
  formatter = described_class.new(output)
@@ -35,14 +29,38 @@ module RuboCop
35
29
 
36
30
  it 'should convert rubocop severity to checkstyle severity' do
37
31
  doc = REXML::Document.new(output.string)
38
- REXML::XPath.match(doc, '/checkstyle/file/error').each do |error|
39
- message = error.attribute('message').value
40
- severity = error.attribute('severity').value
41
- case message
42
- when 'refactor', 'convention'; expect(severity).to eq('info')
43
- when 'warning'; expect(severity).to eq('warning')
44
- when 'error', 'fatal'; expect(severity).to eq('error')
32
+ REXML::XPath.match(doc, '/checkstyle/file').each do |file|
33
+ if defined?(PathUtil)
34
+ expect(file.attribute('name').value).to eq('sample.rb')
45
35
  end
36
+ REXML::XPath.match(file, '/error').each do |error|
37
+ message = error.attribute('message').value
38
+ severity = error.attribute('severity').value
39
+ case message
40
+ when 'refactor', 'convention' then expect(severity).to eq('info')
41
+ when 'warning' then expect(severity).to eq('warning')
42
+ when 'error', 'fatal' then expect(severity).to eq('error')
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH is defined' do
49
+ around do |example|
50
+ ENV['RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH'] = 'true'
51
+ example.run
52
+ ENV.delete('RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH')
53
+ end
54
+
55
+ it 'should use absolute path in name attribute of file tag' do
56
+ output = StringIO.new
57
+ formatter = described_class.new(output)
58
+ formatter.started(file)
59
+ formatter.file_finished(file, cop.respond_to?(:offenses) ? cop.offenses : cop.offences)
60
+ formatter.finished([file])
61
+ doc = REXML::Document.new(output.string)
62
+ file = REXML::XPath.first(doc, '/checkstyle/file')
63
+ expect(Pathname.new(file.attributes['name'])).to be_absolute
46
64
  end
47
65
  end
48
66
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w{ .. lib }))
3
+ $LOAD_PATH.unshift(File.absolute_path('../../lib', __FILE__))
4
4
  require 'rspec'
5
5
  require 'rubocop'
6
6
  require 'rubocop/formatter/checkstyle_formatter'
metadata CHANGED
@@ -1,96 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-checkstyle_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eito Katagiri
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2021-08-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rubocop
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 0.14.0
19
+ version: 1.14.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 0.14.0
26
+ version: 1.14.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: appraisal
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: 1.0.0
33
+ version: 2.4.1
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: 1.0.0
40
+ version: 2.4.1
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: '1.3'
47
+ version: 2.2.10
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
- version: '1.3'
54
+ version: 2.2.10
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
- version: '10.1'
61
+ version: 12.3.3
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
- version: '10.1'
68
+ version: 12.3.3
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
- version: 2.14.0
75
+ version: 3.5.0
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
- version: 2.14.0
82
+ version: 3.5.0
94
83
  description: A formatter for rubocop that outputs in checkstyle format
95
84
  email:
96
85
  - eitoball@gmail.com
@@ -98,33 +87,27 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
- - .gitignore
102
- - .travis.yml
90
+ - ".github/workflows/build.yml"
91
+ - ".gitignore"
92
+ - ".rubocop.yml"
93
+ - ".rubocop_todo.yml"
103
94
  - Appraisals
104
95
  - Gemfile
105
96
  - LICENSE.txt
106
97
  - README.md
107
98
  - Rakefile
108
- - gemfiles/rubocop_0.14.1.gemfile
109
- - gemfiles/rubocop_0.14.1.gemfile.lock
110
- - gemfiles/rubocop_0.15.0.gemfile
111
- - gemfiles/rubocop_0.15.0.gemfile.lock
112
- - gemfiles/rubocop_0.16.0.gemfile
113
- - gemfiles/rubocop_0.16.0.gemfile.lock
114
- - gemfiles/rubocop_0.17.0.gemfile
115
- - gemfiles/rubocop_0.17.0.gemfile.lock
116
- - gemfiles/rubocop_0.18.1.gemfile
117
- - gemfiles/rubocop_0.18.1.gemfile.lock
118
- - gemfiles/rubocop_0.19.1.gemfile
119
- - gemfiles/rubocop_0.19.1.gemfile.lock
120
- - gemfiles/rubocop_0.20.1.gemfile
121
- - gemfiles/rubocop_0.20.1.gemfile.lock
122
- - gemfiles/rubocop_0.21.0.gemfile
123
- - gemfiles/rubocop_0.21.0.gemfile.lock
124
- - gemfiles/rubocop_0.22.0.gemfile
125
- - gemfiles/rubocop_0.22.0.gemfile.lock
126
- - gemfiles/rubocop_0.23.0.gemfile
127
- - gemfiles/rubocop_0.23.0.gemfile.lock
99
+ - gemfiles/rubocop_1.14.0.gemfile
100
+ - gemfiles/rubocop_1.14.0.gemfile.lock
101
+ - gemfiles/rubocop_1.15.0.gemfile
102
+ - gemfiles/rubocop_1.15.0.gemfile.lock
103
+ - gemfiles/rubocop_1.16.1.gemfile
104
+ - gemfiles/rubocop_1.16.1.gemfile.lock
105
+ - gemfiles/rubocop_1.17.0.gemfile
106
+ - gemfiles/rubocop_1.17.0.gemfile.lock
107
+ - gemfiles/rubocop_1.18.4.gemfile
108
+ - gemfiles/rubocop_1.18.4.gemfile.lock
109
+ - gemfiles/rubocop_1.19.1.gemfile
110
+ - gemfiles/rubocop_1.19.1.gemfile.lock
128
111
  - lib/rubocop/formatter/checkstyle_formatter.rb
129
112
  - rubocop-checkstyle_formatter.gemspec
130
113
  - spec/rubocop/formatter/checkstyle_formatter_spec.rb
@@ -132,33 +115,25 @@ files:
132
115
  homepage: https://github.com/eitoball/rubocop-checkstyle_formatter
133
116
  licenses:
134
117
  - MIT
118
+ metadata: {}
135
119
  post_install_message:
136
120
  rdoc_options: []
137
121
  require_paths:
138
122
  - lib
139
123
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
124
  requirements:
142
- - - ! '>='
125
+ - - ">="
143
126
  - !ruby/object:Gem::Version
144
127
  version: '0'
145
- segments:
146
- - 0
147
- hash: 3272514483018578912
148
128
  required_rubygems_version: !ruby/object:Gem::Requirement
149
- none: false
150
129
  requirements:
151
- - - ! '>='
130
+ - - ">="
152
131
  - !ruby/object:Gem::Version
153
132
  version: '0'
154
- segments:
155
- - 0
156
- hash: 3272514483018578912
157
133
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 1.8.23.2
134
+ rubygems_version: 3.2.9
160
135
  signing_key:
161
- specification_version: 3
136
+ specification_version: 4
162
137
  summary: A formatter for rubocop that outputs in checkstyle format
163
138
  test_files:
164
139
  - spec/rubocop/formatter/checkstyle_formatter_spec.rb