A tool to clean trailing whitespace from recently changed lines or an entire codebase.
Project description
TWSC: Trailing Whitespace Cleaner
TWSC (Trailing Whitespace Cleaner) is a Python package designed to clean up trailing whitespace in code files efficiently. It works for files in Git repositories, untracked files, or even entire codebases when not in a Git environment.
Features
-
Clean Tracked Changes:
- Cleans only the changed lines in tracked files since the last commit.
-
Handle Untracked Files:
- Cleans trailing whitespace from all untracked files in a Git repository.
-
Full Codebase Cleanup:
- Offers to clean trailing whitespace from all files in the codebase when not in a Git repository.
-
Supported Extensions:
- Python (
.py), JavaScript (.js), TypeScript (.ts), Java (.java), Go (.go), C (.c), C++ (.cpp), Ruby (.rb), Shell (.sh), Rust (.rs), HTML (.html), CSS (.css).
- Python (
Installation
Install TWSC using pip:
pip install twsc
Usage
Command-Line Interface
Run twsc from the root of your project directory:
twsc
Options
-
Force Full Cleanup: Use the
--force-clean-allflag to clean the entire codebase, even if it’s a Git repository:twsc --force-clean-all -
Version Information: Check the package version:
twsc --version
How It Works
In a Git Repository:
- Tracked Files:
- Identifies lines changed since the last commit and cleans up only those lines.
- Untracked Files:
- Cleans up all lines in untracked files.
Outside a Git Repository:
- Prompts the user to clean the entire codebase, targeting supported file types.
Example
Before Cleanup:
def example_function():
print("Hello, World!")
After Cleanup:
def example_function():
print("Hello, World!")
Logging
TWSC uses Python's logging module to provide detailed logs during execution. Logs are printed to the console in the following format:
2024-11-19 10:45:23 - INFO - Cleaning recently changed files.
2024-11-19 10:45:23 - INFO - Cleaned trailing whitespace in: file1.py
For contribution and development
Run Tests
Clone the repository and install dependencies:
git clone https://github.com/letsgogeeky/twsc.git
cd twsc
pip install -r requirements.txt
python -m unittest discover -s tests
Contributing
Contributions are welcome! Feel free to:
- Open an issue for bug reports or feature requests.
- Submit pull requests for improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Known Limitations
-
Unsupported Extensions:
.phpfiles are not supported for cleanup.
-
Non-Git Directories:
- Requires confirmation to clean the entire codebase.
Feel free to reach out if you have questions or issues with TWSC!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twsc-0.9.1.tar.gz.
File metadata
- Download URL: twsc-0.9.1.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9d74acc8d5a2cb9773ae8a5029723df4940617fcd70703754735d8a0f17b136
|
|
| MD5 |
3fceb2d3dcd5ca29161b284a48198c2a
|
|
| BLAKE2b-256 |
1185d2c0f64145bfa026b9dc92676b8454c917c0fd9d0522d8f3c78564bd8875
|
File details
Details for the file twsc-0.9.1-py3-none-any.whl.
File metadata
- Download URL: twsc-0.9.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82fe4a437120631631ab2500681d66e41aed5510ed23e3b317d4f6ddd4658dd9
|
|
| MD5 |
be3fbbdd416cb75d1446909eae89b09a
|
|
| BLAKE2b-256 |
659734a4b2dc3946acd54678b2355a6067db1e5ba8ba855d1936efcc5b28f246
|