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

Skip to content

Commit b4ab84d

Browse files
committed
only perform migrate_config parsing if it is a list
1 parent b2207e5 commit b4ab84d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

pre_commit/commands/migrate_config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ def _is_header_line(line: str) -> bool:
1616

1717

1818
def _migrate_map(contents: str) -> str:
19-
# Find the first non-header line
20-
lines = contents.splitlines(True)
21-
i = 0
22-
# Only loop on non empty configuration file
23-
while i < len(lines) and _is_header_line(lines[i]):
24-
i += 1
19+
if isinstance(yaml_load(contents), list):
20+
# Find the first non-header line
21+
lines = contents.splitlines(True)
22+
i = 0
23+
# Only loop on non empty configuration file
24+
while i < len(lines) and _is_header_line(lines[i]):
25+
i += 1
2526

26-
header = ''.join(lines[:i])
27-
rest = ''.join(lines[i:])
27+
header = ''.join(lines[:i])
28+
rest = ''.join(lines[i:])
2829

29-
if isinstance(yaml_load(contents), list):
3030
# If they are using the "default" flow style of yaml, this operation
3131
# will yield a valid configuration
3232
try:

0 commit comments

Comments
 (0)