Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6487669

Browse files
committed
use textwrap.indent instead of _indent
1 parent b2207e5 commit 6487669

2 files changed

Lines changed: 2 additions & 21 deletions

File tree

pre_commit/commands/migrate_config.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import re
2+
import textwrap
23

34
import yaml
45

56
from pre_commit.clientlib import load_config
67
from pre_commit.util import yaml_load
78

89

9-
def _indent(s: str) -> str:
10-
lines = s.splitlines(True)
11-
return ''.join(' ' * 4 + line if line.strip() else line for line in lines)
12-
13-
1410
def _is_header_line(line: str) -> bool:
1511
return line.startswith(('#', '---')) or not line.strip()
1612

@@ -34,7 +30,7 @@ def _migrate_map(contents: str) -> str:
3430
yaml_load(trial_contents)
3531
contents = trial_contents
3632
except yaml.YAMLError:
37-
contents = f'{header}repos:\n{_indent(rest)}'
33+
contents = f'{header}repos:\n{textwrap.indent(rest, " " * 4)}'
3834

3935
return contents
4036

tests/commands/migrate_config_test.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,9 @@
22

33
import pre_commit.constants as C
44
from pre_commit.clientlib import InvalidConfigError
5-
from pre_commit.commands.migrate_config import _indent
65
from pre_commit.commands.migrate_config import migrate_config
76

87

9-
@pytest.mark.parametrize(
10-
('s', 'expected'),
11-
(
12-
('', ''),
13-
('a', ' a'),
14-
('foo\nbar', ' foo\n bar'),
15-
('foo\n\nbar\n', ' foo\n\n bar\n'),
16-
('\n\n\n', '\n\n\n'),
17-
),
18-
)
19-
def test_indent(s, expected):
20-
assert _indent(s) == expected
21-
22-
238
def test_migrate_config_normal_format(tmpdir, capsys):
249
cfg = tmpdir.join(C.CONFIG_FILE)
2510
cfg.write(

0 commit comments

Comments
 (0)