java-checkstyle 0.0.2

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.
@@ -0,0 +1,177 @@
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 sun coding conventions from:
9
+
10
+ - the Java Language Specification at
11
+ http://java.sun.com/docs/books/jls/second_edition/html/index.html
12
+
13
+ - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
14
+
15
+ - the Javadoc guidelines at
16
+ http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
17
+
18
+ - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
19
+
20
+ - some best practices
21
+
22
+ Checkstyle is very configurable. Be sure to read the documentation at
23
+ http://checkstyle.sf.net (or in your downloaded distribution).
24
+
25
+ Most Checks are configurable, be sure to consult the documentation.
26
+
27
+ To completely disable a check, just comment it out or delete it from the file.
28
+
29
+ Finally, it is worth reading the documentation.
30
+
31
+ -->
32
+
33
+ <module name="Checker">
34
+ <!--
35
+ If you set the basedir property below, then all reported file
36
+ names will be relative to the specified directory. See
37
+ http://checkstyle.sourceforge.net/5.x/config.html#Checker
38
+
39
+ <property name="basedir" value="${basedir}"/>
40
+ -->
41
+
42
+ <!-- Checks that a package-info.java file exists for each package. -->
43
+ <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
44
+ <!-- <module name="JavadocPackage"/> -->
45
+
46
+ <!-- Checks whether files end with a new line. -->
47
+ <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
48
+ <module name="NewlineAtEndOfFile"/>
49
+
50
+ <!-- Checks that property files contain the same keys. -->
51
+ <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
52
+ <module name="Translation"/>
53
+
54
+ <!-- Checks for Size Violations. -->
55
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
56
+ <module name="FileLength"/>
57
+
58
+ <!-- Checks for whitespace -->
59
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
60
+ <module name="FileTabCharacter"/>
61
+
62
+ <!-- Miscellaneous other checks. -->
63
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
64
+ <module name="RegexpSingleline">
65
+ <property name="format" value="\s+$"/>
66
+ <property name="minimum" value="0"/>
67
+ <property name="maximum" value="0"/>
68
+ <property name="message" value="Line has trailing spaces."/>
69
+ </module>
70
+
71
+ <!-- Checks for Headers -->
72
+ <!-- See http://checkstyle.sf.net/config_header.html -->
73
+ <!-- <module name="Header"> -->
74
+ <!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
75
+ <!-- <property name="fileExtensions" value="java"/> -->
76
+ <!-- </module> -->
77
+
78
+ <module name="TreeWalker">
79
+
80
+ <!-- Checks for Javadoc comments. -->
81
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
82
+ <module name="JavadocMethod"/>
83
+ <module name="JavadocType"/>
84
+ <module name="JavadocVariable"/>
85
+ <module name="JavadocStyle"/>
86
+
87
+
88
+ <!-- Checks for Naming Conventions. -->
89
+ <!-- See http://checkstyle.sf.net/config_naming.html -->
90
+ <module name="ConstantName"/>
91
+ <module name="LocalFinalVariableName"/>
92
+ <module name="LocalVariableName"/>
93
+ <module name="MemberName"/>
94
+ <module name="MethodName"/>
95
+ <module name="PackageName"/>
96
+ <module name="ParameterName"/>
97
+ <module name="StaticVariableName"/>
98
+ <module name="TypeName"/>
99
+
100
+
101
+ <!-- Checks for imports -->
102
+ <!-- See http://checkstyle.sf.net/config_import.html -->
103
+ <module name="AvoidStarImport"/>
104
+ <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
105
+ <module name="RedundantImport"/>
106
+ <module name="UnusedImports"/>
107
+
108
+
109
+ <!-- Checks for Size Violations. -->
110
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
111
+ <module name="LineLength"/>
112
+ <module name="MethodLength"/>
113
+ <module name="ParameterNumber"/>
114
+
115
+
116
+ <!-- Checks for whitespace -->
117
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
118
+ <module name="EmptyForIteratorPad"/>
119
+ <module name="GenericWhitespace"/>
120
+ <module name="MethodParamPad"/>
121
+ <module name="NoWhitespaceAfter"/>
122
+ <module name="NoWhitespaceBefore"/>
123
+ <module name="OperatorWrap"/>
124
+ <module name="ParenPad"/>
125
+ <module name="TypecastParenPad"/>
126
+ <module name="WhitespaceAfter"/>
127
+ <module name="WhitespaceAround"/>
128
+
129
+
130
+ <!-- Modifier Checks -->
131
+ <!-- See http://checkstyle.sf.net/config_modifiers.html -->
132
+ <module name="ModifierOrder"/>
133
+ <module name="RedundantModifier"/>
134
+
135
+
136
+ <!-- Checks for blocks. You know, those {}'s -->
137
+ <!-- See http://checkstyle.sf.net/config_blocks.html -->
138
+ <module name="AvoidNestedBlocks"/>
139
+ <module name="EmptyBlock"/>
140
+ <module name="LeftCurly"/>
141
+ <module name="NeedBraces"/>
142
+ <module name="RightCurly"/>
143
+
144
+
145
+ <!-- Checks for common coding problems -->
146
+ <!-- See http://checkstyle.sf.net/config_coding.html -->
147
+ <module name="AvoidInlineConditionals"/>
148
+ <module name="EmptyStatement"/>
149
+ <module name="EqualsHashCode"/>
150
+ <module name="HiddenField"/>
151
+ <module name="IllegalInstantiation"/>
152
+ <module name="InnerAssignment"/>
153
+ <module name="MagicNumber"/>
154
+ <module name="MissingSwitchDefault"/>
155
+ <!--<module name="RedundantThrows"/>-->
156
+ <module name="SimplifyBooleanExpression"/>
157
+ <module name="SimplifyBooleanReturn"/>
158
+
159
+ <!-- Checks for class design -->
160
+ <!-- See http://checkstyle.sf.net/config_design.html -->
161
+ <module name="DesignForExtension"/>
162
+ <module name="FinalClass"/>
163
+ <module name="HideUtilityClassConstructor"/>
164
+ <module name="InterfaceIsType"/>
165
+ <module name="VisibilityModifier"/>
166
+
167
+
168
+ <!-- Miscellaneous other checks. -->
169
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
170
+ <module name="ArrayTypeStyle"/>
171
+ <module name="FinalParameters"/>
172
+ <module name="TodoComment"/>
173
+ <module name="UpperEll"/>
174
+
175
+ </module>
176
+
177
+ </module>
@@ -0,0 +1,5 @@
1
+ class HelloWorld {
2
+ public static void main(String[] args) {
3
+ System.out.println("Hello World!");
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ class HelloWorld {
2
+ public static void main(String[] args) {
3
+ System.out.println("Hello World!");
4
+ }
5
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Typical hello world example.
3
+ */
4
+ final class HelloWorld {
5
+ /**
6
+ * Prevent class from being instantiated.
7
+ *
8
+ * @throws AssertionError
9
+ */
10
+ private HelloWorld() {
11
+ throw new AssertionError("Instantiating utility class...");
12
+ }
13
+
14
+ /**
15
+ * Prints Hello World!
16
+ *
17
+ * @param args Command line arguments
18
+ */
19
+ public static void main(final String[] args) {
20
+ System.out.println("Hello World!");
21
+ }
22
+ }
@@ -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>
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'plugins/pre_commit/checks/checkstyle'
3
+
4
+ describe PreCommit::Checks::Checkstyle do
5
+ let(:config) {double(PreCommit::Configuration, get: '')}
6
+ let(:check) {PreCommit::Checks::Checkstyle.new(nil, config, [])}
7
+
8
+ it "succeds if nothing changed" do
9
+ expect(check.call([])).to be_nil
10
+ end
11
+
12
+ it "succeeds for good code" do
13
+ files = [fixture_file('good.java')]
14
+ expect(check.call(files)).to be_nil
15
+ end
16
+
17
+ it "should fail for bad formatted code" do
18
+ file = fixture_file("bad.java")
19
+
20
+ result = check.call([file])
21
+
22
+ expect(result).to include "File errors: #{file}"
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:"
27
+ end
28
+
29
+
30
+ it "should accept multiple fails" do
31
+ # given
32
+ file = fixture_file("bad.java")
33
+ file2 = fixture_file("bad2.java")
34
+
35
+ # when
36
+ result = check.call([file, file2])
37
+
38
+ # then
39
+ expect(result).to include "File errors: #{file}"
40
+ expect(result).to include "File errors: #{file2}"
41
+ end
42
+
43
+ it "should accept custom checkstyle" do
44
+ # given
45
+ files = [fixture_file('good.java')]
46
+ custom_config = double(PreCommit::Configuration,
47
+ get: fixture_file('google_checks.xml'))
48
+ # when
49
+ check.config = custom_config
50
+ # then
51
+ expect(check.call(files)).to be_nil
52
+ end
53
+ end