Skip to main content

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

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] [--config CONFIG] [--no-config] [--init] [--show-config] [-s SPACES] [-m] [-t] [-f] [--remove-bom] [--keep-bom] [--format-json] [--git-staged]
              [--git-unstaged] [--git-all-changed] [--no-gitignore] [--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] [-r] [-i] [--progress] [--dry-run] [--backup] [--pre-commit] [-v] [-q] [--no-color] [--diff FILE1 FILE2]
              [paths ...]

Advanced tab/space indentation fixer with extended features

positional arguments:
  paths                 Files or directories to process

options:
  -h, --help            show this help message and exit
  --diff FILE1 FILE2    Compare indentation between two files

Configuration:
  --config CONFIG       Path to configuration file
  --no-config           Ignore configuration files
  --init                Initialize configuration file (.tabfixrc)
  --show-config         Show current configuration and exit

Formatting options:
  -s, --spaces SPACES   Number of spaces per tab (default: 4)
  -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

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

Encoding and file handling:
  --skip-binary         Skip files that appear to be binary
  --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

Operation mode:
  -r, --recursive       Process directories recursively
  -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)
  --pre-commit          Generate pre-commit hook configuration

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

Configuration:
  tabfix will look for configuration files in the following order:
  1. .tabfixrc, .tabfixrc.json, .tabfixrc.toml, .tabfixrc.yaml
  2. pyproject.toml (in [tool.tabfix] section)
  3. tabfix.json

  Command line arguments override configuration file settings.

Examples:
  tabfix --init                    # Create .tabfixrc config file
  tabfix --pre-commit              # Generate pre-commit hook config
  tabfix --recursive --remove-bom  # Process recursively, remove BOM
  tabfix --git-staged --interactive # Interactive mode on staged files

install optional unifmt or dev/encoding/full

pip install tabfix-tool[unifmt] # 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.5.1.tar.gz (44.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.5.1-py3-none-any.whl (47.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tabfix_tool-1.2.5.1.tar.gz
  • Upload date:
  • Size: 44.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.5.1.tar.gz
Algorithm Hash digest
SHA256 65b3f928541a17775bddbfaaca58d1d83922d8ab86ab056c06081e76a3885e55
MD5 33a1e7460f72fc3c32ea615b0d9d30c9
BLAKE2b-256 350e2a8d8be88edcb5fb8f35e258439ab9616ea1ef566a40d5c9cc04e21733ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for tabfix_tool-1.2.5.1.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.5.1-py3-none-any.whl.

File metadata

  • Download URL: tabfix_tool-1.2.5.1-py3-none-any.whl
  • Upload date:
  • Size: 47.3 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.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b996b2af652ef39e8cbf14599bf59576f4c2de7cb7b8fd67aa1ad66d4704290f
MD5 b6f0ef76476fdf85a92a2d1683241d8b
BLAKE2b-256 6d6c2b7d63bb060c08c4fbc73f65d044d52e47f238d203540e7b0640450d446c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tabfix_tool-1.2.5.1-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