{"id":22895500,"url":"https://github.com/kgruiz/autoformatters","last_synced_at":"2026-05-01T15:31:47.162Z","repository":{"id":263201178,"uuid":"889662150","full_name":"kgruiz/AutoFormatters","owner":"kgruiz","description":"A collection of tools and scripts for automated formatting and cleaning of C++ and Python code.","archived":false,"fork":false,"pushed_at":"2025-08-27T02:39:29.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-27T11:03:26.712Z","etag":null,"topics":["automation","clang-format","code-cleaning","code-formatter","cpp","python","vscode"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kgruiz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-16T22:24:11.000Z","updated_at":"2025-08-27T02:39:33.000Z","dependencies_parsed_at":"2024-12-13T23:30:09.158Z","dependency_job_id":"9eb82232-950e-4098-8612-eb4ad8934975","html_url":"https://github.com/kgruiz/AutoFormatters","commit_stats":null,"previous_names":["kgruiz/autoformatters"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kgruiz/AutoFormatters","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FAutoFormatters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FAutoFormatters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FAutoFormatters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FAutoFormatters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kgruiz","download_url":"https://codeload.github.com/kgruiz/AutoFormatters/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FAutoFormatters/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32502985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","clang-format","code-cleaning","code-formatter","cpp","python","vscode"],"created_at":"2024-12-13T23:29:55.596Z","updated_at":"2026-05-01T15:31:47.144Z","avatar_url":"https://github.com/kgruiz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Code Formatter \u0026 Cleaner Collection\n\nThis is a collection of Python scripts and configuration files designed to help you maintain clean, well-formatted C++ and Python codebases. This collection automates the process of formatting code according to best practices, along with some personal adjustments, ensuring consistency and readability across your projects.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [CppSpaceLines.py](#cppspacelinespy)\n  - [PythonSpaceLines.py](#pythonspacelinespy)\n  - [RemoveCompilerDEBUG.py](#removecompilerdebugpy)\n  - [.clang-format](#clang-format)\n- [Configuration](#configuration)\n- [Logging](#logging)\n- [Integration with VSCode](#integration-with-vscode)\n  - [1. Install Extensions](#1-install-extensions)\n  - [2. Configure `settings.json`](#2-configure-settingsjson)\n  - [3. Set Up Keybindings](#3-set-up-keybindings)\n  - [4. Specify the Python Interpreter Path (Optional)](#4-specify-the-python-interpreter-path-optional)\n- [Warning](#warning)\n\n## Features\n\n- **C++ Code Formatting:** Automatically adds appropriate newlines after classes, structs, namespaces, functions, and control flow statements to enhance readability.\n- **Python Code Formatting:** Ensures proper spacing after class and function declarations, docstrings, and control flow keywords.\n- **Debug Code Removal:** Removes all code sections wrapped within `#ifdef DEBUG` and `#endif` directives in C++ files.\n- **Debug Code Insertion:** Quickly inserts `#ifdef DEBUG` and `#endif` preprocessor directives to wrap debug-specific code blocks in C++ files.\n- **Custom Clang-Format Configuration:** Provides a `.clang-format` file tailored to enforce specific coding styles based on the Google C++ style guide with custom adjustments.\n\n## Installation\n\n1. **Clone the Repository**\n\n   ```bash\n   git clone https://github.com/yourusername/code-formatter-cleaner-collection.git\n   cd code-formatter-cleaner-collection\n   ```\n\n2. **Set Up a Virtual Environment (Optional but Recommended)**\n\n   ```bash\n   python -m venv venv\n   source venv/bin/activate  # On Windows: venv\\Scripts\\activate\n   ```\n\n3. **Install Dependencies**\n\n   The scripts rely on Python's standard library, so no additional packages are required.\n\n## Usage\n\nEach script is designed to be run from the command line, taking the target file path as an argument.\n\n### CppSpaceLines.py\n\n**Description:** Formats C++ source files by adding newlines after specific code constructs such as classes, structs, namespaces, functions, and control flow statements.\n\n**Usage:**\n\n```bash\npython CppSpaceLines.py \u003cfilePath\u003e\n```\n\n**Example:**\n\n```bash\npython CppSpaceLines.py src/main.cpp\n```\n\n### PythonSpaceLines.py\n\n**Description:** Formats Python source files by adding newlines after class and function declarations, docstrings, and control flow keywords to improve code readability.\n\n**Usage:**\n\n```bash\npython PythonSpaceLines.py \u003cfilePath\u003e\n```\n\n**Example:**\n\n```bash\npython PythonSpaceLines.py scripts/utils.py\n```\n\n### RemoveCompilerDEBUG.py\n\n**Description:** Removes all sections of C++ code enclosed within `#ifdef DEBUG` and `#endif` directives, including the content within these blocks.\n\n**Usage:**\n\n```bash\npython RemoveCompilerDEBUG.py \u003cfilePath\u003e\n```\n\n**Example:**\n\n```bash\npython RemoveCompilerDEBUG.py src/debug.cpp\n```\n\n### .clang-format\n\n**Description:** A configuration file for `clang-format` to enforce a consistent C++ coding style based on the Google style guide with customized settings.\n\n**Summary:** The `.clang-format` file sets indentation, line length, brace style, and other formatting rules to maintain code consistency.\n\n**Usage:**\n\n1. **Install clang-format**\n\n   ```bash\n   # On macOS\n   brew install clang-format\n\n   # On Ubuntu\n   sudo apt-get install clang-format\n\n   # On Windows\n   choco install clang-format\n   ```\n\n2. **Format Your C++ Files**\n\n   ```bash\n   clang-format -i \u003cfilePath\u003e\n   ```\n\n   **Example:**\n\n   ```bash\n   clang-format -i src/main.cpp\n   ```\n\n   The provided `.clang-format` file will be automatically detected and applied.\n\n## Configuration\n\nThe `.clang-format` file included in this repository is pre-configured with settings based on the Google C++ style guide, including custom adjustments for indentation, line length, brace placement, and more. Feel free to customize this file to better suit your project's coding standards.\n\n## Logging\n\nAll scripts are equipped with logging functionality to provide detailed information about the formatting process. Logs include:\n\n- **Debug Messages:** Information about which patterns are being applied and the lines affected.\n- **Error Messages:** Alerts when the specified file is not found or incorrect usage is detected.\n- **Info Messages:** Confirmation upon successful formatting.\n\nLogs are output to the console. You can adjust the logging level by modifying the `logging.basicConfig` level in each script.\n\n## Integration with VSCode\n\nIntegrate the **Code Formatter \u0026 Cleaner Collection** with Visual Studio Code (VSCode) to automate code formatting and cleaning.\n\n### 1. Install Extensions\n\n- **Run on Save** by emeraldwalk:\n  - Open VSCode.\n  - Go to the Extensions Marketplace (`Ctrl+Shift+X` or `Cmd+Shift+X`).\n  - Search for \"Run on Save\" by emeraldwalk and install it.\n\n- **Clang-Format** by Xaver Hellauer:\n  - Search for \"Clang-Format\" by Xaver Hellauer and install it.\n\n- **Black Formatter** for Python:\n  - Install the **Black** extension by searching \"Black Formatter\" in the Extensions Marketplace.\n\n- **Multi Command** by ryuta46:\n  - Install the **multi-command** extension to allow defining and executing multiple commands via a single keybinding.\n\n### 2. Configure `settings.json`\n\nOpen your `settings.json` in VSCode and add the following configurations:\n\n```yaml\n{\n    # Set Clang-Format as the default formatter for C++\n    \"editor.defaultFormatter\": \"xaver.clang-format\",\n    \"clang-format.style\": \"file:/path/to/.clang-format\",\n\n    # Configure Run on Save for Python and C++ scripts\n    \"emeraldwalk.runonsave\": {\n        \"commands\": [\n            {\n                \"match\": \"\\\\.(cpp|h|hpp)$\",\n                \"isAsync\": true,\n                \"cmd\": \"python /path/to/CppSpaceLines.py ${file}\"\n            },\n            {\n                \"match\": \"\\\\.py$\",\n                \"isAsync\": true,\n                \"cmd\": \"python /path/to/PythonSpaceLines.py ${file}\"\n            },\n            {\n                \"match\": \"\\\\.(cpp|h|hpp)$\",\n                \"isAsync\": true,\n                \"cmd\": \"python /path/to/RemoveCompilerDEBUG.py ${file}\"\n            }\n        ]\n    },\n\n    # Enable Black formatter for Python\n    \"python.formatting.provider\": \"black\",\n    \"editor.formatOnSave\": true,\n\n    # Configure multiCommand sequences\n    \"multiCommand.commands\": [\n        {\n            \"command\": \"multiCommand.RemoveAllCompilerDEBUG\",\n            \"sequence\": [\n                {\n                    \"command\": \"command-runner.run\",\n                    \"args\": {\n                        \"command\": \"clear \u0026\u0026 /Users/kadengruizenga/anaconda3/envs/basic/bin/python -u /opt/homebrew/Cellar/clang-format/19.1.1/RemoveCompilerDEBUG.py \\\"${file}\\\"\"\n                    }\n                }\n            ]\n        },\n        {\n            \"command\": \"multiCommand.CPPifdefDEBUG\",\n            \"sequence\": [\n                \"editor.action.insertLineAfter\",\n                {\n                    \"command\": \"type\",\n                    \"args\": {\n                        \"text\": \"\\n#ifdef DEBUG\\n#endif\"\n                    }\n                },\n                \"cursorUp\",\n                \"cursorEnd\",\n                \"editor.action.insertLineAfter\"\n            ]\n        }\n    ]\n}\n```\n\n**Note:** Replace `/path/to/` with the actual paths to your scripts and ensure the Python interpreter path is correct.\n\n### 3. Set Up Keybindings\n\nTo streamline the usage of your scripts, set up custom keybindings in VSCode.\n\n1. **Open `keybindings.json`:**\n\n   - Press `Ctrl+Shift+P` (or `Cmd+Shift+P` on macOS) to open the Command Palette.\n   - Type `Preferences: Open Keyboard Shortcuts (JSON)` and select it.\n\n2. **Add the Following Keybindings:**\n\n   ```yaml\n   [\n       {\n           \"key\": \"alt+shift+d\",\n           \"command\": \"extension.multiCommand.execute\",\n           \"args\": { \"command\": \"multiCommand.RemoveAllCompilerDEBUG\" },\n           \"when\": \"(resourceExtname == .hpp || resourceExtname == .h || resourceExtname == .cpp) \u0026\u0026 editorTextFocus\"\n       },\n       {\n           \"key\": \"alt+shift+i\",\n           \"command\": \"extension.multiCommand.execute\",\n           \"args\": { \"command\": \"multiCommand.CPPifdefDEBUG\" },\n           \"when\": \"(resourceExtname == .hpp || resourceExtname == .h || resourceExtname == .cpp) \u0026\u0026 editorTextFocus\"\n       }\n   ]\n   ```\n\n   - **`Alt+Shift+D`:** Executes the `RemoveAllCompilerDEBUG` command, which runs the `RemoveCompilerDEBUG.py` script on the current C++ file to remove debug sections.\n   - **`Alt+Shift+I`:** Executes the `CPPifdefDEBUG` command, which inserts `#ifdef DEBUG` and `#endif` preprocessor directives into the current C++ file to wrap debug-specific code blocks.\n\n### 4. Specify the Python Interpreter Path (Optional)\n\nIf your Python interpreter or virtual environment is located outside the workspace folder, update the `cmd` field with the absolute path to the Python executable.\n\n**Example for a Virtual Environment:**\n\n```ymal\n{\n    \"emeraldwalk.runonsave\": {\n        \"commands\": [\n            {\n                \"match\": \"\\\\.(cpp|h|hpp)$\",\n                \"isAsync\": true,\n                \"cmd\": \"/absolute/path/to/venv/bin/python /absolute/path/to/CppSpaceLines.py ${file}\" # macOS/Linux\n                # \"cmd\": \"C:\\\\absolute\\\\path\\\\to\\\\venv\\\\Scripts\\\\python.exe C:\\\\absolute\\\\path\\\\to\\\\CppSpaceLines.py ${file}\" # Windows\n            }\n        ]\n    }\n}\n```\n\n\u003e **Tips:**\n\u003e\n\u003e - **Windows Paths:** Use double backslashes (`\\\\`) or forward slashes (`/`).\n\u003e - **macOS/Linux Paths:** Use forward slashes (`/`).\n\u003e - **Environment Variables:** If Python is added to your system's PATH, you can use `python` instead of the full path.\n\n## Warning\n\n**Use caution when using Python scripts to modify file formatting.** There is a risk of glitches or crashes that may result in lost or corrupted code. Always ensure you have backups or version control in place before enabling automated formatting.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgruiz%2Fautoformatters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkgruiz%2Fautoformatters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgruiz%2Fautoformatters/lists"}