File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import re
2+ import textwrap
23
34import yaml
45
56from pre_commit .clientlib import load_config
67from 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-
1410def _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
Original file line number Diff line number Diff line change 22
33import pre_commit .constants as C
44from pre_commit .clientlib import InvalidConfigError
5- from pre_commit .commands .migrate_config import _indent
65from pre_commit .commands .migrate_config import migrate_config
76
87
9- @pytest .mark .parametrize (
10- ('s' , 'expected' ),
11- (
12- ('' , '' ),
13- ('a' , ' a' ),
14- ('foo\n bar' , ' foo\n bar' ),
15- ('foo\n \n bar\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-
238def test_migrate_config_normal_format (tmpdir , capsys ):
249 cfg = tmpdir .join (C .CONFIG_FILE )
2510 cfg .write (
You can’t perform that action at this time.
0 commit comments