From cc22ed642b34f15798facec1bddd597aa8c0c395 Mon Sep 17 00:00:00 2001 From: Eugene Peh Date: Mon, 22 May 2017 08:33:43 +0800 Subject: [PATCH] [#319] Checkstyle: enforce operators' placement in line wraps (#382) Our coding standard for Java requires operators' placement in line wraps to follow specific rules, such as having assignment operator (=) stay attached to the token that precedes it and having the arithmetric operator (+) in a new line. These rules are not enforced by checkstyle. Let's teach Checkstyle to be stricter about line wrapping around more symbols by adding the relevant OperatorWrap rules. --- build.gradle | 2 +- config/checkstyle/checkstyle.xml | 22 +++++++++++++++++++ src/main/java/seedu/address/MainApp.java | 8 +++---- .../seedu/address/commons/core/Version.java | 21 +++++++++++++----- .../guihandles/PersonListPanelHandle.java | 4 ++-- .../address/commons/core/ConfigTest.java | 6 ++--- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 14f96e93858..6b6f4b32974 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ allprojects { junitVersion = '4.12' testFxVersion = '4.0.5-alpha' monocleVersion = '1.8.0_20' - checkstyleVersion = '7.1.2' + checkstyleVersion = '7.2' libDir = 'lib' } diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 3d7f86bd4db..13fc915fcfd 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -322,6 +322,28 @@ + + + + + + + + + + + diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 9b9f55288de..12812b6ec88 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -121,8 +121,8 @@ protected Config initConfig(String configFilePath) { Optional configOptional = ConfigUtil.readConfig(configFilePathUsed); initializedConfig = configOptional.orElse(new Config()); } catch (DataConversionException e) { - logger.warning("Config file at " + configFilePathUsed + " is not in the correct format. " + - "Using default config properties"); + logger.warning("Config file at " + configFilePathUsed + " is not in the correct format. " + + "Using default config properties"); initializedConfig = new Config(); } @@ -144,8 +144,8 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) { Optional prefsOptional = storage.readUserPrefs(); initializedPrefs = prefsOptional.orElse(new UserPrefs()); } catch (DataConversionException e) { - logger.warning("UserPrefs file at " + prefsFilePath + " is not in the correct format. " + - "Using default user prefs"); + logger.warning("UserPrefs file at " + prefsFilePath + " is not in the correct format. " + + "Using default user prefs"); initializedPrefs = new UserPrefs(); } catch (IOException e) { logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook"); diff --git a/src/main/java/seedu/address/commons/core/Version.java b/src/main/java/seedu/address/commons/core/Version.java index 9023b29ae3d..e8fe0d3e629 100644 --- a/src/main/java/seedu/address/commons/core/Version.java +++ b/src/main/java/seedu/address/commons/core/Version.java @@ -71,11 +71,22 @@ public String toString() { @Override public int compareTo(Version other) { - return this.major != other.major ? this.major - other.major : - this.minor != other.minor ? this.minor - other.minor : - this.patch != other.patch ? this.patch - other.patch : - this.isEarlyAccess == other.isEarlyAccess() ? 0 : - this.isEarlyAccess ? -1 : 1; + if (this.major != other.major) { + return this.major - other.major; + } + if (this.minor != other.minor) { + return this.minor - other.minor; + } + if (this.patch != other.patch) { + return this.patch - other.patch; + } + if (this.isEarlyAccess == other.isEarlyAccess()) { + return 0; + } + if (this.isEarlyAccess) { + return -1; + } + return 1; } @Override diff --git a/src/test/java/guitests/guihandles/PersonListPanelHandle.java b/src/test/java/guitests/guihandles/PersonListPanelHandle.java index 66a76d8d3c5..a9370bfd25b 100644 --- a/src/test/java/guitests/guihandles/PersonListPanelHandle.java +++ b/src/test/java/guitests/guihandles/PersonListPanelHandle.java @@ -55,8 +55,8 @@ public boolean isListMatching(ReadOnlyPerson... persons) { */ public boolean isListMatching(int startPosition, ReadOnlyPerson... persons) throws IllegalArgumentException { if (persons.length + startPosition != getListView().getItems().size()) { - throw new IllegalArgumentException("List size mismatched\n" + - "Expected " + (getListView().getItems().size() - 1) + " persons"); + throw new IllegalArgumentException("List size mismatched\n" + + "Expected " + (getListView().getItems().size() - 1) + " persons"); } assertTrue(this.containsInOrder(startPosition, persons)); for (int i = 0; i < persons.length; i++) { diff --git a/src/test/java/seedu/address/commons/core/ConfigTest.java b/src/test/java/seedu/address/commons/core/ConfigTest.java index aeb07c4f3a4..cc4bf567cb4 100644 --- a/src/test/java/seedu/address/commons/core/ConfigTest.java +++ b/src/test/java/seedu/address/commons/core/ConfigTest.java @@ -14,9 +14,9 @@ public class ConfigTest { @Test public void toString_defaultObject_stringReturned() { - String defaultConfigAsString = "App title : Address App\n" + - "Current log level : INFO\n" + - "Preference file Location : preferences.json"; + String defaultConfigAsString = "App title : Address App\n" + + "Current log level : INFO\n" + + "Preference file Location : preferences.json"; assertEquals(defaultConfigAsString, new Config().toString()); }