Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoformat/spacevisitor #96

Merged
merged 42 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7534a55
Space visitor
nielsdebruin Nov 29, 2024
7b6c432
Add support for left brackets
nielsdebruin Nov 29, 2024
dbf27f5
Add support after comma for method call
nielsdebruin Nov 29, 2024
5af2396
Fixes
nielsdebruin Nov 29, 2024
dda74d0
Polish
nielsdebruin Dec 2, 2024
a95f2b9
Merge branch 'main' into autoformat/spacevisitor
nielsdebruin Dec 2, 2024
da70321
Fix bug
nielsdebruin Dec 2, 2024
d68b8b2
Add TODO for type parameters
nielsdebruin Dec 2, 2024
b910c1c
Add support for assignments
nielsdebruin Dec 2, 2024
9656e5f
Add support for assignment operator
nielsdebruin Dec 2, 2024
d03249d
Merge branch 'main' into autoformat/spacevisitor
nielsdebruin Dec 2, 2024
94532f7
Add support for binary operators
nielsdebruin Dec 3, 2024
211a69e
Add support for changed assignments
nielsdebruin Dec 3, 2024
7e970e6
Merge branch 'main' into autoformat/spacevisitor
nielsdebruin Dec 3, 2024
b3509a0
Add support for method declaration
nielsdebruin Dec 4, 2024
b2ea621
Add support for if else statements
nielsdebruin Dec 4, 2024
c7b5331
Small fix
nielsdebruin Dec 4, 2024
166abf4
Merge remote-tracking branch 'origin/main' into autoformat/spacevisitor
nielsdebruin Dec 4, 2024
0aff351
Add block statements
nielsdebruin Dec 4, 2024
cc5bc07
Add support for class declarations
nielsdebruin Dec 4, 2024
320e543
Make static methods top-level functions
knutwannheden Dec 4, 2024
6d66764
Split tests
nielsdebruin Dec 5, 2024
0ee4e83
Refactor some functions to use listutils
nielsdebruin Dec 5, 2024
913c12e
Merge remote-tracking branch 'origin/main' into autoformat/spacevisitor
nielsdebruin Dec 5, 2024
9ed550c
Add progress, added support for-loop, array-dec
nielsdebruin Dec 5, 2024
5eb2342
Add support for dicts
nielsdebruin Dec 6, 2024
6397f47
Merge remote-tracking branch 'origin/main' into autoformat/spacevisitor
nielsdebruin Dec 6, 2024
a800af7
Add support for type hints
nielsdebruin Dec 6, 2024
56838b1
Fix bug
nielsdebruin Dec 6, 2024
0435bf0
Fix bug
nielsdebruin Dec 6, 2024
466ef03
Add test/partial support for import formatting
nielsdebruin Dec 6, 2024
482605f
Correct formatting of import
nielsdebruin Dec 6, 2024
e80c55a
Replace some comprehensions with listmap
nielsdebruin Dec 7, 2024
e925adf
Remove more list comprehensions
nielsdebruin Dec 8, 2024
d122d7a
Add support for training spaces
nielsdebruin Dec 9, 2024
2015577
Fix bug
nielsdebruin Dec 10, 2024
3d61404
Merge remote-tracking branch 'origin/main' into autoformat/spacevisitor
nielsdebruin Dec 10, 2024
49f109e
Refactor compute_by_type
nielsdebruin Dec 10, 2024
28a903c
Format
nielsdebruin Dec 10, 2024
41e2bac
Fix bug and add tests
nielsdebruin Dec 10, 2024
fa9a5de
Add support and test for Union type hints.
nielsdebruin Dec 10, 2024
186ebfa
Fix bug and fix support for union types and sets
nielsdebruin Dec 10, 2024
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
Prev Previous commit
Next Next commit
Fix bug
  • Loading branch information
nielsdebruin committed Dec 10, 2024
commit 201557755e25aebbebad825830d0e1e6aa0f8671
14 changes: 9 additions & 5 deletions rewrite/rewrite/markers.py
Original file line number Diff line number Diff line change
@@ -52,14 +52,14 @@ def markers(self) -> List[Marker]:
def with_markers(self, markers: List[Marker]) -> Markers:
return self if markers is self._markers else Markers(self._id, markers)

def find_first(self, type: type):
def find_first(self, cls: Type[M]):
for marker in self.markers:
if isinstance(marker, type):
if isinstance(marker, cls):
return marker
return None

def find_all(self, type: type):
return [m for m in self.markers if isinstance(m, type)]
def find_all(self, cls: Type[M]):
return [m for m in self.markers if isinstance(m, cls)]

def compute_if(self, condition: Callable[[Marker], bool], remap_fn: Callable[[Marker], Marker]) -> Markers:
knutwannheden marked this conversation as resolved.
Show resolved Hide resolved
"""
@@ -70,11 +70,15 @@ def compute_if(self, condition: Callable[[Marker], bool], remap_fn: Callable[[Ma
:return: new Markers instance with the updated markers, or the same instance if no markers were updated
"""
updated_markers = []
updated = False
for marker in self.markers:
if condition(marker):
updated_markers.append(remap_fn(marker))
updated = True
else:
updated_markers.append(marker)

return Markers(self.id, updated_markers) if updated_markers else self
return Markers(self.id, updated_markers) if updated else self

def compute_by_type(self, cls: Type[M], remap_fn: Callable[[M], Marker]) -> Markers:
"""
4 changes: 1 addition & 3 deletions rewrite/rewrite/python/format/spaces_visitor.py
Original file line number Diff line number Diff line change
@@ -426,9 +426,7 @@ def space_before_right_padded_element(container: j.JRightPadded, add_space: bool


def space_last_comment_suffix(comments: List[j.Comment], add_space: bool) -> List[j.Comment]:
return [space_suffix(comment, add_space) if i == len(comments) - 1 else comment for i, comment
in
enumerate(comments)]
return list_map(lambda c, i: space_suffix(c, add_space) if i == len(comments) - 1 else c, comments)


def space_suffix(comment: j.Comment, add_space: bool) -> j.Comment: