Skip to content

Commit

Permalink
Fix code style for checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
leadpony committed Jun 15, 2019
1 parent c061cce commit ac4dcc1
Show file tree
Hide file tree
Showing 216 changed files with 2,853 additions and 2,064 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target/
.settings/
.classpath
.project
.checkstyle
121 changes: 121 additions & 0 deletions justify-cli/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
<property name="fileExtensions" value="java, properties, xml"/>

<!-- Checks whether files end with a new line. -->
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf_cr_crlf"/>
</module>

<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="FileLength"/>

<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter">
<property name="eachLine" value="true" />
</module>

<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>

<module name="Translation"/>

<module name="TreeWalker">

<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocType" />
<module name="JavadocStyle"/>

<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>

<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<!-- <module name="AvoidStarImport"/> -->
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>

<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="LineLength">
<property name="max" value="120" />
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>

<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>

<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>

<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>

<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="TodoComment"/>
<module name="UpperEll"/>

</module>

</module>
24 changes: 24 additions & 0 deletions justify-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@
</testResources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<excludes>**/module-info.java</excludes>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<includeTestResources>true</includeTestResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -156,6 +167,19 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ enum Color {
DEFAULT(""),
SUCCESS("\u001b[92m"),
WARNING("\u001b[93m"),
DANGER("\u001b[91m"),
;
DANGER("\u001b[91m");

private final String code;

private Color(String code) {
Color(String code) {
this.code = code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static Location at(String location) {
}

/**
* Opens an input stream from this location,
* Opens an input stream from this location.
*
* @return newly created input stream.
* @throws IOException if an I/O error has occurred.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ enum Message {
SCHEMA_FAILED,
CATALOG_FAILED,

ACCESS_FAILED,
;
ACCESS_FAILED;

private static final String BUNDLE_NAME = Message.class.getPackage().getName() + ".messages";
private static final ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME);
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

/**
* Returns this message as a string.
Expand All @@ -76,7 +75,7 @@ enum Message {
*/
@Override
public String toString() {
return bundle.getString(name());
return BUNDLE.getString(name());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String name() {

@Override
public Localizable localizedName() {
return locale->Message.PATH_OR_URL.toString();
return locale -> Message.PATH_OR_URL.toString();
}

@Override
Expand All @@ -46,7 +46,7 @@ public InstanceType valueType() {

@Override
public boolean test(JsonValue value) {
String string = ((JsonString)value).getString();
String string = ((JsonString) value).getString();
try {
Location.at(string);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum Status {

private final int code;

private Status(int code) {
Status(int code) {
this.code = code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ enum ValidateOption implements Option {
INSTANCE("-i"),
REFERENCE("-r"),
CATALOG("-catalog"),
STRICT("-strict"),
;
STRICT("-strict");

private final String[] names;

private static final Map<String, ValidateOption> options = new HashMap<>();
private static final Map<String, ValidateOption> OPTIONS = new HashMap<>();

static {
for (ValidateOption value : values()) {
for (String name : value.names) {
options.put(name, value);
OPTIONS.put(name, value);
}
}
}
Expand All @@ -50,7 +49,7 @@ enum ValidateOption implements Option {
*
* @param names the names of this option.
*/
private ValidateOption(String... names) {
ValidateOption(String... names) {
this.names = names;
}

Expand Down Expand Up @@ -109,8 +108,8 @@ public Object getTypedArgument(String string) {
* @throws NoSuchElementException if no such option exists.
*/
static ValidateOption byName(String name) {
if (options.containsKey(name)) {
return options.get(name);
if (OPTIONS.containsKey(name)) {
return OPTIONS.get(name);
} else {
throw new NoSuchElementException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
*
* @author leadpony
*/
package org.leadpony.justify.cli;
package org.leadpony.justify.cli;
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author leadpony
*/
class Fixture {
final class Fixture {

private static final Path BASE_DIR = Paths.get("target", "test-classes");
private static final URI BASE_URL = URI.create("http://localhost:1234/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ public static Stream<Arguments> validLocal() {
Arguments.of("test.json"),
Arguments.of("target/test.json"),
Arguments.of("../test.json"),
Arguments.of("/root/test.json")
);
Arguments.of("/root/test.json"));
}

@ParameterizedTest
@MethodSource("validLocal")
public void at_shouldReturnLocalResource(String string) throws MalformedURLException {
public void atShouldReturnLocalResource(String string) throws MalformedURLException {
Location actual = Location.at(string);
assertThat(actual).isNotNull();
assertThat(actual.toURL().getProtocol()).isEqualTo("file");
Expand All @@ -51,27 +50,25 @@ public void at_shouldReturnLocalResource(String string) throws MalformedURLExcep
public static Stream<Arguments> validRemote() throws MalformedURLException {
return Stream.of(
Arguments.of("http://localhost/test.json", new URL("http://localhost/test.json")),
Arguments.of("https://example.org/test.json", new URL("https://example.org/test.json"))
);
Arguments.of("https://example.org/test.json", new URL("https://example.org/test.json")));
}

@ParameterizedTest
@MethodSource("validRemote")
public void at_shouldReturnRemoteResource(String string, URL expected) throws MalformedURLException {
public void atShouldReturnRemoteResource(String string, URL expected) throws MalformedURLException {
Location actual = Location.at(string);
assertThat(actual.toURL()).isEqualTo(expected);
}

public static Stream<Arguments> invalidRemote() throws MalformedURLException {
return Stream.of(
Arguments.of("")
);
Arguments.of(""));
}

@ParameterizedTest
@MethodSource("invalidRemote")
public void at_shouldThrowException(String string) {
Throwable thrown = catchThrowable(()->{
public void atShouldThrowException(String string) {
Throwable thrown = catchThrowable(() -> {
Location.at(string);
});
assertThat(thrown).isNotNull().isInstanceOf(IllegalArgumentException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public static Stream<Fixture> fixtures() {
Fixture.of(Status.VALID, "-s", "empty.schema.json", "-r", "true.schema.json"),
Fixture.of(Status.VALID, "-s", "empty.schema.json", "-r", "false.schema.json"),
Fixture.of(Status.VALID, "-s", "empty.schema.json", "-r", "invalid-id.schema.json"),
Fixture.of(Status.VALID, "-s", "company.schema.json", "-r", "person.schema.json", "geographical-location.schema.json"),
Fixture.of(Status.VALID, "-s", "company.schema.json", "-r", "person.schema.json",
"geographical-location.schema.json"),
Fixture.of(Status.VALID, "-s", "company.schema.json", "-catalog", "catalog.json"),
Fixture.of(Status.FAILED, "-s", "company.schema.json", "-catalog", "nonexistent.json"),
Fixture.of(Status.FAILED, "-s", "company.schema.json", "-catalog", "malformed.json"),
Expand All @@ -71,7 +72,8 @@ public static Stream<Fixture> fixtures() {
Fixture.of(Status.VALID, "-s", "arrays.schema.json", "-i", "arrays.json"),
Fixture.of(Status.INVALID, "-s", "arrays.schema.json", "-i", "arrays-invalid.json"),
Fixture.of(Status.VALID, "-s", "geographical-location.schema.json", "-i", "geographical-location.json"),
Fixture.of(Status.INVALID, "-s", "geographical-location.schema.json", "-i", "geographical-location-invalid.json"),
Fixture.of(Status.INVALID, "-s", "geographical-location.schema.json", "-i",
"geographical-location-invalid.json"),
Fixture.of(Status.VALID, "-s", "person.schema.json", "-i", "person.json"),
Fixture.of(Status.INVALID, "-s", "person.schema.json", "-i", "person-invalid.json"),
Fixture.of(Status.INVALID, "-s", "person.schema.json", "-i", "person-malformed.json"),
Expand All @@ -80,13 +82,17 @@ public static Stream<Fixture> fixtures() {
Fixture.of(Status.INVALID, "-s", "person.schema.json", "-i", "person-invalid.json", "person.json"),

// Validates an instance against a schema with referenced schemas.
Fixture.of(Status.VALID, "-s", "product.schema.json", "-r", "geographical-location.schema.json", "-i", "product.json"),
Fixture.of(Status.INVALID, "-s", "product.schema.json", "-r", "geographical-location.schema.json", "-i", "product-invalid.json"),
Fixture.of(Status.INVALID, "-s", "product.schema.json", "-r", "geographical-location.schema.json", "-i", "product-invalid.json", "product.json"),
Fixture.of(Status.VALID, "-s", "product.schema.json", "-r", "geographical-location.schema.json", "-i",
"product.json"),
Fixture.of(Status.INVALID, "-s", "product.schema.json", "-r", "geographical-location.schema.json", "-i",
"product-invalid.json"),
Fixture.of(Status.INVALID, "-s", "product.schema.json", "-r", "geographical-location.schema.json", "-i",
"product-invalid.json", "product.json"),
Fixture.of(Status.VALID, "-s", "company.schema.json", "-catalog", "catalog.json", "-i", "company.json"),
Fixture.of(Status.INVALID, "-s", "company.schema.json", "-catalog", "catalog.json", "-i", "company-invalid.json"),
Fixture.of(Status.INVALID, "-s", "company.schema.json", "-catalog", "catalog.json", "-i", "company-invalid.json", "company.json")
);
Fixture.of(Status.INVALID, "-s", "company.schema.json", "-catalog", "catalog.json", "-i",
"company-invalid.json"),
Fixture.of(Status.INVALID, "-s", "company.schema.json", "-catalog", "catalog.json", "-i",
"company-invalid.json", "company.json"));
}

private static int index = 1;
Expand Down
Loading

0 comments on commit ac4dcc1

Please sign in to comment.