java-checkstyle 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7195c535a4ffe35bc6059ad1dc13a1e326dfc94e
4
- data.tar.gz: c8facc5e071412a45073591ed1aaf76f01d5cfe2
3
+ metadata.gz: 726ce64842d1a5659c871c86418aa4b0672a3e5c
4
+ data.tar.gz: 8c825774132b66642463a447e35027fe14a28d7d
5
5
  SHA512:
6
- metadata.gz: 8e5184be4154f4a5db9f184c411f3c3492079b39be29ae7e167b5c0bdffc0f0416950015913537137ddda9e58a5ab1c837a305f8b24570751bd34a4e6fc35197
7
- data.tar.gz: 953cb0b0c1c35b4499d7898273af8a1bc3a44dbe177d2611f4b4e8fb438c8d9a883ce9a6d558d50b5ae27f47f1276dd6b632183ffda2e5fc377a23afa5182746
6
+ metadata.gz: b28d57af8e812686bd780159407c651fe09f2a460d3779324ac87a5e7d2eb628250f3142996b2cc2b7f0d15c16712134d7aff2047b43250e743d1acfeb14a688
7
+ data.tar.gz: 80e93ca8085577907461404de4de41bfc369412cb15118f6a48d7139b71ecad1472983ff108b7200c759f6490a51e8614b75eff4c19b0041181f23dc7b44357b
@@ -0,0 +1,102 @@
1
+ ### Java - Pre-Commit Checkstyle
2
+
3
+ ## Detailed Installation Guide
4
+
5
+ This is a detailed version to install this useful hook.
6
+
7
+ # Let`s do it!
8
+
9
+ First install and setup the check in pre-commit:
10
+ ### Pre-Commit Checkstyle
11
+ Install the gem
12
+
13
+ $ gem install pre-commit
14
+
15
+ ### Install the Java-checkstyle gem
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'java-checkstyle'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install java-checkstyle
28
+
29
+ Now your pre-commit hook has been installed.
30
+
31
+ ## Using in your project
32
+
33
+ Create your project folder and start a git repository
34
+
35
+ ```bash
36
+ mkdir awesome_project
37
+ cd awesome_project
38
+ git init
39
+ ```
40
+ **Install the hook for this repository**
41
+
42
+ Use the pre-commit command to generate a stub pre-commit hook
43
+ ```bash
44
+ # Inside of your project with git
45
+ pre-commit install
46
+ ```
47
+ This creates a .git/hooks/pre-commit script which will check your git config and run checks that are enabled.
48
+
49
+ **Enable the java checkstyle checks**
50
+
51
+ ``` bash
52
+ pre-commit enable git checks checkstyle
53
+ ```
54
+
55
+ OR
56
+
57
+ ``` bash
58
+ pre-commit enable yaml checks checkstyle
59
+ ```
60
+
61
+ Then the pre commmit has been configured! For this your repository.
62
+
63
+ ## Let`s test it!
64
+ Create a new java code with some style errors see: [Google checkstyle guide](http://google.github.io/styleguide/javaguide.html)
65
+
66
+ ```java
67
+ class HelloWorld
68
+ {
69
+ public static void main(String[] args)
70
+ {
71
+ System.out.println("Hello World!");
72
+ }
73
+ }
74
+ ```
75
+ Then add it and try commit
76
+ ``` bash
77
+ git add .
78
+ git commit -m "Time's up, let's do this! Leeeeeeeeeeeeeroy Jjjjjjenkinsss!!"
79
+ ```
80
+
81
+ Still don`t know our hero Leroy Jenkis? Oh man! see [here](https://www.youtube.com/watch?v=LkCNJRfSZBU)
82
+
83
+ ![My awesome change has been catch. Oh boy!](https://raw.githubusercontent.com/CristianOliveiraDaRosa/java-checkstyle/master/demo.png)
84
+
85
+ ---
86
+ ## Installing with RVM
87
+
88
+ If you are using rvm you need to install pre-commit into the ```default``` gemset, because it does not use the ```current``` environment
89
+
90
+ $ rvm default do gem install pre-commit
91
+
92
+ Alternatively you can configure pre-commit to use the ```current``` rvm gemset
93
+
94
+ $ git config pre-commit.ruby "rvm `rvm current` do ruby"
95
+
96
+ More details about this part see on:
97
+ [pre-commit](https://github.com/jish/pre-commit)
98
+
99
+ ## Authors:
100
+ - Allen Madsen (Original Version 0.0.1)
101
+ - Alex Rocha
102
+ - Cristian Oliveira
data/README.md CHANGED
@@ -1,27 +1,39 @@
1
1
  ## Java - Pre-Commit Checkstyle
2
+ [![Gem Version](https://badge.fury.io/rb/java-checkstyle.svg)](https://badge.fury.io/rb/java-checkstyle)
2
3
  [![Build Status](https://travis-ci.org/CristianOliveiraDaRosa/java-checkstyle.svg?branch=dev)](https://travis-ci.org/CristianOliveiraDaRosa/java-checkstyle)
3
4
  [![Code Climate](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle/badges/gpa.svg)](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle)
4
5
  [![Test Coverage](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle/badges/coverage.svg)](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle/coverage)
5
6
 
6
- [Checkstyle](http://checkstyle.sourceforge.net/) linter plugin for [pre-commit](https://github.com/jish/pre-commit). Useful for linting Java code.
7
+ Useful pre-commit hook for linting Java code. It uses as default [The Google Style Guide](https://google.github.io/styleguide/javaguide.html)
8
+
9
+ It uses the famous [Checkstyle](http://checkstyle.sourceforge.net/) linter as a plugin for [pre-commit](https://github.com/jish/pre-commit).
10
+
11
+ ## Demo
12
+
13
+ ![My awesome change has been catch. Oh boy!](https://raw.githubusercontent.com/CristianOliveiraDaRosa/java-checkstyle/master/readmedemo.png)
7
14
 
8
15
  ## Installation
9
16
 
10
- Add this line to your application's Gemfile:
17
+ First install the gems.
18
+ ### Pre-Commit Checkstyle
11
19
 
12
- gem 'pre-commit-checkstyle'
20
+ gem install pre-commit
13
21
 
14
- And then execute:
22
+ ### Java Checkstyle Plugin
15
23
 
16
- $ bundle
24
+ gem install java-checkstyle
17
25
 
18
- Or install it yourself as:
26
+ ### Configuring
27
+ Use the pre-commit command to generate a stub pre-commit hook.
28
+ Inside folder of your git repo:
19
29
 
20
- $ gem install pre-commit-checkstyle
30
+ ```bash
31
+ pre-commit install
32
+ ```
21
33
 
22
- ## Usage
34
+ It will create a .git/hooks/pre-commit script which will check your git config and run checks that are enabled.
23
35
 
24
- Make sure the gem is installed and setup the check in [pre-commit](https://github.com/jish/pre-commit) with:
36
+ ### Enabling checks
25
37
 
26
38
  ``` bash
27
39
  pre-commit enable git checks checkstyle
@@ -33,14 +45,64 @@ OR
33
45
  pre-commit enable yaml checks checkstyle
34
46
  ```
35
47
 
48
+ ### Result
49
+ Every time you try to commit some java code with style errors it will validate
50
+ before.
51
+
52
+ ---
53
+ #### Detailed version to install.
54
+ Still don't work? Try the detailed version [here](https://github.com/CristianOliveiraDaRosa/java-checkstyle/blob/master/DETAILED_TUTORIAL.md)
55
+
56
+ ---
57
+
58
+ ## Installing with RVM
59
+
60
+ If you are using rvm you need to install pre-commit into the ```default``` gemset, because it does not use the ```current``` environment
61
+
62
+ $ rvm default do gem install pre-commit
63
+
64
+ Alternatively you can configure pre-commit to use the ```current``` rvm gemset
65
+
66
+ $ git config pre-commit.ruby "rvm `rvm current` do ruby"
67
+
68
+ More details about this part see on:
69
+ [pre-commit](https://github.com/jish/pre-commit)
70
+
71
+ And your pre-commit hook has been configured.
72
+
73
+ ## Checkstyle Guide
74
+
75
+ It uses as default [The Google Style Guide](https://google.github.io/styleguide/javaguide.html).
76
+
77
+ ## Tests
78
+ Running tests with rspec
79
+
80
+ Make sure you have been executed:
81
+ ```bash
82
+ bundle install
83
+ ```
84
+ Then run:
85
+
86
+ ```bash
87
+ rspec
88
+ ```
89
+
36
90
  ## Contributing
37
91
 
38
- 1. Fork it ( http://github.com/secondrotation/pre-commit-checkstyle/fork )
92
+ 1. Fork it
39
93
  2. Create your feature branch (`git checkout -b my-new-feature`)
40
94
  3. Commit your changes (`git commit -am 'Add some feature'`)
41
95
  4. Push to the branch (`git push origin my-new-feature`)
42
96
  5. Create new Pull Request
43
97
 
98
+ #### Codeclimate
99
+ Before push, make sure you have been executed rubocop
100
+ ``` bash
101
+ rubocop lib/*
102
+ ```
103
+
104
+ *Pull request should have Unit Tests*
105
+
44
106
  ## Authors:
45
107
  - Allen Madsen (Original Version 0.0.1)
46
108
  - Alex Rocha
data/demo.png ADDED
Binary file
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency('pre-commit', '~> 0.16')
21
+ spec.add_dependency('pre-commit', '~> 0.26')
22
22
  spec.add_dependency('crack', '~> 0.4.2')
23
23
 
24
24
  spec.add_development_dependency("bundler", "~> 1.5")
25
25
  spec.add_development_dependency("rake", '~> 10.4', '>= 10.4.2')
26
- spec.add_development_dependency("rspec", '~> 3.3', '>= 3.3.2')
26
+ spec.add_development_dependency('rspec', '~> 3.3.0')
27
27
  end
@@ -25,6 +25,10 @@ module PreCommit
25
25
  format(extract(output))
26
26
  end
27
27
 
28
+ def self.description
29
+ 'Runs Checkstyle linter for java code.'
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def args(staged_files)
@@ -50,11 +54,7 @@ module PreCommit
50
54
  end
51
55
 
52
56
  def alternate_config_file
53
- Support::Path.relative_to('sun_checks.xml')
54
- end
55
-
56
- def self.description
57
- 'Runs coffeelint to detect errors'
57
+ Support::Path.relative_to('google_checks.xml')
58
58
  end
59
59
 
60
60
  def format(errors)
@@ -8,7 +8,11 @@ module PreCommit
8
8
  #
9
9
  # @param [Hash] JSON errors details
10
10
  # @return [String] formatted output (may return nil)
11
+ # @raise ArgumentError when input is empty
12
+ #
11
13
  def format(errors)
14
+ throw ArgumentError.new if errors.nil? || errors.empty?
15
+
12
16
  files = errors['checkstyle']['file']
13
17
 
14
18
  return nil if files.empty?
@@ -19,10 +23,15 @@ module PreCommit
19
23
 
20
24
  private
21
25
 
26
+ def line(error)
27
+ " line: #{error['line']}:#{error['column']}"\
28
+ " error: #{error['message']}\n"
29
+ end
30
+
22
31
  def format_errors(errors)
32
+ return line(errors) unless errors.is_a? Array
23
33
  errors.reduce('') do |out, error|
24
- out + " line: #{error['line']}:#{error['column']}"\
25
- " error: #{error['message']}\n"
34
+ out + line(error)
26
35
  end
27
36
  end
28
37
 
@@ -11,6 +11,6 @@ module PreCommit
11
11
  # Cristian Oliveira
12
12
  # Alex Rocha
13
13
  module Checkstyle
14
- VERSION = '0.0.2'
14
+ VERSION = '1.0.0'
15
15
  end
16
16
  end
@@ -24,8 +24,6 @@
24
24
  <module name = "Checker">
25
25
  <property name="charset" value="UTF-8"/>
26
26
 
27
- <property name="severity" value="warning"/>
28
-
29
27
  <property name="fileExtensions" value="java, properties, xml"/>
30
28
  <!-- Checks for whitespace -->
31
29
  <!-- See http://checkstyle.sf.net/config_whitespace.html -->
data/readmedemo.png ADDED
Binary file
@@ -1,4 +1,4 @@
1
- class HelloWorld {
1
+ class hello {
2
2
  public static void main(String[] args) {
3
3
  System.out.println("Hello World!");
4
4
  }
@@ -1,4 +1,5 @@
1
- class HelloWorld {
1
+ class HelloWorld
2
+ {
2
3
  public static void main(String[] args) {
3
4
  System.out.println("Hello World!");
4
5
  }
@@ -1,20 +1,21 @@
1
1
  /**
2
2
  * Typical hello world example.
3
+ * It has a good style.
3
4
  */
4
- final class HelloWorld {
5
+ final class Good {
5
6
  /**
6
7
  * Prevent class from being instantiated.
7
8
  *
8
- * @throws AssertionError
9
+ * @throws AssertionError if some smart guy try.
9
10
  */
10
- private HelloWorld() {
11
+ public Good() {
11
12
  throw new AssertionError("Instantiating utility class...");
12
13
  }
13
14
 
14
15
  /**
15
16
  * Prints Hello World!
16
17
  *
17
- * @param args Command line arguments
18
+ * @param args Command line arguments.
18
19
  */
19
20
  public static void main(final String[] args) {
20
21
  System.out.println("Hello World!");
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <checkstyle version="6.11">
3
+ <file name="/Users/cristianoliveira/work/java-checkstyle/spec/fixtures/bad.java">
4
+ <error line="1" severity="error" message="some error message" source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"/>
5
+ <error line="11" column= "1 " severity= "warning" message="some error message" source="com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"/>
6
+ </file>
7
+ </checkstyle>
8
+ Checkstyle ends with 4 errors.
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <checkstyle version="6.11">
3
+ <file name="/Users/cristianoliveira/work/java-checkstyle/spec/fixtures/bad.java">
4
+ <error line="1" severity="error" message="some error message" source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"/>
5
+ <error line="11" column= "1 " severity= "warning" message="some error message" source="com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"/>
6
+ </file>
7
+ <file name="/Users/cristianoliveira/work/java-checkstyle/spec/fixtures/bad2.java">
8
+ <error line="2 " column= "3 " severity= "error" message="some error message" source= "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck "/>
9
+ <error line="2 " column= "27 " severity= "error" message="some error message" source= "com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck "/>
10
+ </file>
11
+ </checkstyle>
12
+ Checkstyle ends with 4 errors.
@@ -10,7 +10,7 @@ describe PreCommit::Checks::Checkstyle do
10
10
  end
11
11
 
12
12
  it "succeeds for good code" do
13
- files = [fixture_file('good.java')]
13
+ files = [fixture_file('Good.java')]
14
14
  expect(check.call(files)).to be_nil
15
15
  end
16
16
 
@@ -18,23 +18,20 @@ describe PreCommit::Checks::Checkstyle do
18
18
  file = fixture_file("bad.java")
19
19
 
20
20
  result = check.call([file])
21
-
21
+
22
22
  expect(result).to include "File errors: #{file}"
23
23
  expect(result).to include "line: 1: error:"
24
- expect(result).to include "line: 1:1 error:"
25
- expect(result).to include "line: 2:3 error:"
26
- expect(result).to include "line: 2:27 error:"
24
+ expect(result).to include "line: 1:7 error:"
27
25
  end
28
26
 
29
-
30
27
  it "should accept multiple fails" do
31
28
  # given
32
29
  file = fixture_file("bad.java")
33
30
  file2 = fixture_file("bad2.java")
34
-
35
- # when
36
- result = check.call([file, file2])
37
-
31
+
32
+ # when
33
+ result = check.call([file, file2])
34
+
38
35
  # then
39
36
  expect(result).to include "File errors: #{file}"
40
37
  expect(result).to include "File errors: #{file2}"
@@ -42,12 +39,12 @@ describe PreCommit::Checks::Checkstyle do
42
39
 
43
40
  it "should accept custom checkstyle" do
44
41
  # given
45
- files = [fixture_file('good.java')]
42
+ files = [fixture_file('bad.java')]
46
43
  custom_config = double(PreCommit::Configuration,
47
- get: fixture_file('google_checks.xml'))
44
+ get: fixture_file('sun_checks.xml'))
48
45
  # when
49
46
  check.config = custom_config
50
47
  # then
51
- expect(check.call(files)).to be_nil
48
+ expect(check.call(files)).to_not be_nil
52
49
  end
53
50
  end
@@ -4,56 +4,90 @@ require 'plugins/pre_commit/message/extractor'
4
4
  # Tests for PreCommit::Message::Extractor
5
5
  describe PreCommit::Message::Extractor do
6
6
  let(:extractor) { PreCommit::Message::Extractor.new }
7
- let(:output) {
8
- '<?xml version="1.0" encoding="UTF-8"?>
9
- <checkstyle version="6.11">
10
- <file name="/Users/cristianoliveira/work/java-checkstyle/spec/fixtures/bad.java">
11
- <error line="1" severity="error" message="some error message" source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"/>
12
- <error line="11" column= "1 " severity= "warning" message="some error message" source="com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"/>
13
- </file>
14
- <file name="/Users/cristianoliveira/work/java-checkstyle/spec/fixtures/bad2.java">
15
- <error line="2 " column= "3 " severity= "error" message="some error message" source= "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck "/>
16
- <error line="2 " column= "27 " severity= "error" message="some error message" source= "com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck "/>
17
- </file>
18
- </checkstyle>
19
- Checkstyle ends with 4 errors.' }
20
-
21
- it "should return empty file for nil output" do
22
- output = nil
23
- result = extractor.extract output
24
-
25
- expect(result['checkstyle']['file']).to be_empty
26
- end
27
7
 
28
- it "should extract files" do
29
- result = extractor.extract output
30
- expect(result['checkstyle']['file'].size).to eq 2
8
+ context "empty output" do
9
+ it "should return empty file for nil output" do
10
+ result = extractor.extract nil
11
+ expect(result['checkstyle']['file']).to be_empty
12
+ end
13
+
14
+ it "should return empty file for empty output" do
15
+ result = extractor.extract ''
16
+ expect(result['checkstyle']['file']).to be_empty
17
+ end
31
18
  end
32
19
 
33
- it "should extract errors" do
34
- result = extractor.extract output
35
- expect(result['checkstyle']['file'][0]['error'].size).to eq 2
20
+ context "has one bad file" do
21
+ # given
22
+ let(:output) { IO.read(fixture_file("output_one_bad_file.log")) }
23
+
24
+ it "should contain one single file" do
25
+ result = extractor.extract output
26
+ expect(result['checkstyle']['file']).to be_a Hash
27
+ end
28
+
29
+ it "should contain its errors" do
30
+ result = extractor.extract output
31
+ expect(result['checkstyle']['file']['error'].size).to eq 2
32
+ end
33
+
34
+ it "should extract error details" do
35
+ expected = [
36
+ {
37
+ "line"=>"1",
38
+ "severity"=>"error",
39
+ "message"=>"some error message",
40
+ "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"
41
+ },
42
+ {
43
+ "line" => "11",
44
+ "column" => "1 ",
45
+ "severity" => "warning",
46
+ "message" => "some error message",
47
+ "source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"
48
+ }
49
+ ]
50
+
51
+ result = extractor.extract output
52
+ errors = result['checkstyle']['file']['error']
53
+ expect(errors).to eq expected
54
+ end
36
55
  end
37
56
 
38
- it "should extract error details" do
39
- expected = [
40
- {
41
- "line"=>"1",
42
- "severity"=>"error",
43
- "message"=>"some error message",
44
- "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"
45
- },
46
- {
47
- "line" => "11",
48
- "column" => "1 ",
49
- "severity" => "warning",
50
- "message" => "some error message",
51
- "source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"
52
- }
53
- ]
54
-
55
- result = extractor.extract output
56
- errors = result['checkstyle']['file'][0]['error']
57
- expect(errors).to eq expected
57
+ context "has multiple bad files" do
58
+ let(:output) { IO.read(fixture_file("output_two_bad_files.log")) }
59
+
60
+ it "should extract multiple files" do
61
+ result = extractor.extract output
62
+ expect(result['checkstyle']['file']).to be_a Array
63
+ end
64
+
65
+ it "should extract their errors" do
66
+ result = extractor.extract output
67
+ expect(result['checkstyle']['file'][0]['error'].size).to eq 2
68
+ expect(result['checkstyle']['file'][1]['error'].size).to eq 2
69
+ end
70
+
71
+ it "should extract error details" do
72
+ expected = [
73
+ {
74
+ "line"=>"1",
75
+ "severity"=>"error",
76
+ "message"=>"some error message",
77
+ "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"
78
+ },
79
+ {
80
+ "line" => "11",
81
+ "column" => "1 ",
82
+ "severity" => "warning",
83
+ "message" => "some error message",
84
+ "source" => "com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck"
85
+ }
86
+ ]
87
+
88
+ result = extractor.extract output
89
+ errors = result['checkstyle']['file'][0]['error']
90
+ expect(errors).to eq expected
91
+ end
58
92
  end
59
93
  end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+ require 'plugins/pre_commit/message/formatter'
3
+ ##
4
+ # Tests for PreCommit::Message::Formatter
5
+ describe PreCommit::Message::Formatter do
6
+ let(:formatter) { PreCommit::Message::Formatter.new }
7
+
8
+ context "When has empty input" do
9
+ it {expect{ formatter.format(nil) }.to raise_error(ArgumentError)}
10
+ it {expect{ formatter.format('') }.to raise_error(ArgumentError)}
11
+ end
12
+
13
+ context "When has no errors" do
14
+ let(:errors) { { 'checkstyle' => { 'file' => [] } } }
15
+ it { expect(formatter.format(errors)).to be_nil }
16
+ end
17
+
18
+ context "When has one file" do
19
+ let(:errors) do
20
+ { 'checkstyle' => {
21
+ 'file' => {
22
+ 'name' => '/some/path/file_name.java',
23
+ 'error' => [{
24
+ "line"=>"1",
25
+ "column"=>"40",
26
+ "severity"=>"error",
27
+ "message"=>"some error message",
28
+ "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"
29
+ }]
30
+ }
31
+ }
32
+ }
33
+ end
34
+
35
+ it{ expect(formatter.format(errors)).to include "File errors: /some/path/file_name.java"}
36
+ it{ expect(formatter.format(errors)).to include " line: 1:40 error: some error message"}
37
+ end
38
+
39
+ context "When has more than one file" do
40
+ let(:errors) do
41
+ { 'checkstyle' => {
42
+ 'file' => [
43
+ {
44
+ 'name' => '/some/path/file_name.java',
45
+ 'error' => [{
46
+ "line"=>"1",
47
+ "severity"=>"error",
48
+ "message"=>"some error message",
49
+ "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"
50
+ }]
51
+ },
52
+ {
53
+ 'name' => '/some/path/file_name2.java',
54
+ 'error' => [{
55
+ "line"=>"11",
56
+ "column"=>"40",
57
+ "severity"=>"error",
58
+ "message"=>"some error message",
59
+ "source"=>"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"
60
+ }]
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ end
66
+
67
+ it{ expect(formatter.format(errors)).to include "File errors: /some/path/file_name.java"}
68
+ it{ expect(formatter.format(errors)).to include " line: 1: error: some error message"}
69
+ it{ expect(formatter.format(errors)).to include "File errors: /some/path/file_name2.java"}
70
+ it{ expect(formatter.format(errors)).to include " line: 11:40 error: some error message"}
71
+ end
72
+ 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: 0.0.2
4
+ version: 1.0.0
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: 2015-10-11 00:00:00.000000000 Z
13
+ date: 2015-10-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pre-commit
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '0.16'
21
+ version: '0.26'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '0.16'
28
+ version: '0.26'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: crack
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +80,14 @@ dependencies:
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '3.3'
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 3.3.2
83
+ version: 3.3.0
87
84
  type: :development
88
85
  prerelease: false
89
86
  version_requirements: !ruby/object:Gem::Requirement
90
87
  requirements:
91
88
  - - "~>"
92
89
  - !ruby/object:Gem::Version
93
- version: '3.3'
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 3.3.2
90
+ version: 3.3.0
97
91
  description: Checkstyle linter plugin for pre-commit. Useful for linting Java code.
98
92
  email:
99
93
  - blatyo@gmail.com
@@ -106,27 +100,30 @@ files:
106
100
  - ".gitignore"
107
101
  - ".rspec"
108
102
  - ".travis.yml"
103
+ - DETAILED_TUTORIAL.md
109
104
  - Gemfile
110
105
  - LICENSE.txt
111
106
  - README.md
112
107
  - Rakefile
108
+ - demo.png
113
109
  - java-checkstyle.gemspec
114
110
  - lib/plugins/pre_commit/checks/checkstyle.rb
115
111
  - lib/plugins/pre_commit/message/extractor.rb
116
112
  - lib/plugins/pre_commit/message/formatter.rb
117
113
  - lib/plugins/pre_commit/support/path.rb
118
114
  - lib/pre-commit/checkstyle/version.rb
119
- - lib/pre-commit/support/checkstyle/checkstyle-5.7-all.jar
120
115
  - lib/pre-commit/support/checkstyle/checkstyle-6.11-all.jar
121
116
  - lib/pre-commit/support/checkstyle/google_checks.xml
122
- - lib/pre-commit/support/checkstyle/sun_checks.xml
117
+ - readmedemo.png
123
118
  - spec/fixtures/bad.java
124
119
  - spec/fixtures/bad2.java
125
120
  - spec/fixtures/good.java
126
- - spec/fixtures/google_checks.xml
121
+ - spec/fixtures/output_one_bad_file.log
122
+ - spec/fixtures/output_two_bad_files.log
123
+ - spec/fixtures/sun_checks.xml
127
124
  - spec/plugins/pre_commit/checks/checkstyle_spec.rb
128
125
  - spec/plugins/pre_commit/message/extractor_spec.rb
129
- - spec/plugins/pre_commit/output/formatter.rb
126
+ - spec/plugins/pre_commit/message/formatter_spec.rb
130
127
  - spec/spec_helper.rb
131
128
  homepage: https://github.com/CristianOliveiraDaRosa/java-checkstyle
132
129
  licenses:
@@ -148,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
145
  version: '0'
149
146
  requirements: []
150
147
  rubyforge_project:
151
- rubygems_version: 2.4.8
148
+ rubygems_version: 2.4.3
152
149
  signing_key:
153
150
  specification_version: 4
154
151
  summary: Checkstyle linter plugin for pre-commit
@@ -156,9 +153,10 @@ test_files:
156
153
  - spec/fixtures/bad.java
157
154
  - spec/fixtures/bad2.java
158
155
  - spec/fixtures/good.java
159
- - spec/fixtures/google_checks.xml
156
+ - spec/fixtures/output_one_bad_file.log
157
+ - spec/fixtures/output_two_bad_files.log
158
+ - spec/fixtures/sun_checks.xml
160
159
  - spec/plugins/pre_commit/checks/checkstyle_spec.rb
161
160
  - spec/plugins/pre_commit/message/extractor_spec.rb
162
- - spec/plugins/pre_commit/output/formatter.rb
161
+ - spec/plugins/pre_commit/message/formatter_spec.rb
163
162
  - spec/spec_helper.rb
164
- has_rdoc:
@@ -1,206 +0,0 @@
1
- <?xml version="1.0"?>
2
- <!DOCTYPE module PUBLIC
3
- "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4
- "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5
-
6
- <!--
7
-
8
- Checkstyle configuration that checks the Google coding conventions from:
9
-
10
- - Google Java Style
11
- https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html
12
-
13
- Checkstyle is very configurable. Be sure to read the documentation at
14
- http://checkstyle.sf.net (or in your downloaded distribution).
15
-
16
- Most Checks are configurable, be sure to consult the documentation.
17
-
18
- To completely disable a check, just comment it out or delete it from the file.
19
-
20
- Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
21
-
22
- -->
23
-
24
- <module name = "Checker">
25
- <property name="charset" value="UTF-8"/>
26
-
27
- <property name="severity" value="warning"/>
28
-
29
- <property name="fileExtensions" value="java, properties, xml"/>
30
- <!-- Checks for whitespace -->
31
- <!-- See http://checkstyle.sf.net/config_whitespace.html -->
32
- <module name="FileTabCharacter">
33
- <property name="eachLine" value="true"/>
34
- </module>
35
-
36
- <module name="TreeWalker">
37
- <module name="OuterTypeFilename"/>
38
- <module name="IllegalTokenText">
39
- <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
40
- <property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
41
- <property name="message" value="Avoid using corresponding octal or Unicode escape."/>
42
- </module>
43
- <module name="AvoidEscapedUnicodeCharacters">
44
- <property name="allowEscapesForControlCharacters" value="true"/>
45
- <property name="allowByTailComment" value="true"/>
46
- <property name="allowNonPrintableEscapes" value="true"/>
47
- </module>
48
- <module name="LineLength">
49
- <property name="max" value="100"/>
50
- <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
51
- </module>
52
- <module name="AvoidStarImport"/>
53
- <module name="OneTopLevelClass"/>
54
- <module name="NoLineWrap"/>
55
- <module name="EmptyBlock">
56
- <property name="option" value="TEXT"/>
57
- <property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
58
- </module>
59
- <module name="NeedBraces"/>
60
- <module name="LeftCurly">
61
- <property name="maxLineLength" value="100"/>
62
- </module>
63
- <module name="RightCurly"/>
64
- <module name="RightCurly">
65
- <property name="option" value="alone"/>
66
- <property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
67
- </module>
68
- <module name="WhitespaceAround">
69
- <property name="allowEmptyConstructors" value="true"/>
70
- <property name="allowEmptyMethods" value="true"/>
71
- <property name="allowEmptyTypes" value="true"/>
72
- <property name="allowEmptyLoops" value="true"/>
73
- <message key="ws.notFollowed"
74
- value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
75
- <message key="ws.notPreceded"
76
- value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
77
- </module>
78
- <module name="OneStatementPerLine"/>
79
- <module name="MultipleVariableDeclarations"/>
80
- <module name="ArrayTypeStyle"/>
81
- <module name="MissingSwitchDefault"/>
82
- <module name="FallThrough"/>
83
- <module name="UpperEll"/>
84
- <module name="ModifierOrder"/>
85
- <module name="EmptyLineSeparator">
86
- <property name="allowNoEmptyLineBetweenFields" value="true"/>
87
- </module>
88
- <module name="SeparatorWrap">
89
- <property name="tokens" value="DOT"/>
90
- <property name="option" value="nl"/>
91
- </module>
92
- <module name="SeparatorWrap">
93
- <property name="tokens" value="COMMA"/>
94
- <property name="option" value="EOL"/>
95
- </module>
96
- <module name="PackageName">
97
- <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
98
- <message key="name.invalidPattern"
99
- value="Package name ''{0}'' must match pattern ''{1}''."/>
100
- </module>
101
- <module name="TypeName">
102
- <message key="name.invalidPattern"
103
- value="Type name ''{0}'' must match pattern ''{1}''."/>
104
- </module>
105
- <module name="MemberName">
106
- <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
107
- <message key="name.invalidPattern"
108
- value="Member name ''{0}'' must match pattern ''{1}''."/>
109
- </module>
110
- <module name="ParameterName">
111
- <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
112
- <message key="name.invalidPattern"
113
- value="Parameter name ''{0}'' must match pattern ''{1}''."/>
114
- </module>
115
- <module name="LocalVariableName">
116
- <property name="tokens" value="VARIABLE_DEF"/>
117
- <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
118
- <property name="allowOneCharVarInForLoop" value="true"/>
119
- <message key="name.invalidPattern"
120
- value="Local variable name ''{0}'' must match pattern ''{1}''."/>
121
- </module>
122
- <module name="ClassTypeParameterName">
123
- <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
124
- <message key="name.invalidPattern"
125
- value="Class type name ''{0}'' must match pattern ''{1}''."/>
126
- </module>
127
- <module name="MethodTypeParameterName">
128
- <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
129
- <message key="name.invalidPattern"
130
- value="Method type name ''{0}'' must match pattern ''{1}''."/>
131
- </module>
132
- <module name="NoFinalizer"/>
133
- <module name="GenericWhitespace">
134
- <message key="ws.followed"
135
- value="GenericWhitespace ''{0}'' is followed by whitespace."/>
136
- <message key="ws.preceded"
137
- value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
138
- <message key="ws.illegalFollow"
139
- value="GenericWhitespace ''{0}'' should followed by whitespace."/>
140
- <message key="ws.notPreceded"
141
- value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
142
- </module>
143
- <module name="Indentation">
144
- <property name="basicOffset" value="2"/>
145
- <property name="braceAdjustment" value="0"/>
146
- <property name="caseIndent" value="2"/>
147
- <property name="throwsIndent" value="4"/>
148
- <property name="lineWrappingIndentation" value="4"/>
149
- <property name="arrayInitIndent" value="2"/>
150
- </module>
151
- <module name="AbbreviationAsWordInName">
152
- <property name="ignoreFinal" value="false"/>
153
- <property name="allowedAbbreviationLength" value="1"/>
154
- </module>
155
- <module name="OverloadMethodsDeclarationOrder"/>
156
- <module name="VariableDeclarationUsageDistance"/>
157
- <module name="CustomImportOrder">
158
- <property name="specialImportsRegExp" value="com.google"/>
159
- <property name="sortImportsInGroupAlphabetically" value="true"/>
160
- <property name="customImportOrderRules" value="STATIC###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
161
- </module>
162
- <module name="MethodParamPad"/>
163
- <module name="OperatorWrap">
164
- <property name="option" value="NL"/>
165
- <property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
166
- </module>
167
- <module name="AnnotationLocation">
168
- <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
169
- </module>
170
- <module name="AnnotationLocation">
171
- <property name="tokens" value="VARIABLE_DEF"/>
172
- <property name="allowSamelineMultipleAnnotations" value="true"/>
173
- </module>
174
- <module name="NonEmptyAtclauseDescription"/>
175
- <module name="JavadocTagContinuationIndentation"/>
176
- <module name="SummaryJavadocCheck">
177
- <property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
178
- </module>
179
- <module name="JavadocParagraph"/>
180
- <module name="AtclauseOrder">
181
- <property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
182
- <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
183
- </module>
184
- <module name="JavadocMethod">
185
- <property name="scope" value="public"/>
186
- <property name="allowMissingParamTags" value="true"/>
187
- <property name="allowMissingThrowsTags" value="true"/>
188
- <property name="allowMissingReturnTag" value="true"/>
189
- <property name="minLineCount" value="2"/>
190
- <property name="allowedAnnotations" value="Override, Test"/>
191
- <property name="allowThrowsTagsForSubclasses" value="true"/>
192
- </module>
193
- <module name="MethodName">
194
- <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
195
- <message key="name.invalidPattern"
196
- value="Method name ''{0}'' must match pattern ''{1}''."/>
197
- </module>
198
- <module name="SingleLineJavadoc">
199
- <property name="ignoreInlineTags" value="false"/>
200
- </module>
201
- <module name="EmptyCatchBlock">
202
- <property name="exceptionVariableName" value="expected"/>
203
- </module>
204
- <module name="CommentsIndentation"/>
205
- </module>
206
- </module>
File without changes