Skip to content

Python Autoformatter Visitors #112

@nielsdebruin

Description

@nielsdebruin

What problem are you trying to solve?

The autoformatted is an essential part of many open-rewrite recipes. The general structure of the Python autoformatter will follow that of the Java equivalent. Effectively, these consist of a sequence of visitors, each responsible for specific parts of the formatting process. As the Python code is mapped to an LST that is mostly identical to the Java code, we can reuse much of the same logic already implemented in the Java autoformatting visitors. Below is a list of visitors, each of which should be partially implemented for a workable version of the Python autoformatter and their current status.

Visitors Stage 1 (Complete):

  • Blank lines
  • Normalize format
  • Normalize line breaks
  • Normalize tabs or spaces
  • Remove trailing white spaces
  • Spaces
  • Tabs and indents

Important! To achieve a working Python version as swiftly as possible, we designed it to closely resemble the already (working) Java autoformatter. However, the code/structure in the Java autoformatter has built up a decent amount of technical debt and is a good candidate for refactoring. While this approach is likely the quickest way to construct the Python autoformatter, it also transfers technical debt from the Java visitor to the Python autoformatter. Moreover, some of the logic present in the Java autoformatter might not be required/relevant in the Python autoformatter but is also not harmful; hence, after the autoformatter is in working order and adequate test coverage is established, a secondary refactor/review of the code should be performed.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions