java-checkstyle 0.0.2

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
+ SHA1:
3
+ metadata.gz: 7195c535a4ffe35bc6059ad1dc13a1e326dfc94e
4
+ data.tar.gz: c8facc5e071412a45073591ed1aaf76f01d5cfe2
5
+ SHA512:
6
+ metadata.gz: 8e5184be4154f4a5db9f184c411f3c3492079b39be29ae7e167b5c0bdffc0f0416950015913537137ddda9e58a5ab1c837a305f8b24570751bd34a4e6fc35197
7
+ data.tar.gz: 953cb0b0c1c35b4499d7898273af8a1bc3a44dbe177d2611f4b4e8fb438c8d9a883ce9a6d558d50b5ae27f47f1276dd6b632183ffda2e5fc377a23afa5182746
data/.codeclimate.yml ADDED
@@ -0,0 +1,2 @@
1
+ languages:
2
+ Ruby: true
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.2.0
5
+ - jruby-19mode
6
+
7
+ script:
8
+ - rake
9
+ - bundle exec rubocop lib/*
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pre-commit-checkstyle.gemspec
4
+ gemspec
5
+ gem 'crack'
6
+
7
+ group :test do
8
+ gem "codeclimate-test-reporter", require: nil
9
+ gem 'rubocop', require: false
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Allen Madsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ ## Java - Pre-Commit Checkstyle
2
+ [![Build Status](https://travis-ci.org/CristianOliveiraDaRosa/java-checkstyle.svg?branch=dev)](https://travis-ci.org/CristianOliveiraDaRosa/java-checkstyle)
3
+ [![Code Climate](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle/badges/gpa.svg)](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle)
4
+ [![Test Coverage](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle/badges/coverage.svg)](https://codeclimate.com/github/CristianOliveiraDaRosa/java-checkstyle/coverage)
5
+
6
+ [Checkstyle](http://checkstyle.sourceforge.net/) linter plugin for [pre-commit](https://github.com/jish/pre-commit). Useful for linting Java code.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'pre-commit-checkstyle'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install pre-commit-checkstyle
21
+
22
+ ## Usage
23
+
24
+ Make sure the gem is installed and setup the check in [pre-commit](https://github.com/jish/pre-commit) with:
25
+
26
+ ``` bash
27
+ pre-commit enable git checks checkstyle
28
+ ```
29
+
30
+ OR
31
+
32
+ ``` bash
33
+ pre-commit enable yaml checks checkstyle
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( http://github.com/secondrotation/pre-commit-checkstyle/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
44
+ ## Authors:
45
+ - Allen Madsen (Original Version 0.0.1)
46
+ - Alex Rocha
47
+ - Cristian Oliveira
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pre-commit/checkstyle/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "java-checkstyle"
8
+ spec.version = PreCommit::Checkstyle::VERSION
9
+ spec.authors = ["Allen Madsen", "Cristian Oliveira", "Alex Rocha"]
10
+ spec.email = ["blatyo@gmail.com", "contato@cristianoliveira.com.br"]
11
+ spec.summary = %q{Checkstyle linter plugin for pre-commit}
12
+ spec.description = %q{Checkstyle linter plugin for pre-commit. Useful for linting Java code.}
13
+ spec.homepage = "https://github.com/CristianOliveiraDaRosa/java-checkstyle"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency('pre-commit', '~> 0.16')
22
+ spec.add_dependency('crack', '~> 0.4.2')
23
+
24
+ spec.add_development_dependency("bundler", "~> 1.5")
25
+ spec.add_development_dependency("rake", '~> 10.4', '>= 10.4.2')
26
+ spec.add_development_dependency("rspec", '~> 3.3', '>= 3.3.2')
27
+ end
@@ -0,0 +1,71 @@
1
+ require 'pre-commit/checks/shell'
2
+ require_relative '../message/extractor'
3
+ require_relative '../message/formatter'
4
+ require_relative '../support/path'
5
+
6
+ module PreCommit
7
+ module Checks
8
+ ##
9
+ # Plugin implementation for pre-commit gem
10
+ #
11
+ # It provides a java checkstyle validation using checkstyle.jar
12
+ # for details see:
13
+ # lib/pre-commit/support/checkstyle
14
+ class Checkstyle < Shell
15
+ ##
16
+ # Function called after pre-commit execution
17
+ # this method receive the +staged_files+ from git
18
+ #
19
+ # @param [String] Standard git ouput with staged files
20
+ def call(staged_files)
21
+ staged_files = staged_files.grep(/\.java$/)
22
+ return if staged_files.empty?
23
+
24
+ output = execute(args(staged_files))
25
+ format(extract(output))
26
+ end
27
+
28
+ private
29
+
30
+ def args(staged_files)
31
+ [
32
+ 'java',
33
+ checkstyle_jar,
34
+ configuration_file,
35
+ staged_files,
36
+ output_format
37
+ ]
38
+ end
39
+
40
+ def checkstyle_jar
41
+ ['-jar', Support::Path.relative_to('checkstyle-6.11-all.jar')]
42
+ end
43
+
44
+ def configuration_file
45
+ config_file ? ['-c', config_file] : []
46
+ end
47
+
48
+ def output_format
49
+ ['-f', 'xml']
50
+ end
51
+
52
+ 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'
58
+ end
59
+
60
+ def format(errors)
61
+ @formatter ||= PreCommit::Message::Formatter.new
62
+ @formatter.format errors
63
+ end
64
+
65
+ def extract(data)
66
+ @extractor ||= PreCommit::Message::Extractor.new
67
+ @extractor.extract data
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,27 @@
1
+ require 'crack'
2
+
3
+ module PreCommit
4
+ module Message
5
+ ##
6
+ # Responsible for extract error messages from terminal output
7
+ class Extractor
8
+ EMPTY = { 'checkstyle' => { 'file' => [] } }
9
+
10
+ ##
11
+ # Extract data from a XML formatted +output+
12
+ #
13
+ # @param output [String] Xml formatted ouput
14
+ # @return [Hash]
15
+ def extract(output)
16
+ return EMPTY if output.nil? || output.empty?
17
+ Crack::XML.parse(xml_content(output))
18
+ end
19
+
20
+ private
21
+
22
+ def xml_content(raw_output)
23
+ raw_output[/<(.*)>/m]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ module PreCommit
2
+ module Message
3
+ ##
4
+ # Responsible for format a given output
5
+ class Formatter
6
+ ##
7
+ # Format output for a given +errors+ details
8
+ #
9
+ # @param [Hash] JSON errors details
10
+ # @return [String] formatted output (may return nil)
11
+ def format(errors)
12
+ files = errors['checkstyle']['file']
13
+
14
+ return nil if files.empty?
15
+ return format_single(files) unless files.is_a? Array
16
+
17
+ format_multiple(files)
18
+ end
19
+
20
+ private
21
+
22
+ def format_errors(errors)
23
+ errors.reduce('') do |out, error|
24
+ out + " line: #{error['line']}:#{error['column']}"\
25
+ " error: #{error['message']}\n"
26
+ end
27
+ end
28
+
29
+ def format_single(file)
30
+ "File errors: #{file['name']} \n" + format_errors(file['error'])
31
+ end
32
+
33
+ def format_multiple(files)
34
+ files.reduce('') { |a, e| a + format_single(e) }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ module Support
2
+ ##
3
+ # Responsible for provide relative paths to support files
4
+ # Files located under: /lib/plugin/pre-commit/support/checkstyle*
5
+ module Path
6
+ ##
7
+ # Return support path relative to a given +file+
8
+ #
9
+ # @param file [String] file name
10
+ # @return [String] formatted path
11
+ def self.relative_to(file)
12
+ File.expand_path(
13
+ "../../../../pre-commit/support/checkstyle/#{file}",
14
+ __FILE__
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ ##
2
+ # This a fork version of the original
3
+ # checkstyle:
4
+ # https://github.com/secondrotation/pre-commit-checkstyle
5
+ #
6
+ module PreCommit
7
+ ##
8
+ # CheckStyle Version
9
+ # Authors:
10
+ # Allen Madsen (Original Version 0.0.1)
11
+ # Cristian Oliveira
12
+ # Alex Rocha
13
+ module Checkstyle
14
+ VERSION = '0.0.2'
15
+ end
16
+ end
@@ -0,0 +1,206 @@
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>