java-checkstyle 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +8 -14
- data/foo.java +9 -0
- data/java-checkstyle.gemspec +4 -3
- data/lib/plugins/pre-commit/message/extractor.rb +22 -17
- data/lib/plugins/pre-commit/message/formatter.rb +3 -5
- data/lib/{plugins/pre-commit → pre-commit}/checkstyle/version.rb +1 -2
- data/spec/plugins/pre_commit/checks/checkstyle_spec.rb +3 -4
- data/spec/plugins/pre_commit/message/extractor_spec.rb +24 -29
- data/spec/plugins/pre_commit/message/formatter_spec.rb +10 -7
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae4c1084ae89aff25bbdeb83f8f23ca5717df96a
|
4
|
+
data.tar.gz: 1a4587b7b160b6c276e55a6c73e88e41c9024a6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af6fa8496cb1beff907c37d83b372019da561b5b384c6abb5d9aec2adeb5d93fa0c079e11f17f06bec047d378748b13f0ac5f64011f3b8005a74338da1c7f045
|
7
|
+
data.tar.gz: b4099e356de18a377c69882e250f6d4fddfbe4139365c9bb8349e74591e1b66bd083356e325c925612145a6535a1d8d9cd6b6c2d90f5a3beb3a9aa9ee49d32f6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
## Java - Pre-Commit Checkstyle
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/java-checkstyle.svg)](https://badge.fury.io/rb/java-checkstyle)
|
3
|
-
[![Build Status](https://travis-ci.org/
|
4
|
-
[![Code Climate](https://codeclimate.com/github/
|
5
|
-
[![Test Coverage](https://codeclimate.com/github/
|
3
|
+
[![Build Status](https://travis-ci.org/cristianoliveira/java-checkstyle.svg)](https://travis-ci.org/CristianOliveiraDaRosa/java-checkstyle)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/cristianoliveira/java-checkstyle/badges/gpa.svg)](https://codeclimate.com/github/cristianoliveira/java-checkstyle)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/cristianoliveira/java-checkstyle/badges/coverage.svg)](https://codeclimate.com/github/cristianoliveira/java-checkstyle/coverage)
|
6
6
|
|
7
7
|
Useful git pre-commit hook for linting Java code.
|
8
8
|
|
@@ -11,17 +11,17 @@ and the famous [Checkstyle](http://checkstyle.sourceforge.net/) linter as a plug
|
|
11
11
|
|
12
12
|
## Demo
|
13
13
|
|
14
|
-
![My awesome change has been catch. Oh boy!](https://raw.githubusercontent.com/
|
14
|
+
![My awesome change has been catch. Oh boy!](https://raw.githubusercontent.com/cristianoliveira/java-checkstyle/master/readmedemo.png)
|
15
15
|
[Don't you know who is Leeroy Jenkins?](https://www.youtube.com/watch?v=mLyOj_QD4a4)
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
19
19
|
First install the gems.
|
20
|
-
|
20
|
+
#### Pre-Commit Checkstyle
|
21
21
|
|
22
22
|
gem install pre-commit
|
23
23
|
|
24
|
-
|
24
|
+
#### Java Checkstyle Plugin
|
25
25
|
|
26
26
|
gem install java-checkstyle
|
27
27
|
|
@@ -38,25 +38,19 @@ pre-commit install
|
|
38
38
|
|
39
39
|
It will create a .git/hooks/pre-commit script which will check your git config and run checks that are enabled.
|
40
40
|
|
41
|
-
|
41
|
+
#### Enabling checks
|
42
42
|
|
43
43
|
``` bash
|
44
44
|
pre-commit enable git checks checkstyle
|
45
45
|
```
|
46
46
|
|
47
|
-
OR
|
48
|
-
|
49
|
-
``` bash
|
50
|
-
pre-commit enable yaml checks checkstyle
|
51
|
-
```
|
52
|
-
|
53
47
|
### Result
|
54
48
|
Every time you try to commit some java code with style errors it will validate
|
55
49
|
for you ensuring that your code will be always awesome.
|
56
50
|
|
57
51
|
---
|
58
52
|
#### Detailed version to install.
|
59
|
-
Still don't work? Try the detailed version [here](https://github.com/
|
53
|
+
Still don't work? Try the detailed version [here](https://github.com/cristianoliveira/java-checkstyle/blob/master/DETAILED_TUTORIAL.md)
|
60
54
|
|
61
55
|
---
|
62
56
|
|
data/foo.java
ADDED
data/java-checkstyle.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require './lib/
|
4
|
+
require './lib/pre-commit/checkstyle/version.rb'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "java-checkstyle"
|
8
8
|
spec.version = PreCommit::Checkstyle::VERSION
|
9
9
|
spec.authors = ["Allen Madsen", "Cristian Oliveira", "Alex Rocha"]
|
10
|
-
spec.email = ["blatyo@gmail.com", "contato@cristianoliveira.com.br"]
|
10
|
+
spec.email = ["blatyo@gmail.com", "contato@cristianoliveira.com.br", "alex.rochas@yahoo.com.br"]
|
11
11
|
spec.summary = %q{Checkstyle linter plugin for pre-commit}
|
12
12
|
spec.description = %q{Checkstyle linter plugin for pre-commit. Useful for linting Java code.}
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/CristianOliveira/java-checkstyle"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency("bundler", "~> 1.5")
|
25
25
|
spec.add_development_dependency("rake", '~> 10.4', '>= 10.4.2')
|
26
26
|
spec.add_development_dependency('rspec', '~> 3.3.0')
|
27
|
+
spec.add_development_dependency('rubocop', '~> 0.34.2')
|
27
28
|
end
|
@@ -8,14 +8,17 @@ module PreCommit
|
|
8
8
|
# Responsible for extract error messages from terminal output
|
9
9
|
class Extractor
|
10
10
|
##
|
11
|
-
# Extract data from a XML formatted +
|
11
|
+
# Extract data from a XML formatted +terminal_output+
|
12
12
|
#
|
13
|
-
# @param
|
14
|
-
# @return [
|
15
|
-
def extract(
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
# @param terminal_output [String] XML formatted terminal ouput
|
14
|
+
# @return [Domain::Checkstyle] The checkstyle
|
15
|
+
def extract(terminal_output)
|
16
|
+
if blank?(terminal_output) ||
|
17
|
+
blank?(xml_content_of(terminal_output))
|
18
|
+
return Domain::Checkstyle.good
|
19
|
+
end
|
20
|
+
|
21
|
+
xml_data = Crack::XML.parse(xml_content_of(terminal_output))
|
19
22
|
files = xml_data['checkstyle']['file']
|
20
23
|
|
21
24
|
Domain::Checkstyle.new(extract_bad_file(files))
|
@@ -23,25 +26,27 @@ module PreCommit
|
|
23
26
|
|
24
27
|
private
|
25
28
|
|
26
|
-
def
|
29
|
+
def xml_content_of(raw_output)
|
27
30
|
raw_output[/<(.*)>/m]
|
28
31
|
end
|
29
32
|
|
30
33
|
def extract_bad_file(xml_files)
|
31
|
-
return [
|
32
|
-
|
33
|
-
xml_files.reduce([]) { |a, e| a.push(create_bad_file(e)) }
|
34
|
+
return [bad_file(xml_files)] unless xml_files.is_a? Array
|
35
|
+
xml_files.map { |e| bad_file(e) }
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
Domain::BadFile.new(file['name'], extract_errors(file
|
38
|
+
def bad_file(file)
|
39
|
+
Domain::BadFile.new(file['name'], extract_errors(file))
|
38
40
|
end
|
39
41
|
|
40
|
-
def extract_errors(
|
41
|
-
return [] if
|
42
|
-
return [
|
42
|
+
def extract_errors(file)
|
43
|
+
return [] if blank? file['error']
|
44
|
+
return [file['error']] unless file['error'].is_a? Array
|
45
|
+
file['error']
|
46
|
+
end
|
43
47
|
|
44
|
-
|
48
|
+
def blank?(value)
|
49
|
+
value.nil? || value.empty?
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
@@ -6,8 +6,8 @@ module PreCommit
|
|
6
6
|
##
|
7
7
|
# Format output for a given +errors+ details
|
8
8
|
#
|
9
|
-
# @param [
|
10
|
-
# @return [String] formatted output
|
9
|
+
# @param checkstyle [Domain::Checkstyle] Checkstyle details
|
10
|
+
# @return [String] formatted output or nil when has no errors
|
11
11
|
# @raise ArgumentError when input is empty
|
12
12
|
#
|
13
13
|
def format(checkstyle)
|
@@ -28,9 +28,7 @@ module PreCommit
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def format_errors(errors)
|
31
|
-
errors.reduce('')
|
32
|
-
out + line(error)
|
33
|
-
end
|
31
|
+
errors.reduce('') { |a, e| a + line(e) }
|
34
32
|
end
|
35
33
|
|
36
34
|
def line(error)
|
@@ -39,12 +39,11 @@ describe PreCommit::Checks::Checkstyle do
|
|
39
39
|
|
40
40
|
it "should accept custom checkstyle" do
|
41
41
|
# given
|
42
|
+
ENV["CHECKSTYLE_CONFIG"] = "sun_checks.xml"
|
42
43
|
files = [fixture_file('bad.java')]
|
43
|
-
custom_config = double(PreCommit::Configuration,
|
44
|
-
get: fixture_file('sun_checks.xml'))
|
45
44
|
# when
|
46
|
-
|
45
|
+
result = check.call(files)
|
47
46
|
# then
|
48
|
-
expect(
|
47
|
+
expect(result).to_not be_nil
|
49
48
|
end
|
50
49
|
end
|
@@ -10,15 +10,13 @@ describe PreCommit::Message::Extractor do
|
|
10
10
|
|
11
11
|
context "When nil output" do
|
12
12
|
it "should be good" do
|
13
|
-
|
14
|
-
expect(result).to be_good
|
13
|
+
expect( extractor.extract(nil) ).to be_good
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
context "When empty output" do
|
19
18
|
it "should be good" do
|
20
|
-
|
21
|
-
expect(result).to be_good
|
19
|
+
expect( extractor.extract('') ).to be_good
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
@@ -26,23 +24,25 @@ describe PreCommit::Message::Extractor do
|
|
26
24
|
# given
|
27
25
|
let(:output) { IO.read(fixture_file("output_one_bad_file.log")) }
|
28
26
|
|
27
|
+
# when
|
28
|
+
before { @checkstyle = extractor.extract(output) }
|
29
|
+
|
30
|
+
# then
|
29
31
|
it "should not be good" do
|
30
|
-
|
31
|
-
expect(result).to_not be_good
|
32
|
+
expect( @checkstyle ).to_not be_good
|
32
33
|
end
|
33
34
|
|
34
35
|
it "should contain one single file" do
|
35
|
-
|
36
|
-
expect(result.bad_files).to be_a Array
|
36
|
+
expect( @checkstyle.bad_files ).to be_a Array
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should contain its errors" do
|
40
|
-
|
41
|
-
expect(result.bad_files[0].errors.size).to eq 2
|
40
|
+
expect( @checkstyle.bad_files[0].errors.size ).to be 2
|
42
41
|
end
|
43
42
|
|
44
43
|
it "should extract error details" do
|
45
|
-
|
44
|
+
expect( @checkstyle.bad_files[0].errors ).to eq(
|
45
|
+
[
|
46
46
|
{
|
47
47
|
"line"=>"1",
|
48
48
|
"severity"=>"error",
|
@@ -56,35 +56,34 @@ describe PreCommit::Message::Extractor do
|
|
56
56
|
"message" => "some error message",
|
57
57
|
"source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"
|
58
58
|
}
|
59
|
-
|
60
|
-
|
61
|
-
result = extractor.extract output
|
62
|
-
errors = result.bad_files[0].errors
|
63
|
-
expect(errors).to eq expected
|
59
|
+
]
|
60
|
+
)
|
64
61
|
end
|
65
62
|
end
|
66
63
|
|
67
64
|
context "When has multiple bad files" do
|
65
|
+
# given
|
68
66
|
let(:output) { IO.read(fixture_file("output_two_bad_files.log")) }
|
69
67
|
|
68
|
+
# when
|
69
|
+
before { @checkstyle = extractor.extract output }
|
70
|
+
|
71
|
+
# then
|
70
72
|
it "should not be good" do
|
71
|
-
|
72
|
-
expect(result).to_not be_good
|
73
|
+
expect( @checkstyle ).to_not be_good
|
73
74
|
end
|
74
75
|
|
75
76
|
it "should extract multiple files" do
|
76
|
-
|
77
|
-
expect(result.bad_files).to be_a Array
|
77
|
+
expect( @checkstyle.bad_files ).to be_a Array
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should extract their errors" do
|
81
|
-
|
82
|
-
expect(
|
83
|
-
expect(result.bad_files[1].errors.size).to eq 2
|
81
|
+
expect( @checkstyle.bad_files[0].errors.size ).to be 2
|
82
|
+
expect( @checkstyle.bad_files[1].errors.size ).to be 2
|
84
83
|
end
|
85
84
|
|
86
85
|
it "should extract error details" do
|
87
|
-
|
86
|
+
expect( @checkstyle.bad_files[0].errors ).to eq ([
|
88
87
|
{
|
89
88
|
"line"=>"1",
|
90
89
|
"severity"=>"error",
|
@@ -98,11 +97,7 @@ describe PreCommit::Message::Extractor do
|
|
98
97
|
"message" => "some error message",
|
99
98
|
"source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"
|
100
99
|
}
|
101
|
-
]
|
102
|
-
|
103
|
-
result = extractor.extract output
|
104
|
-
|
105
|
-
expect(result.bad_files[0].errors).to eq expected
|
100
|
+
])
|
106
101
|
end
|
107
102
|
end
|
108
103
|
end
|
@@ -27,7 +27,6 @@ describe PreCommit::Message::Formatter do
|
|
27
27
|
"message"=>"some error message",
|
28
28
|
"source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"
|
29
29
|
}])
|
30
|
-
|
31
30
|
}
|
32
31
|
|
33
32
|
context "When has empty input" do
|
@@ -42,8 +41,10 @@ describe PreCommit::Message::Formatter do
|
|
42
41
|
context "When has one file" do
|
43
42
|
let(:errors) { Domain::Checkstyle.new( [ file_error ] ) }
|
44
43
|
|
45
|
-
|
46
|
-
|
44
|
+
before { @formatted_output = formatter.format(errors)}
|
45
|
+
|
46
|
+
it{ expect( @formatted_output ).to include "File errors: /some/path/file_name.java"}
|
47
|
+
it{ expect( @formatted_output ).to include " line: 1: error: some error message"}
|
47
48
|
end
|
48
49
|
|
49
50
|
context "When has more than one file" do
|
@@ -51,9 +52,11 @@ describe PreCommit::Message::Formatter do
|
|
51
52
|
Domain::Checkstyle.new( [ file_error, file_error_2 ] )
|
52
53
|
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
it{ expect(
|
57
|
-
it{ expect(
|
55
|
+
before { @formatted_output = formatter.format(errors) }
|
56
|
+
|
57
|
+
it{ expect( @formatted_output ).to include "File errors: /some/path/file_name.java"}
|
58
|
+
it{ expect( @formatted_output ).to include " line: 1: error: some error message"}
|
59
|
+
it{ expect( @formatted_output ).to include "File errors: /some/path/file_name2.java"}
|
60
|
+
it{ expect( @formatted_output ).to include " line: 11:40 error: some error message"}
|
58
61
|
end
|
59
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: java-checkstyle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allen Madsen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-05-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pre-commit
|
@@ -88,10 +88,25 @@ dependencies:
|
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 3.3.0
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rubocop
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.34.2
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.34.2
|
91
105
|
description: Checkstyle linter plugin for pre-commit. Useful for linting Java code.
|
92
106
|
email:
|
93
107
|
- blatyo@gmail.com
|
94
108
|
- contato@cristianoliveira.com.br
|
109
|
+
- alex.rochas@yahoo.com.br
|
95
110
|
executables: []
|
96
111
|
extensions: []
|
97
112
|
extra_rdoc_files: []
|
@@ -106,14 +121,15 @@ files:
|
|
106
121
|
- README.md
|
107
122
|
- Rakefile
|
108
123
|
- demo.png
|
124
|
+
- foo.java
|
109
125
|
- java-checkstyle.gemspec
|
110
126
|
- lib/plugins/pre-commit/checks/checkstyle.rb
|
111
|
-
- lib/plugins/pre-commit/checkstyle/version.rb
|
112
127
|
- lib/plugins/pre-commit/domain/bad_file.rb
|
113
128
|
- lib/plugins/pre-commit/domain/checkstyle.rb
|
114
129
|
- lib/plugins/pre-commit/message/extractor.rb
|
115
130
|
- lib/plugins/pre-commit/message/formatter.rb
|
116
131
|
- lib/plugins/pre-commit/support/path.rb
|
132
|
+
- lib/pre-commit/checkstyle/version.rb
|
117
133
|
- lib/resources/checkstyle/checkstyle-6.11-all.jar
|
118
134
|
- lib/resources/checkstyle/google_checks.xml
|
119
135
|
- readmedemo.png
|
@@ -127,7 +143,7 @@ files:
|
|
127
143
|
- spec/plugins/pre_commit/message/extractor_spec.rb
|
128
144
|
- spec/plugins/pre_commit/message/formatter_spec.rb
|
129
145
|
- spec/spec_helper.rb
|
130
|
-
homepage: https://github.com/
|
146
|
+
homepage: https://github.com/CristianOliveira/java-checkstyle
|
131
147
|
licenses:
|
132
148
|
- MIT
|
133
149
|
metadata: {}
|
@@ -147,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
163
|
version: '0'
|
148
164
|
requirements: []
|
149
165
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.5.2
|
151
167
|
signing_key:
|
152
168
|
specification_version: 4
|
153
169
|
summary: Checkstyle linter plugin for pre-commit
|
@@ -162,4 +178,3 @@ test_files:
|
|
162
178
|
- spec/plugins/pre_commit/message/extractor_spec.rb
|
163
179
|
- spec/plugins/pre_commit/message/formatter_spec.rb
|
164
180
|
- spec/spec_helper.rb
|
165
|
-
has_rdoc:
|