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.
- 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.
You can install Code-Formatter-Advisor directly from PyPI using pip:
pip install code-formatter-advisor
-
Clone the repository:
git clone https://github.com/Elisassa/Code-Formatter-Advisor.git cd Code-Formatter-Advisor
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
--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).
-
Analyze a single file and display suggestions in the terminal:
code-formatter-advisor test.py
-
Analyze multiple files and save suggestions to an output file:
code-formatter-advisor test1.py test2.py --output suggestions.txt
-
Check the version of the tool:
code-formatter-advisor --version
If you installed Code-Formatter-Advisor using pip, you can simply run the following commands from anywhere:
-
Analyze a single file and display suggestions in the terminal:
code-formatter-advisor test.py
-
Analyze multiple files and save suggestions to an output file:
code-formatter-advisor test1.py test2.py --output suggestions.txt
-
Check the version of the tool:
code-formatter-advisor --version
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:
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.
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
tosum_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.
-
Initialization: The project was initialized by setting up a basic Python environment using
venv
to manage dependencies. -
Dependencies: Required libraries were defined and installed via a
requirements.txt
file, includingargparse
for command-line argument parsing,dotenv
for environment variable management, and others for formatting analysis. -
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.
- The main logic is implemented in
The package is available on PyPI and can be installed via:
pip install code-formatter-advisor
To view the source code, report issues, or contribute to the project, please visit the GitHub repository: Code-Formatter-Advisor on GitHub
The current version is v1.0.0
. The versioning follows Semantic Versioning, and any new features, bug fixes, or changes will be released accordingly.
- Install the Package: Users can install the package from PyPI using pip.
- Run the Command: Use the
code-formatter-advisor
command followed by the file(s) you want to analyze. - Follow the Suggestions: The tool provides suggestions to improve code formatting, which can be seen in the terminal or saved to a file.
User testing was conducted to ensure that the installation process and usage instructions were straightforward. Feedback from testers helped refine the README and the overall user experience. If you encounter any issues, feel free to create an issue on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.