P42 Refactoring for Visual Studio Code (alpha)
Refactoring Suggestions in the Editor
Refactor suggestions are indicated as blue information underlines in applicable code segments. They can be invoked as quick fixes or through the refactoring menu. See Refactorings below for details.
Bulk Refactoring for Folders
For folders in the Explorer, there is a new "Refactor... [P42]" command for bulk refactorings. You can select a code modernization refactoring from a dialog. The selected refactoring is then applied to the files in the folder.
- Get you workspace in a clean state, e.g. by committing or stashing current changes, or by switching to a clean branch.
- Run the P42 code refactoring on the folders you want to update.
- Thoroughly review the individual changes in the diff viewer and revert / fix them as needed. Refactorings need to cover many edge cases, so there is a chance that some changes may lose comments, break formatting, or affect the semantics. If you find bugs, please report them here: https://github.com/p42ai/refactor-vscode/issues
- Run your test suites to ensure nothing broke unexpectedly.
- Commit the changes.
Convert default value assignments to parameter default values
Shorten default value assignments with nullish coalescing operator
Combine nested if-statements into single if statement with '&&' condition
Combine nested single
Convert check of last string character to 'String.endsWith()
Convert indexed for loop to for..of loop
Convert check for null and undefined into '== null' comparison
Combine return statements into a single return with a conditional expression
Split combined variable declaration into separate declarations
Convert to optional chain expressions
Convert '.apply()' call to use spread operator (...)
Convert 'var' variable declarations that can be block scoped to let and const
Convert functions to arrow functions
Convert string concatenation to template literals
p42.toml file in the workspace root contains the P42 configuration.
Currently, individual refactorings can be enabled and disabled. By default, all refactorings are enabled.
To disable a refactoring, add a section with "refactoring.$refactoring-id" and set enabled to false, for example:
enabled = false
The refactoring ids are displayed as grayed-out text in parentheses in the hover messages.
Does P42 analyse my code in the P42 cloud?
No. Your code remains on your computer and all P42 code analysis happens on your computer. No code or other data is transferred to a cloud service by the P42 extension.
How can I disable a refactoring / suggestions?
You can disable them by adding a section in the
p42.config.toml configuration file. See Configuration above.
This software is offered free of charge by
P42 Software UG (haftungsbeschränkt), Pappelallee 78/79, 10437 Berlin, Germany.
The software may not be redistributed or sold without permission.
P42 Software UG (haftungsbeschränkt) is only liable for defects in accordance with applicable law.
Open Source Libraries