FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix autoupdate parsing without trailing newline by Niranjan-png · Pull Request #3784 · pre-commit/pre-commit · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion pre_commit/commands/autoupdate.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _update_one(
return i, old, new


REV_LINE_RE = re.compile(r'^(\s+)rev:(\s*)([\'"]?)([^\s#]+)(.*)(\r?\n)$')
REV_LINE_RE = re.compile(r'^(\s+)rev:(\s*)([\'"]?)([^\s#]+)(.*)(\r?\n|)$')


def _original_lines(
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Regression test: autoupdate handles missing final newline."""
from __future__ import annotations

import re


def test_no_final_newline_rev_line():
config = 'repos:\n- repo: https://example.com/repo\n rev: v1.0.0'
REV_LINE_RE = re.compile(r'^(\s+)rev:(\s*)([^\s#]+)(.*)(\r?\n|)$')
rev_lines = [
line for line in config.splitlines()
if REV_LINE_RE.match(line)
]
assert len(rev_lines) == 1, f"Expected 1 rev line, found {len(rev_lines)}"


def test_final_newline_rev_line():
config = 'repos:\n- repo: https://example.com/repo\n rev: v1.0.0\n'
REV_LINE_RE = re.compile(r'^(\s+)rev:(\s*)([^\s#]+)(.*)(\r?\n|)$')
rev_lines = [
line for line in config.splitlines(True)
if REV_LINE_RE.match(line)
]
assert len(rev_lines) == 1


def test_crlf_rev_line():
config = 'repos:\r\n- repo: https://example.com/repo\r\n rev: v1.0.0\r\n'
REV_LINE_RE = re.compile(r'^(\s+)rev:(\s*)([^\s#]+)(.*)(\r?\n|)$')
rev_lines = [
line for line in config.splitlines(True)
if REV_LINE_RE.match(line)
]
assert len(rev_lines) == 1


def test_lf_rev_line():
config = 'repos:\n- repo: https://example.com/repo\n rev: v1.0.0\n'
REV_LINE_RE = re.compile(r'^(\s+)rev:(\s*)([^\s#]+)(.*)(\r?\n|)$')
rev_lines = [
line for line in config.splitlines(True)
if REV_LINE_RE.match(line)
]
assert len(rev_lines) == 1
Loading

Back | FazBrowse Home | New Git URL