Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/prose-gate/prose-gate.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"repeat_marker": true,
"docstrings": true,
"trailing_directives": ["#\\s*(?:(?i:noqa|nopep8)|type:\\s*ignore)\\b", "\\bpylint:"],
"metadata_block": ["# /// script", "#(?: .*)?", "# ///"],
"numpy_sections": ["attributes", "methods", "other parameters", "parameters", "raises", "receives", "returns", "warns", "yields"],
"google_sections": [
"Args", "Arguments", "Attributes", "Keyword Args", "Keyword Arguments", "Methods", "Other Parameters", "Parameters", "Raise",
Expand Down
25 changes: 25 additions & 0 deletions .github/actions/prose-gate/prose_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,30 @@ def is_comment_prose(body: str, config: Config) -> bool:
)


def without_metadata_blocks(unit: Unit, ctx: Context) -> Unit:
"""The comment unit without the lines of each closed metadata block the language declares.

A tool reads such a block rather than a person, so no comment rule reads it. A line off the
block's form, or a gap, abandons the block, so an unclosed one is left whole.
"""
form = ctx.language.get("metadata_block")
if unit.kind != "comment" or not form:
return unit
opener, body, closer = (re.compile(pattern) for pattern in form)
out: set[int] = set()
run: list[int] = []
for line in unit.lines:
adjacent = bool(run) and line.leading and line.number == run[-1] + 1
if adjacent and closer.fullmatch(line.raw):
out.update((*run, line.number))
run = []
elif adjacent and body.fullmatch(line.raw):
run.append(line.number)
else:
run = [line.number] if line.leading and opener.fullmatch(line.raw) else []
return unit._replace(lines=tuple(line for line in unit.lines if line.number not in out))


def rule_comment_added(unit: Unit, ctx: Context) -> list[Finding]:
"""Every prose comment line opening its own line, which the diff scope narrows to a change.

Expand Down Expand Up @@ -1793,6 +1817,7 @@ def check_file(
lexer = lexer_name(path, text.split("\n", 1)[0].rstrip("\r"))
config = config_for(str(root) if root else None)
ctx = Context(path, root, fenced, language_of(lexer) or {}, config, allowed)
units = [without_metadata_blocks(unit, ctx) for unit in units]
passes: dict[Rule, set[str]] = {}
for name in RULE_TABLE:
if name in rules:
Expand Down
Loading
Loading