Skip to main content

A tool to analyze code and provide formatting improvement suggestions

Project description

Code-Formatter-Advisor

Code-Formatter-Advisor is a command-line tool that leverages GroqCloud API to analyze code and provide formatting improvement suggestions. It offers a streamlined interface for specifying input files, customizing outputs, and enhancing code readability and consistency. The tool supports multiple programming languages and integrates seamlessly into your workflow by delivering suggestions directly in the terminal or saving them to a file.

📜Description

  • Provides code formatting suggestions based on best practices.
  • Supports multiple programming languages.
  • Easy-to-use command-line interface.
  • Ability to output suggestions to a file or display them in the terminal.

⚙️Installation

  1. Clone the repository:

    git clone https://github.com/Elisassa/Code-Formatter-Advisor.git
    cd Code-Formatter-Advisor
    
  2. Create a virtual environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate # On Windows use `venv\Scripts\activate`
    
  3. Install the required dependencies:

    pip install -r requirements.txt
    

📝Usage

Command-Line Arguments

  • --output or -o: Specify the output file name for the suggestions.
  • --version or -v: Display the version of the tool.
  • files: The code files to be analyzed (one or more).

Example Commands

  1. Analyze a single file and display suggestions in the terminal:

    python main.py test.py
    
  2. Analyze multiple files and save suggestions to an output file:

    python main.py test1.py test2.py --output suggestions.txt
    
  3. Check the version of the tool:

    python main.py --version
    

🔍Demonstration

The Code-Formatter-Advisor analyzes your code and provides actionable formatting suggestions to improve readability and consistency. Below is a demonstration of how the tool works:

Original Unformatted Code:

Below is an example of code before using Code-Formatter-Advisor. Notice the issues such as inconsistent indentation, missing type hints, and lack of descriptive comments.

image

Suggested Improvements by Code-Formatter-Advisor:

After running the code through Code-Formatter-Advisor, the tool suggests various improvements such as:

  • Consistent Indentation: Standardizes indentation to 4 spaces for better readability.
  • Removal of Extra Spaces: Removes unnecessary spaces around function arguments, colons, and assignment operators.
  • Descriptive Function Names: Renames functions to be more descriptive, like changing add_numbers to sum_numbers.
  • Addition of Docstrings: Adds docstrings to describe the purpose and usage of functions, making the code self-documenting.
  • Type Hints: Adds type hints to function arguments and return values to clarify the expected input and output.

Formatted Code Suggestions

🛠️How Code-Formatter-Advisor Was Created

Project Setup

  1. Initialization: The project was initialized by setting up a basic Python environment using venv to manage dependencies.

  2. Dependencies: Required libraries were defined and installed via a requirements.txt file, including argparse for command-line argument parsing, dotenv for environment variable management, and others for formatting analysis.

  3. Development:

    • The main logic is implemented in main.py, which handles reading files, interacting with the code formatting API, and processing user inputs.
    • argparse is used to handle command-line arguments, allowing users to specify files, output locations, and other options.
    • A custom API client (Groq) was integrated to analyze code and provide formatting suggestions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_formatter_advisor-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

code_formatter_advisor-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file code_formatter_advisor-0.1.0.tar.gz.

File metadata

File hashes

Hashes for code_formatter_advisor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7e315a4d467f0ad614b5b9c34ebfefb091d0d6c0cf2fad361828566a806e8b74
MD5 e455c9af02431afccb749714c00a573f
BLAKE2b-256 2cb91dacab6c0b9f14fb131f03d12dac6a06e4d2688542f3e3057bc4e4ba4cb0

See more details on using hashes here.

File details

Details for the file code_formatter_advisor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for code_formatter_advisor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f0654f642b7733ce8883d955616d2c2ccff1ad9af7b8fbdd93db777d26508c0
MD5 08eac43eef07f1cb7e4eaf6dc80b29b0
BLAKE2b-256 e463432039460c74e44da514664f3a8a1cf90569fb40cc309814bc8fe2853b02

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page