Skip to content

Commit

Permalink
[se-edu#319] Checkstyle: enforce one variable declaration per line (s…
Browse files Browse the repository at this point in the history
…e-edu#671)

Having several variables are on the same line risk having conflicts
for unrelated modifications by different developers.

This rule checks for multiple variable declarations on single lines
such as these,

int a; int b;
int a, b;

while still allow multiple variable declarations on single statements
such as these,

int a,
     b;

Let's teach Checkstyle to enforce the rule
MultipleVariableDeclarations to check that there are no multiple
variable declarations on single lines.
  • Loading branch information
eugenepeh authored and Zhiyuan-Amos committed Sep 21, 2017
1 parent 1b9b5c3 commit 56949f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
3 changes: 3 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@
<property name="allowEmptyLoopBody" value="true"/>
</module>

<!-- Checks that each variable declaration is in its own statement and on its own line. -->
<module name="MultipleVariableDeclarations"/>

<module name="OneStatementPerLine"/>

<module name="UpperEll">
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/commons/core/VersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void versionToString_validVersion_correctStringRepresentation() {

@Test
public void versionComparable_validVersion_compareToIsCorrect() {
Version one, another;
Version one;
Version another;

// Tests equality
one = new Version(0, 0, 0, true);
Expand Down
61 changes: 30 additions & 31 deletions src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,39 @@
*/
public class TypicalPersons {

public static final ReadOnlyPerson ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE, HOON, IDA, AMY, BOB;
public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER
public static final ReadOnlyPerson ALICE = new PersonBuilder().withName("Alice Pauline")
.withAddress("123, Jurong West Ave 6, #08-111").withEmail("[email protected]")
.withPhone("85355255")
.withTags("friends").build();
public static final ReadOnlyPerson BENSON = new PersonBuilder().withName("Benson Meier")
.withAddress("311, Clementi Ave 2, #02-25")
.withEmail("[email protected]").withPhone("98765432")
.withTags("owesMoney", "friends").build();
public static final ReadOnlyPerson CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563")
.withEmail("[email protected]").withAddress("wall street").build();
public static final ReadOnlyPerson DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533")
.withEmail("[email protected]").withAddress("10th street").build();
public static final ReadOnlyPerson ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224")
.withEmail("[email protected]").withAddress("michegan ave").build();
public static final ReadOnlyPerson FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427")
.withEmail("[email protected]").withAddress("little tokyo").build();
public static final ReadOnlyPerson GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442")
.withEmail("[email protected]").withAddress("4th street").build();

static {
ALICE = new PersonBuilder().withName("Alice Pauline")
.withAddress("123, Jurong West Ave 6, #08-111").withEmail("[email protected]")
.withPhone("85355255")
.withTags("friends").build();
BENSON = new PersonBuilder().withName("Benson Meier").withAddress("311, Clementi Ave 2, #02-25")
.withEmail("[email protected]").withPhone("98765432")
.withTags("owesMoney", "friends").build();
CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563")
.withEmail("[email protected]").withAddress("wall street").build();
DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533")
.withEmail("[email protected]").withAddress("10th street").build();
ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224")
.withEmail("[email protected]").withAddress("michegan ave").build();
FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427")
.withEmail("[email protected]").withAddress("little tokyo").build();
GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442")
.withEmail("[email protected]").withAddress("4th street").build();
// Manually added
public static final ReadOnlyPerson HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424")
.withEmail("[email protected]").withAddress("little india").build();
public static final ReadOnlyPerson IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131")
.withEmail("[email protected]").withAddress("chicago ave").build();

// Manually added
HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424")
.withEmail("[email protected]").withAddress("little india").build();
IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131")
.withEmail("[email protected]").withAddress("chicago ave").build();
// Manually added - Person's details found in {@code CommandTestUtil}
public static final ReadOnlyPerson AMY = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY)
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build();
public static final ReadOnlyPerson BOB = new PersonBuilder().withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND)
.build();

// Manually added - Person's details found in {@code CommandTestUtil}
AMY = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY)
.withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build();
BOB = new PersonBuilder().withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB)
.withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
}
public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER

private TypicalPersons() {} // prevents instantiation

Expand Down

0 comments on commit 56949f2

Please sign in to comment.