Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .coveragerc

This file was deleted.

30 changes: 0 additions & 30 deletions .editorconfig

This file was deleted.

6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

66 changes: 0 additions & 66 deletions .pre-commit-config.yaml

This file was deleted.

8 changes: 4 additions & 4 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- id: indents-to-tabs
name: Indents to tabs
description: Replace spaces with tabs in indents
entry: indents-to-tabs
- id: indents-to-spaces
name: Indents to spaces
description: Replace tabs with spaces in indents
entry: indents-to-spaces
language: python
types: [text]
6 changes: 0 additions & 6 deletions .prettierrc.toml

This file was deleted.

44 changes: 19 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
# Please type "make help" in your terminal for a list of make targets.

# ITT => Indents To Tabs
# ITT_VENV is the name of directory to store the virtual environment
ITT_VENV ?= .venv
# ITS => Indents To Spaces
# ITS_VENV is the name of directory to store the virtual environment
ITS_VENV ?= .venv
# ROOT_PYTHON is invoked to create the venv
ROOT_PYTHON ?= python3
# ITT_PYTHON is used to invoke packages in the venv
ITT_PYTHON ?= $(ITT_VENV)/bin/python3
# ITS_PYTHON is used to invoke packages in the venv
ITS_PYTHON ?= $(ITS_VENV)/bin/python3

.DEFAULT_GOAL:=help

$(ITT_VENV)/bin/activate:
mkdir -p $(ITT_VENV)
$(ROOT_PYTHON) -m venv $(ITT_VENV)
$(ITT_VENV)/bin/pip install -r requirements-dev.txt
$(ITT_VENV)/bin/pip install -e .
$(ITS_VENV)/bin/activate:
mkdir -p $(ITS_VENV)
$(ROOT_PYTHON) -m venv $(ITS_VENV)
$(ITS_VENV)/bin/pip install -r requirements-dev.txt
$(ITS_VENV)/bin/pip install -e .

.PHONY: test ## Test the project
test: $(ITT_VENV)/bin/activate
$(ITT_VENV)/bin/mypy src
$(ITT_VENV)/bin/mypy tests
$(ITT_VENV)/bin/pytest

.PHONY: tox ## Test the project in multiple Python environments
tox: $(ITT_VENV)/bin/activate
$(ITT_VENV)/bin/tox
test: $(ITS_VENV)/bin/activate
$(ITS_VENV)/bin/pytest

.PHONY: build ## Build the project for distribution
build: clean $(ITT_VENV)/bin/activate
$(ITT_PYTHON) -m build
build: clean $(ITS_VENV)/bin/activate
$(ITS_PYTHON) -m build

.PHONY: release ## Upload build artifacts to PyPI
release: $(ITT_VENV)/bin/activate
$(ITT_PYTHON) -m twine upload --repository testpypi dist/*
release: $(ITS_VENV)/bin/activate
$(ITS_PYTHON) -m twine upload --repository testpypi dist/*

.PHONY: clean ## Remove project development artifacts
clean:
Expand All @@ -41,10 +35,10 @@ clean:

.PHONY: purge ## Clean + remove caches, virtual environment
purge: clean
rm -rf .mypy_cache
rm -rf src/indents_to_spaces/__pycache__
rm -rf tests/__pycache__
rm -rf .pytest_cache
rm -rf .tox
rm -rf $(ITT_VENV)
rm -rf $(ITS_VENV)

.PHONY: help ## List make targets with description
help:
Expand Down
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Pre-Commit Hook: Convert indents (from spaces) to tabs
# Pre-Commit Hook: Convert indents from tabs to spaces

This project is a both a fork and the exact opposite of Andrew Pinkham's
[pre-commit-indents-to-tabs](https://github.com/jambonrose/pre-commit-indents-to-tabs)
plugin.

It converts all indents from tabs to spaces when used with [pre-commit](https://pre-commit.com).

## Usage

Expand All @@ -10,28 +16,28 @@ The code below demonstrates a minimal configuration for usage in
`.pre-commit-config.yaml`.

```yaml
- repo: https://github.com/jambonrose/pre-commit-indents-to-tabs
- repo: https://github.com/oliv5/pre-commit-indents-to-spaces
rev: v0.0.1
hooks:
- id: indents-to-tabs
- id: indents-to-spaces
args: ["--spaces=4"]
```

The configuration below will run the `terraform fmt -write` command
before replacing spaces with tabs in the indents of Terraform files. The
configuration below also demonstrats the use of the `--spaces` flag,
although it is technically redundant as `2` is the default.
It is possible to set few plugin parameters. The exemple below forces to
replace each indent by 8 spaces characters instead of the default 4.

```yaml
- repo: https://github.com/jambonrose/pre-commit-indents-to-tabs
- repo: https://github.com/oliv5/pre-commit-indents-to-spaces
rev: v0.0.1
hooks:
- id: indents-to-tabs
args: ["--fmt=terraform,fmt,-write", "--spaces=2"]
types: ["terraform"]
- id: indents-to-spaces
args: ["--spaces=8"]
```

## Project Rationale

*By Andrew Pinkham, the author of the original `pre-commit-indents-to-tabs`*

I created this project as a reaction to the Terraform autoformatter.
However, the project can be used in other circumstances.

Expand All @@ -49,3 +55,8 @@ alignment. Tabs allow people to set their own preference, a necessity
for those with different needs.

I hope this helps others with eye issues.

## Credits

Huge thanks to Andrew Pinkham, the author of the original [pre-commit-indents-to-tabs](https://github.com/jambonrose/pre-commit-indents-to-tabs)
plugin.
13 changes: 0 additions & 13 deletions mypy.ini

This file was deleted.

2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
minversion = 7.0
addopts = -vv --capture=no --cov
addopts = -vv --capture=no
4 changes: 0 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
build==0.7.0
coverage==6.3.2
mypy==0.931
pytest==7.0.1
pytest-cov==3.0.0
tox==3.24.5
twine==3.8.0
25 changes: 11 additions & 14 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
universal = True

[metadata]
name = pre-commit-indents-to-tabs
version = attr: indents_to_tabs.__version__
description = Pre-commit hook to replace spaces with tabs in indents.
author = Andrew Pinkham
name = pre-commit-indents-to-spaces
version = attr: indents_to_spaces.__version__
description = Pre-commit hook to replace tabs with spaces in indents.
author = Oliv5
license = BSD 2-Clause License
license_file = LICENSE
url = https://github.com/jambonrose/pre-commit-indents-to-tabs
url = https://github.com/oliv5/pre-commit-indents-to-spaces
project_urls =
Bug Tracker = https://github.com/jambonrose/pre-commit-indents-to-tabs/discussions
Bug Tracker = https://github.com/oliv5/pre-commit-indents-to-spaces/discussions
classifiers =
License :: OSI Approved :: BSD License
Programming Language :: Python :: 3
Expand All @@ -23,26 +23,23 @@ classifiers =
Programming Language :: Python :: Implementation :: PyPy

[options]
package_dir=
packages = find:
package_dir =
=src
packages=find:
python_requires = >=3.7
setup_requires =
setuptools >= 46.4.0 # required to use attr to extract version
tests_require =
coverage >= 6.3
mypy >= 0.931
pytest >= 7.0.1
pytest-cov >= 3.0.0
test_suite = tests
zip_safe = False

[options.entry_points]
console_scripts =
indents-to-tabs = indents_to_tabs:main
indents-to-spaces = indents_to_spaces:main

[options.packages.find]
where=src
where = src

[options.package_data]
indents_to_tabs = py.typed
indents_to_spaces = py.typed
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Replace spaces with tabs in lines that begin with spaces."""
from __future__ import annotations

import sys
import argparse
import subprocess
from typing import Sequence

from .convert import convert_indents

__version__ = "0.0.1"
__version__ = "0.0.3"


def main(argv: Sequence[str] | None = None) -> int:
Expand All @@ -20,22 +21,22 @@ def main(argv: Sequence[str] | None = None) -> int:
help="Files to convert",
)
parser.add_argument(
"--fmt",
"--run",
type=str,
help="Comma-delimited command to run before indent replacement",
help="Comma-delimited commands to run before indent replacement",
)
parser.add_argument(
"--spaces",
type=int,
default=2,
default=4,
metavar="INTEGER",
help="How many spaces to replace with a tab",
help="How many spaces to replace a tab",
)
args = parser.parse_args(argv)

if args.fmt:
fmt_cmd: list[str] = args.fmt.split(",")
subprocess.run(fmt_cmd)
if args.run:
run_cmd: list[str] = args.run.split(",")
subprocess.run(run_cmd)

return convert_indents(args.filenames, args.spaces)

Expand Down
Loading