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.2.tar.gz (42.6 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.2-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tabfix_tool-1.2.5.2.tar.gz
  • Upload date:
  • Size: 42.6 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.2.tar.gz
Algorithm Hash digest
SHA256 ea9d12dd9383d6c76d980f1baede1fd23ae56e6fe700358c5403e9f789de10fb
MD5 a973312c77485b73a243c6e065801160
BLAKE2b-256 f51259b3080228e7886352789ca3db55130596c6638b42fd2c8122f3d464991f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: tabfix_tool-1.2.5.2-py3-none-any.whl
  • Upload date:
  • Size: 44.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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 13634e7ea4c9bc8fd48b15bb54832f52ab342ecaf41c5144d33362c40f85ee0b
MD5 08e94158bfc7dbfed17569ecf52eda01
BLAKE2b-256 c9e5540592eac175b47c40a51253db492bc65f1ce5d74614210dd403b84c3f16

See more details on using hashes here.

Provenance

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