Skip to content

Commit c5e9c50

Browse files
krichter722tumbarumba
authored andcommitted
Start checkstyle setup
As suggested in #214 the checkstyle setup can be put forward step by step in order to minimize controversy. The start contains a rule to enforce spaces instead of tab characters which are already used in roughly 99.99% of the source.
1 parent 7f10c55 commit c5e9c50

File tree

7 files changed

+58
-25
lines changed

7 files changed

+58
-25
lines changed

build.gradle

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ group = "org.hamcrest"
66
version = "2.2-SNAPSHOT"
77

88
subprojects {
9+
apply plugin: 'checkstyle'
910
apply plugin: 'java-library'
1011

1112
sourceCompatibility = JavaVersion.VERSION_1_7
@@ -18,6 +19,27 @@ subprojects {
1819
mavenCentral()
1920
}
2021

22+
checkstyle {
23+
24+
project.ext.checkstyleVersion = '6.18'
25+
//works with a JDK 7 version which is supposed to be supported although
26+
//deprecated, see https://github.com/hamcrest/JavaHamcrest/pull/211 for
27+
//the discussion about the support
28+
29+
sourceSets = [ project.sourceSets.main, project.sourceSets.test ]
30+
ignoreFailures = false
31+
configFile = file("${project.rootDir}/checkstyle.xml")
32+
33+
configurations {
34+
checkstyle
35+
}
36+
37+
dependencies{
38+
assert project.hasProperty("checkstyleVersion")
39+
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
40+
}
41+
}
42+
2143
test {
2244
testLogging {
2345
exceptionFormat = 'full'

checkstyle.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
5+
<module name="Checker">
6+
<!-- Checks that there are no tab characters ('\t') in the source code. -->
7+
<module name="FileTabCharacter">
8+
<!-- Report on each line in each file -->
9+
<property name="eachLine" value="true"/>
10+
</module>
11+
</module>

hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static <E> Matcher<Collection<? extends E>> hasSize(Matcher<? super Integ
4444
*/
4545
@SuppressWarnings({ "rawtypes", "unchecked" })
4646
public static <E> Matcher<Collection<? extends E>> hasSize(int size) {
47-
return (Matcher)IsCollectionWithSize.hasSize(equalTo(size));
47+
return (Matcher)IsCollectionWithSize.hasSize(equalTo(size));
4848
}
4949

5050
}

hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static <E> Matcher<Iterable<? extends E>> contains(Matcher<? super E>...
129129
// required for JDK 1.6
130130
//noinspection RedundantTypeArguments
131131
final List<Matcher<? super E>> nullSafeWithExplicitTypeMatchers = NullSafety.<E>nullSafe(itemMatchers);
132-
return contains(nullSafeWithExplicitTypeMatchers);
132+
return contains(nullSafeWithExplicitTypeMatchers);
133133
}
134134

135135
/**

hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void testHasAReadableDescription() {
5555
}
5656

5757
public void testCanHandleNullMatchers() {
58-
assertMatches(contains(null, null), asList(null, null));
58+
assertMatches(contains(null, null), asList(null, null));
5959
}
6060

6161
public static class WithValue {

hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,30 @@ public String toString() {
2626

2727
@Test public void
2828
matchesWhenUtilisingANestedMatcher() {
29-
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
29+
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
3030

31-
assertMatches(matcher, TEST_OBJECT);
32-
assertDoesNotMatch(matcher, new Object());
31+
assertMatches(matcher, TEST_OBJECT);
32+
assertDoesNotMatch(matcher, new Object());
3333
}
3434

3535
@Test public void
3636
matchesWhenUsingShortcutForHasToStringEqualTo() {
37-
final Matcher<Object> matcher = hasToString(TO_STRING_RESULT);
38-
39-
assertMatches(matcher, TEST_OBJECT);
40-
assertDoesNotMatch(matcher, new Object());
37+
final Matcher<Object> matcher = hasToString(TO_STRING_RESULT);
38+
39+
assertMatches(matcher, TEST_OBJECT);
40+
assertDoesNotMatch(matcher, new Object());
4141
}
4242

4343
@Test public void
4444
describesItself() {
45-
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
45+
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
4646
assertDescription("with toString() \"toString result\"", matcher);
4747
}
4848

4949
@Test public void
5050
describesAMismatch() {
51-
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
52-
String expectedMismatchString = "toString() was \"Cheese\"";
51+
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
52+
String expectedMismatchString = "toString() was \"Cheese\"";
5353
assertMismatchDescription(expectedMismatchString, matcher, "Cheese");
5454
}
5555
}

hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ public final class IsEqualIgnoringCaseTest {
1919
@Test public void
2020
ignoresCaseOfCharsInString() {
2121
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
22-
22+
2323
assertMatches(matcher, "HELLO");
2424
assertMatches(matcher, "hello");
2525
assertMatches(matcher, "HelLo");
26-
assertDoesNotMatch(matcher, "bye");
26+
assertDoesNotMatch(matcher, "bye");
2727
}
2828

2929
@Test public void
3030
mismatchesIfAdditionalWhitespaceIsPresent() {
31-
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
32-
33-
assertDoesNotMatch(matcher, "hello ");
34-
assertDoesNotMatch(matcher, " hello");
31+
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
32+
33+
assertDoesNotMatch(matcher, "hello ");
34+
assertDoesNotMatch(matcher, " hello");
3535
}
3636

3737
@Test public void
3838
mismatchesNull() {
39-
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
40-
41-
assertDoesNotMatch(matcher, null);
39+
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
40+
41+
assertDoesNotMatch(matcher, null);
4242
}
4343

4444
@Test(expected=IllegalArgumentException.class) public void
@@ -49,14 +49,14 @@ public final class IsEqualIgnoringCaseTest {
4949

5050
@Test public void
5151
describesItself() {
52-
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
52+
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
5353
assertDescription("a string equal to \"heLLo\" ignoring case", matcher);
5454
}
5555

5656
@Test public void
5757
describesAMismatch() {
58-
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
59-
String expectedMismatchString = "was \"Cheese\"";
58+
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
59+
String expectedMismatchString = "was \"Cheese\"";
6060
assertMismatchDescription(expectedMismatchString, matcher, "Cheese");
6161
}
6262
}

0 commit comments

Comments
 (0)