Skip to main content

Automated Code Refactoring & Error Correction

1.1. Use Case Name

Automated Code Refactoring & Error Correction

1.2. Tags

Autofix

1.3. Introduction

Manual debugging and refactoring can be time-consuming and prone to human error. This use case empowers developers to leverage CodeVista for automatically detecting logic redundancies, fixing common bugs (Null pointer, Data types), and ensuring the project adheres to specific coding conventions or linting rules (SonarQube, ESLint).

1.4. Outcome

  • Optimized Codebase: Automatically simplify complex if-else blocks and split oversized functions into smaller, manageable ones.
  • Rapid Bug Resolution: Instant suggestions to fix build errors, runtime logs, and validation bugs (null, max length).
  • Compliance: Ensure code consistency by fixing spelling mistakes in variables and following predefined coding conventions.

1.5. Starter Prompt

Analyze the following code block/error log and provide a fix. Optimize the logic for better readability and ensure it handles null exceptions and data type validation.

[Paste your code or error log here]

1.6. Inputs Required

  • Code Snippet/File: The block of code that needs optimization or fixing.
  • Error Logs: Compiler or runtime error messages (for build-fix scenarios).
  • Context: Specific instructions if you want to fix based on a particular rule (e.g., "Fix this based on SonarQube rules").

1.7. Prerequisites

  • Source code containing logic issues, linting errors, or build logs.
  • CodeVista extension installed.
  • (Optional) A coding convention file (e.g., .docx or .json) for convention-based fixing.

1.8. How to Use

  1. Identify Issue: Select a block of code with redundant logic or copy an error message from your terminal.
  2. Trigger Autofix: Use the CodeVista interface and select the Autofix scenario.
  3. Provide Context: If the fix relates to a specific convention (e.g., naming style), mention it in the chat.
  4. Review & Apply: Examine the proposed solution in the diff view and click Apply to update your source code.