mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 04:54:16 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import annotations
|
||||
from .exceptions import ParseError
|
||||
|
||||
from typing import NamedTuple
|
||||
|
||||
from .exceptions import ParseError
|
||||
|
||||
COMMENTCHARS = "#;"
|
||||
|
||||
COMMENTCHARS = '#;'
|
||||
|
||||
|
||||
class _ParsedLine(NamedTuple):
|
||||
|
|
@ -25,19 +26,19 @@ def parse_lines(path: str, line_iter: list[str]) -> list[_ParsedLine]:
|
|||
# new section
|
||||
elif name is not None and data is None:
|
||||
if not name:
|
||||
raise ParseError(path, lineno, "empty section name")
|
||||
raise ParseError(path, lineno, 'empty section name')
|
||||
section = name
|
||||
result.append(_ParsedLine(lineno, section, None, None))
|
||||
# continuation
|
||||
elif name is None and data is not None:
|
||||
if not result:
|
||||
raise ParseError(path, lineno, "unexpected value continuation")
|
||||
raise ParseError(path, lineno, 'unexpected value continuation')
|
||||
last = result.pop()
|
||||
if last.name is None:
|
||||
raise ParseError(path, lineno, "unexpected value continuation")
|
||||
raise ParseError(path, lineno, 'unexpected value continuation')
|
||||
|
||||
if last.value:
|
||||
last = last._replace(value=f"{last.value}\n{data}")
|
||||
last = last._replace(value=f'{last.value}\n{data}')
|
||||
else:
|
||||
last = last._replace(value=data)
|
||||
result.append(last)
|
||||
|
|
@ -47,30 +48,30 @@ def parse_lines(path: str, line_iter: list[str]) -> list[_ParsedLine]:
|
|||
def _parseline(path: str, line: str, lineno: int) -> tuple[str | None, str | None]:
|
||||
# blank lines
|
||||
if iscommentline(line):
|
||||
line = ""
|
||||
line = ''
|
||||
else:
|
||||
line = line.rstrip()
|
||||
if not line:
|
||||
return None, None
|
||||
# section
|
||||
if line[0] == "[":
|
||||
if line[0] == '[':
|
||||
realline = line
|
||||
for c in COMMENTCHARS:
|
||||
line = line.split(c)[0].rstrip()
|
||||
if line[-1] == "]":
|
||||
if line[-1] == ']':
|
||||
return line[1:-1], None
|
||||
return None, realline.strip()
|
||||
# value
|
||||
elif not line[0].isspace():
|
||||
try:
|
||||
name, value = line.split("=", 1)
|
||||
if ":" in name:
|
||||
name, value = line.split('=', 1)
|
||||
if ':' in name:
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
try:
|
||||
name, value = line.split(":", 1)
|
||||
name, value = line.split(':', 1)
|
||||
except ValueError:
|
||||
raise ParseError(path, lineno, "unexpected line: %r" % line)
|
||||
raise ParseError(path, lineno, 'unexpected line: %r' % line)
|
||||
return name.strip(), value.strip()
|
||||
# continuation
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue