Skip to main content

Advanced tab/space indentation fixer with autoformatting support

Project description

PyPI version PyPI downloads Python versions Codacy Badge GitHub repo size GitHub last commit GitHub issues GitHub forks GitHub stars GitHub license

TabFix Tool

Advanced tool for fixing tab/space indentation issues in code files.

Features

  • Fix mixed tabs and spaces indentation
  • Remove trailing whitespace
  • Normalize line endings
  • Handle UTF-8 BOM markers
  • Format JSON files
  • Git integration
  • Progress bars with tqdm
  • Colorful output

Installation

# Install from PyPI
pip install tabfix-tool
# Or directly from GitHub
pip install git+https://github.com/hairpin01/tabfix.git

or via installer

curl https://raw.githubusercontent.com/hairpin01/tabfix/refs/heads/main/src/tabfix/installer.py | python3

[!TIP] to install the unifmt package, see optional

From source

git clone https://github.com/hairpin01/tabfix.git && cd tabfix && pip install -e .

Usage

# Basic usage
tabfix file.py
# Recursive processing
tabfix --recursive src/
# Fix multiple issues
tabfix --all --progress .
# Check without modifying
tabfix --check-mixed --recursive .

Complete Help Reference

Show full command reference (tabfix -h)
$ tabfix -h
usage: tabfix [-h] [-s SPACES] [-r] [--git-staged] [--git-unstaged]
              [--git-all-changed] [--no-gitignore] [--autoformat]
              [--check-format] [--list-formatters] [--formatters FORMATTERS]
              [--init-autoformat] [--skip-binary] [--no-skip-binary]
              [--force-encoding FORCE_ENCODING]
              [--fallback-encoding FALLBACK_ENCODING] [--warn-encoding]
              [--max-file-size MAX_FILE_SIZE] [--smart-processing]
              [--no-smart-processing] [--preserve-quotes] [-m] [-t] [-f]
              [--remove-bom] [--keep-bom] [--format-json] [-i] [--progress]
              [--dry-run] [--backup] [--diff FILE1 FILE2] [-v] [-q]
              [--no-color] [--init] [--config CONFIG] [--no-config]
              [paths ...]

Advanced tab/space indentation fixer with autoformatting

positional arguments:
  paths                 Files or directories to process

options:
  -h, --help            show this help message and exit
  -s, --spaces SPACES   Number of spaces per tab (default: 4)
  -r, --recursive       Process directories recursively
  --init                Initialize configuration file (.tabfixrc)
  --config CONFIG       Path to configuration file
  --no-config           Ignore configuration files

Git integration:
  --git-staged          Process only staged files in git
  --git-unstaged        Process only unstaged files in git
  --git-all-changed     Process all changed files in git
  --no-gitignore        Do not use .gitignore patterns

Autoformatting:
  --autoformat, -a      Autoformat files using external formatters
  --check-format        Check formatting without making changes
  --list-formatters     List available formatters and exit
  --formatters FORMATTERS
                        Comma-separated list of formatters to use (e.g.
                        black,isort)
  --init-autoformat     Initialize autoformat configuration file

Encoding and binary file handling:
  --skip-binary         Skip files that appear to be binary (default: True)
  --no-skip-binary      Process files even if they appear to be binary
  --force-encoding FORCE_ENCODING
                        Force specific encoding (skip auto-detection)
  --fallback-encoding FALLBACK_ENCODING
                        Fallback encoding when detection fails (default:
                        latin-1)
  --warn-encoding       Warn when encoding detection is uncertain
  --max-file-size MAX_FILE_SIZE
                        Maximum file size to process in bytes (default:
                        10MB)

File type specific processing:
  --smart-processing    Enable smart processing for different file types
                        (default: True)
  --no-smart-processing
                        Disable smart processing for different file types
  --preserve-quotes     Preserve original string quotes in code files

Formatting options:
  -m, --fix-mixed       Fix mixed tabs/spaces indentation
  -t, --fix-trailing    Remove trailing whitespace
  -f, --final-newline   Ensure file ends with newline
  --remove-bom          Remove UTF-8 BOM marker
  --keep-bom            Preserve existing BOM marker
  --format-json         Format JSON files with proper indentation

Operation mode:
  -i, --interactive     Interactive mode (confirm each change)
  --progress            Show progress bar during processing
  --dry-run             Show changes without modifying files
  --backup              Create backup files (.bak)
  --diff FILE1 FILE2    Compare indentation between two files

Output control:
  -v, --verbose         Verbose output
  -q, --quiet           Quiet mode (minimal output)
  --no-color            Disable colored output

Examples:
  tabfix --init                    # Create .tabfixrc config file
  tabfix --init-autoformat         # Create autoformat config
  tabfix --autoformat              # Autoformat files using external tools
  tabfix --check-format            # Check formatting without changes
  tabfix --list-formatters         # List available formatters
  tabfix --recursive --remove-bom  # Process recursively, remove BOM
  tabfix --git-staged --interactive # Interactive mode on staged files
  tabfix --diff file1.py file2.py  # Compare indentation

install optional unifmt or dev/encoding/full

pip install tabfix-tool[all] # or {optional}

API Documentation

Python API examples
# developer_script.py
from tabfix import TabFixAPI, TabFixConfig, fix_string, fix_file

# Method 1: Using API class
config = TabFixConfig(spaces=2, fix_mixed=True, fix_trailing=True)
api = TabFixAPI(config)

# Fix a string
fixed_content, changes = api.fix_string("def foo():\n\tprint('hello')", Path("test.py"))
print(f"Fixed content: {fixed_content}")
print(f"Changes: {changes}")

# Fix a file
changed, file_changes = api.fix_file(Path("my_script.py"))
print(f"File changed: {changed}")
print(f"File changes: {file_changes}")

# Method 2: Using convenience functions
# Fix string directly
content = "if True:\n\tprint('tab')"
fixed, changes = fix_string(content, spaces=4)
print(f"Fixed: {fixed}")

# Check if file needs fixing
needs_fix, issues = check_file(Path("config.json"))
print(f"Needs fix: {needs_fix}, Issues: {issues}")

# Detect indentation style
result = detect_indentation(content)
print(f"Indentation: {result}")

# Create config file
create_config_file(Path(".tabfixrc.json"))

More:

# developer_script.py
from tabfix import TabFixAPI, TabFixConfig, fix_string, fix_file

# Method 1: Using API class
config = TabFixConfig(spaces=2, fix_mixed=True, fix_trailing=True)
api = TabFixAPI(config)

# Fix a string
fixed_content, changes = api.fix_string("def foo():\n\tprint('hello')", Path("test.py"))
print(f"Fixed content: {fixed_content}")
print(f"Changes: {changes}")

# Fix a file
changed, file_changes = api.fix_file(Path("my_script.py"))
print(f"File changed: {changed}")
print(f"File changes: {file_changes}")

# Method 2: Using convenience functions
# Fix string directly
content = "if True:\n\tprint('tab')"
fixed, changes = fix_string(content, spaces=4)
print(f"Fixed: {fixed}")

# Check if file needs fixing
needs_fix, issues = check_file(Path("config.json"))
print(f"Needs fix: {needs_fix}, Issues: {issues}")

# Detect indentation style
result = detect_indentation(content)
print(f"Indentation: {result}")

# Create config file
create_config_file(Path(".tabfixrc.json"))

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

tabfix_tool-1.2.6.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tabfix_tool-1.2.6-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

Details for the file tabfix_tool-1.2.6.tar.gz.

File metadata

  • Download URL: tabfix_tool-1.2.6.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tabfix_tool-1.2.6.tar.gz
Algorithm Hash digest
SHA256 863c9e23f927b4ce808266f27ae07eace2c169e958166123cf76e53f7059d48e
MD5 06ea1706bac8c604be3cc90b0c29fa49
BLAKE2b-256 2821d67a86e29ba415a5d6843f29f028217a259ff566ad12778548380a05caef

See more details on using hashes here.

Provenance

The following attestation bundles were made for tabfix_tool-1.2.6.tar.gz:

Publisher: publish.yml on hairpin01/tabfix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tabfix_tool-1.2.6-py3-none-any.whl.

File metadata

  • Download URL: tabfix_tool-1.2.6-py3-none-any.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tabfix_tool-1.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 baf2cdce9d2eaa1eb5f1e0da5333a4b2204231fc9770889738969145e7494a90
MD5 5cf9afea2c6d52a36061a1c23b7775d5
BLAKE2b-256 52116c2fe77b3095d64f1c8d06f32aa9fba78dbb2f6c9c6a6598fa0d44976ff2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tabfix_tool-1.2.6-py3-none-any.whl:

Publisher: publish.yml on hairpin01/tabfix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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