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
2 changes: 1 addition & 1 deletion docs/configuration/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ forced_separate = ["glob_exp1", "glob_exp2"]

## Indent

String to place for indents defaults to " " (4 spaces).
String to place for indents defaults to " " (4 spaces). Accepts a number of spaces, `tab` (or `\t`) for a tab, or a literal string. Only used by the hanging indent multi_line_output modes; the grid and vertical modes align wrapped imports with the opening parenthesis instead.

**Type:** String
**Default:** ` `
Expand Down
5 changes: 4 additions & 1 deletion isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ def _build_arg_parser() -> argparse.ArgumentParser:
output_group.add_argument(
"-i",
"--indent",
help='String to place for indents defaults to " " (4 spaces).',
help='String to place for indents defaults to " " (4 spaces). '
"Accepts a number of spaces, `tab` (or `\\t`) for a tab, or a literal string. "
"Only used by the hanging indent multi_line_output modes; the grid and vertical "
"modes align wrapped imports with the opening parenthesis instead.",
dest="indent",
type=str,
)
Expand Down
2 changes: 2 additions & 0 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ def __init__(
indent = indent.strip("'").strip('"')
if indent.lower() == "tab":
indent = "\t"
else:
indent = indent.replace("\\t", "\t")
combined_config["indent"] = indent

known_other = {}
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ def test_invalid_profile(self) -> None:
with pytest.raises(exceptions.ProfileDoesNotExist):
Config(profile="blackandwhitestylemixedwithpep8")

@pytest.mark.parametrize(
("indent", "expected"),
[
("tab", "\t"),
("Tab", "\t"),
('"tab"', "\t"),
("\t", "\t"),
("\\t", "\t"),
("\\t\\t", "\t\t"),
("2", " "),
("' '", " "),
],
)
def test_indent(self, indent: str, expected: str) -> None:
assert Config(indent=indent).indent == expected

def test_indent_escaped_tab_in_config_file(self, tmp_path: Path) -> None:
(tmp_path / ".isort.cfg").write_text("[settings]\nindent=\\t\n", encoding="utf8")
assert Config(settings_path=str(tmp_path)).indent == "\t"

def test_is_skipped(self) -> None:
assert Config().is_skipped(Path("C:\\path\\isort.py"))
assert Config(skip=["/path/isort.py"]).is_skipped(Path("C:\\path\\isort.py"))
Expand Down
Loading