-
Notifications
You must be signed in to change notification settings - Fork 0
Description
@darrentde We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues 👍
Aspect: Naming boolean variables/methods
No easy-to-detect issues 👍
Aspect: Brace Style
No easy-to-detect issues 👍
Aspect: Package Name Style
No easy-to-detect issues 👍
Aspect: Class Name Style
No easy-to-detect issues 👍
Aspect: Dead Code
Example from src/main/java/chad/Parser.java lines 64-64:
// throw new ChadException("I'm sorry, but I don't know what that means :-(");Example from src/main/java/chad/TaskList.java lines 81-81:
// if (dateTime.isEmpty()) {Example from src/main/java/chad/TaskList.java lines 82-82:
// throw new ChadException("The date of a deadline cannot be empty.");Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/chad/Storage.java lines 27-85:
public static ArrayList<Task> initializeArrayList() throws ChadException {
ArrayList<Task> taskList = new ArrayList<>();
try {
File currentFile = new File("./data/chad_data.txt");
if (currentFile.createNewFile()) {
System.out.println("Created new file");
}
BufferedReader reader = new BufferedReader(new FileReader(currentFile));
String line = reader.readLine();
while (line != null) {
String[] tempArr = line.split("\\|");
String taskType = tempArr[0].trim();
String strIsMark = tempArr[1].trim();
String desc = tempArr[2].trim();
switch (taskType) {
case "D": {
String byDateString = tempArr[3].trim();
LocalDateTime dateTime = LocalDateTime.parse(byDateString);
Task t = new Deadline(desc, dateTime);
if (strIsMark.equals("1")) {
t.markAsDone();
}
taskList.add(t);
break;
}
case "E": {
String byDateTime = tempArr[3].trim();
LocalDateTime dateTime = LocalDateTime.parse(byDateTime);
Task t = new Event(desc, dateTime);
if (strIsMark.equals("1")) {
t.markAsDone();
}
taskList.add(t);
break;
}
case "T": {
Task t = new Todo(desc);
if (strIsMark.equals("1")) {
t.markAsDone();
}
taskList.add(t);
break;
}
default:
System.out.println("Failed to add task " + line);
break;
}
line = reader.readLine();
}
reader.close();
} catch (Exception e) {
throw new ChadException(e.getMessage());
}
return taskList;
}Example from src/main/java/chad/Storage.java lines 142-183:
public static void toggleMarkTaskInFile(int index) throws ChadException {
try {
File tempFile = new File("tempFile.txt");
File currentFile = new File("./data/chad_data.txt");
tempFile.deleteOnExit();
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
BufferedReader reader = new BufferedReader(new FileReader(currentFile));
String currentLine;
int currentIndex = 0;
while ((currentLine = reader.readLine()) != null) {
if (currentIndex != index) {
writer.write(currentLine);
writer.newLine();
} else {
String[] tempArr = currentLine.split("\\|");
String markIndex = tempArr[1].trim();
markIndex = markIndex.equals("0") ? "1" : "0";
tempArr[1] = markIndex;
StringBuilder line = new StringBuilder();
for (int i = 0; i < tempArr.length; i++) {
line.append(tempArr[i].trim());
if (i != tempArr.length - 1) {
line.append(" | ");
}
}
writer.write(line.toString().trim());
writer.newLine();
}
currentIndex += 1;
}
writer.close();
reader.close();
currentFile.delete();
tempFile.renameTo(currentFile);
} catch (Exception e) {
throw new ChadException(e.getMessage());
}
}Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues 👍
Aspect: Header Comments
Example from src/main/java/chad/Chad.java lines 26-30:
/**
* Main Function of Chad
* @throws IOException Thrown when helper file cannot be open
* @throws ChadException Thrown when invalid error occurs
*/Example from src/main/java/chad/Storage.java lines 104-108:
/**
* Delete task in text file
* @param index index of text to be deleted
* @throws IOException Thrown when file cannot be opened
*/Example from src/main/java/chad/TaskList.java lines 37-43:
/**
* Add todo task into task list
* @param tasks arraylist of tasks
* @param userInput todo task added by user
* @throws ChadException Thrown if description is invalid
* @throws IOException Thrown when file cannot be opened in IOException
*/Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues 👍
Aspect: Binary files in repo
No easy-to-detect issues 👍
ℹ️ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact cs2103@comp.nus.edu.sg if you want to follow up on this post.