Skip to content

Sharing iP code quality feedback [for @synh] #1

@soc-se-bot

Description

@soc-se-bot

@synh 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

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/sage/utils/Parser.java lines 20-145:

    public static void parse(TaskList taskList) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();

        while (!input.equals("bye")) {
            try {
                String[] parts = input.split(" ");
                CommandType commandType = CommandType.fromString(parts[0]);
                switch(commandType) {
                case LIST:
                    Ui.printTaskList(taskList);
                    break;
                case MARK:
                    if (parts.length == 2 && parts[1].matches("[0-9]+")) {
                        // Validate task number exists
                        int index = Integer.parseInt(parts[1]); // 1-based indexing
                        if (1 <= index && index <= taskList.getSize()) {
                            Task task = taskList.getTask(index - 1);
                            task.markAsDone();
                            Storage.saveTasks(taskList);
                            Ui.printMarkSuccess(task, index);
                        } else {
                            throw SageException.invalidTaskNumber();
                        }
                    } else {
                        throw SageException.invalidCommand("Mark");
                    }
                    break;
                case UNMARK:
                    if (parts.length == 2 && parts[1].matches("[0-9]+")) {
                        // Validate task number exists
                        int index = Integer.parseInt(parts[1]); // 1-based indexing
                        if (1 <= index && index <= taskList.getSize()) {
                            Task task = taskList.getTask(index - 1);
                            task.markAsUndone();
                            Storage.saveTasks(taskList);
                            Ui.printUnmarkSuccess(task, index);
                        } else {
                            throw SageException.invalidTaskNumber();
                        }
                    } else {
                        throw SageException.invalidCommand("Unmark");
                    }
                    break;
                case DELETE:
                    if (parts.length == 2 && parts[1].matches("[0-9]+")) {
                        // Validate task number exists
                        int index = Integer.parseInt(parts[1]); // 1-based indexing
                        if (1 <= index && index <= taskList.getSize()) {
                            Task task = taskList.getTask(index - 1);
                            taskList.deleteTask(index - 1);
                            Storage.saveTasks(taskList);
                            Ui.printDeleteSuccess(task, index, taskList);
                        } else {
                            throw SageException.invalidTaskNumber();
                        }
                    } else {
                        throw SageException.invalidCommand("Delete");
                    }
                    break;
                case TODO:
                    if (parts.length > 1) {
                        taskList.addTask(new ToDo(input.substring(5)));
                        Storage.saveTasks(taskList);
                        Ui.printAddedSuccess(taskList);
                    } else {
                        throw SageException.invalidCommand("ToDo");
                    }
                    break;
                case DEADLINE:
                    if (input.matches("^deadline\\s+(\\S.+?)\\s+/by\\s+(\\S.+)")) {
                        parts = input.split("/by");
                        if (parts.length == 2) {
                            String description = parts[0].replaceFirst("^deadline\\s+", "").trim(); // Remove "deadline" command
                            try {
                                LocalDate deadline = LocalDate.parse(parts[1].trim());
                                taskList.addTask(new Deadline(description, deadline));
                                Storage.saveTasks(taskList);
                                Ui.printAddedSuccess(taskList);
                            } catch (Exception e) {
                                throw SageException.invalidDate();
                            }
                        }
                    } else {
                        throw SageException.invalidCommand("Deadline");
                    }
                    break;
                case EVENT:
                    if (input.matches("^event\\s+(\\S.+?)\\s+/from\\s+(\\S.+?)\\s+/to\\s+(\\S.+)")) {
                        parts = input.split(" /from | /to ");
                        if (parts.length == 3) {
                            String description = parts[0].replaceFirst("^event\\s+", "").trim(); // Remove "event" command
                            try {
                                LocalDate from = LocalDate.parse(parts[1].trim());
                                LocalDate to = LocalDate.parse(parts[2].trim());
                                taskList.addTask(new Event(description, from, to));
                                Storage.saveTasks(taskList);
                                Ui.printAddedSuccess(taskList);
                            } catch (Exception e) {
                                throw SageException.invalidDate();
                            }
                        }
                    } else {
                        throw SageException.invalidCommand("Event");
                    }
                    break;
                case FIND:
                    if (parts.length == 2) {
                        TaskList foundList = taskList.findTask(parts[1].trim());
                        Ui.printFoundList(foundList);
                    } else {
                        throw SageException.invalidCommand("Find");
                    }
                    break;
                case UNKNOWN:
                    throw SageException.unknownCommand();
                }
            } catch (Exception e) { // Catch all exceptions
                System.out.print(e.getMessage());
            }

            System.out.println();
            input = scanner.nextLine();
        }
        scanner.close();
    }

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/sage/utils/Parser.java lines 17-19:

    /**
     * Main logic of chatbot that parses user input.
     */

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 Messages

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@nus.edu.sg if you want to follow up on this post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions