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] [--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.9.tar.gz (39.7 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.9-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tabfix_tool-1.2.5.9.tar.gz
  • Upload date:
  • Size: 39.7 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.9.tar.gz
Algorithm Hash digest
SHA256 95e9a865fb2f073bd27c99e72e89af05dd64508b313fd54b0cbb16f1ed70c92b
MD5 ebfb52efbe28eceb920f090d44c706b6
BLAKE2b-256 c09ba335d46fb9e29fd7a756c499550322ee006f0f4cef09a0f1c215a6b5b113

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: tabfix_tool-1.2.5.9-py3-none-any.whl
  • Upload date:
  • Size: 39.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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6a9dc40f02060fb6b6a464c16b585477064e5f7252764bb66212a932da8490cf
MD5 b1a44a99d99113c34f4804c7ea2bc82a
BLAKE2b-256 580c22007dd71894470826c367da1deecaabad050af15a93583a02d41983f72b

See more details on using hashes here.

Provenance

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