I am currently working on a project in Visual Studio Code that has poorly formatted code. Due to project constraints, I am not allowed to reformat the existing code and commit those changes. This makes the code difficult to read and maintain. I'm looking for a workaround that allows me to view and work with the code in a more readable format in my local environment without affecting the original formatting in the repository.
Specifically, my questions are:
- Is there a way in VSCode to temporarily apply code formatting that only affects my local view, without changing the actual file content that gets committed?
- Are there any extensions or settings in VSCode that can help with this situation?
- If VSCode cannot do this, is there any other tool or IDE that offers such a feature?
You are looking for formatters. I personally recommend you autopep8 or Black Formatter.
Once the extensions are installed, you only have to righ-click the on any part of the .py file and click on Format Document.
The document will be formatted. Once you finish to read it, you can undo the formatting with ctrl+z.