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

Skip to content

Commit c972205

Browse files
authored
Merge pull request #1684 from pre-commit/migrate_config_less_work
only perform migrate_config parsing if it is a list
2 parents 1975c05 + b4ab84d commit c972205

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
@@ -12,17 +12,17 @@ def _is_header_line(line: str) -> bool:
1212

1313

1414
def _migrate_map(contents: str) -> str:
15-
# Find the first non-header line
16-
lines = contents.splitlines(True)
17-
i = 0
18-
# Only loop on non empty configuration file
19-
while i < len(lines) and _is_header_line(lines[i]):
20-
i += 1
15+
if isinstance(yaml_load(contents), list):
16+
# Find the first non-header line
17+
lines = contents.splitlines(True)
18+
i = 0
19+
# Only loop on non empty configuration file
20+
while i < len(lines) and _is_header_line(lines[i]):
21+
i += 1
2122

22-
header = ''.join(lines[:i])
23-
rest = ''.join(lines[i:])
23+
header = ''.join(lines[:i])
24+
rest = ''.join(lines[i:])
2425

25-
if isinstance(yaml_load(contents), list):
2626
# If they are using the "default" flow style of yaml, this operation
2727
# will yield a valid configuration
2828
try:

0 commit comments

Comments
 (0)