Skip to content

Commit

Permalink
refine reformat_yaml
Browse files Browse the repository at this point in the history
Changes:
* keep line ending in description value when it ends in `. ! : ; ,'
* add comments on offending regexps
* remove multiple whitespaces from offending whitespaces
* do not check offenders in EXAMPLES
  • Loading branch information
russoz committed Dec 25, 2024
1 parent 3ec6c22 commit a96e45e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions andeboxlib/actions/reformat_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def fix_desc_value(line: str) -> str:
line = line[0].upper() + line[1:]
if line.endswith(".)"):
return f"{line[:-2]})."
if line.endswith("."):
if line.endswith((".", "!", ":", ";", ",")):
return line
return f"{line}."

Expand Down Expand Up @@ -86,14 +86,13 @@ def get_processor(variable, in_doc_fragments=False):
re.compile(exp)
for exp in [
r"`",
r"\bi\.e\b",
r"\be\.g\.?\b",
r"[^/]etc\b",
r"\bvia\b",
r"\bi\.e\b", # i.e
r"\be\.g\.?\b", # e.g.
r"[^/]etc\b", # etc, but not /etc
r"\bvia\b", # via
r"\bversus\b",
r"\bvs\.?\b",
r"\bversa\b",
r"\S\s\s+\S",
]
]

Expand Down Expand Up @@ -206,7 +205,7 @@ def reformat_yaml_in_python_file(self, file_path, offenders, dry_run):
outbound_content = self.process_yaml_block(
quoted_content, get_processor(in_variable), dry_run
)
if offenders:
if offenders and in_variable != "EXAMPLES":
report_offenders(outbound_content, first_line_no)
updated_lines.extend(outbound_content)
updated_lines.append('"""')
Expand Down

0 comments on commit a96e45e

Please sign in to comment.