GithubHelp home page GithubHelp logo

pralinkhaira / ai-driven-code-formatter Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 7 KB

An AI-Driven Code Formatter is a powerful tool that leverages artificial intelligence and machine learning techniques to automatically format and optimize code written in various programming languages.

License: MIT License

Python 100.00%

ai-driven-code-formatter's Introduction

AI-Driven Code Formatter

The AI-Driven Code Formatter is a tool that utilizes artificial intelligence and machine learning techniques to automatically format and optimize code written in various programming languages. It aims to improve code readability, maintainability, and adherence to coding style guidelines without requiring manual intervention from developers.

Installation

  1. Install the Black library by running the following command:
    pip install black

Usage

To use the AI-Driven Code Formatter, follow these steps:

  1. Open the Python file you want to format.

  2. Import the Black library in your Python script:

    import black
  3. Define the format_code function that takes a file path as input, formats the code using Black, and writes the formatted code back to the file. Here's an example:

    def format_code(file_path):
        with open(file_path, "r") as file:
            code = file.read()
    
        formatted_code = black.format_file_contents(
            code,
            fast=True,
            mode=black.FileMode(),
        )
    
        with open(file_path, "w") as file:
            file.write(formatted_code)
  4. In the main block, specify the path to the Python file you want to format:

    if __name__ == "__main__":
        python_file_path = "path/to/your/file.py"
        format_code(python_file_path)
  5. Save the script, and then run it. It will format the specified Python file using Black's formatting rules.

Feel free to customize the code according to your specific needs and project requirements.

Update History

Update V1.1 - 17-07-2023:

  • Added error handling for cases where the code is already well-formatted using black.NothingChanged exception.
  • Implemented command-line argument parsing using argparse module for better user interaction.
  • Introduced a separate main function to encapsulate the main execution logic, improving code organization and reusability.

Contributing

Contributions to the AI-Driven Code Formatter project are welcome! If you would like to contribute, please follow the guidelines in CONTRIBUTING.md.

License

This project is licensed under the MIT License.

ai-driven-code-formatter's People

Contributors

pralinkhaira avatar

Stargazers

 avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.