diff --git a/rewrite/rewrite/python/format/normalize_line_breaks_visitor.py b/rewrite/rewrite/python/format/normalize_line_breaks_visitor.py index 525dd9e9..2a423fb7 100644 --- a/rewrite/rewrite/python/format/normalize_line_breaks_visitor.py +++ b/rewrite/rewrite/python/format/normalize_line_breaks_visitor.py @@ -1,9 +1,9 @@ from __future__ import annotations -from typing import Optional, TypeVar, Union +from typing import Optional, TypeVar, Union, cast -from rewrite import Tree, P, Cursor, list_map -from rewrite.java import J, Space, Comment, TextComment +from rewrite import Tree, P, Cursor, list_map, Marker +from rewrite.java import J, Space, Comment, TextComment, TrailingComma from rewrite.python import PythonVisitor, PySpace, GeneralFormatStyle, PyComment from rewrite.visitor import T @@ -43,6 +43,12 @@ def post_visit(self, tree: T, _: object) -> Optional[T]: def visit(self, tree: Optional[Tree], p: P, parent: Optional[Cursor] = None) -> Optional[T]: return tree if self._stop else super().visit(tree, p, parent) + def visit_marker(self, marker: Marker, p: P) -> Marker: + m = cast(Marker, super().visit_marker(marker, p)) + if isinstance(m, TrailingComma): + return m.with_suffix(self.visit_space(m.suffix, None, p)) + return m + STR = TypeVar('STR', bound=Optional[str]) diff --git a/rewrite/tests/python/all/format/normalize_line_breaks_visitor_test.py b/rewrite/tests/python/all/format/normalize_line_breaks_visitor_test.py index e99e3437..3958763f 100644 --- a/rewrite/tests/python/all/format/normalize_line_breaks_visitor_test.py +++ b/rewrite/tests/python/all/format/normalize_line_breaks_visitor_test.py @@ -14,6 +14,10 @@ def setUp(self): " # some comment\r\n" " def test(self):\r\n" " print()\r\n" + " a = [\r\n" + " 1,\r\n" + " 2,\r\n" + " ]\r\n" "\r\n" ) # language=python @@ -22,6 +26,10 @@ def setUp(self): " # some comment\n" " def test(self):\n" " print()\n" + " a = [\n" + " 1,\n" + " 2,\n" + " ]\n" "\n" )