The P42 Safety Analysis checks if refactorings can change the code's behavior (within limitations). The P42 context and quick-fix menu items often contain safety indicators:
- No indicator: P42 has not evaluated the safety of the refactoring or code action. No indicator is the default for code actions such as adding console.log statements that intentionally change your program.
- Safe ✅: The refactoring will not change the behavior of your code.
- Information ℹ️: The refactoring might detrimentally affect comments or readability.
- Warning ⚠️: The refactoring might change the behavior of your code. The text will include short hints at what you need to check to proceed safely. The documentation page for the code action might contain more details.
- Error ⛔: The refactoring will change the behavior of your code and can introduce defects. You might still want to proceed, particularly if you want to change the behavior on purpose.
When you are using TypeScript, the safety analysis relies on the accuracy of your type annotations. If your type annotations are not accurate, some refactorings deemed safe by P42 might lead to the introduction of defects.
The safety analysis analyzes single files without a larger type context. Some indirect types resolved by TypeScript in your program might be considered
unknown. As a result, P42 might present warnings that are not relevant if you have the complete type information.
P42 identifies whether a file is run in an isolated context (i.e.,
function do not change the global scope) based on the file extension or the use of
require. Files with a
.cjs extension or a top-level
module.exports are assumed to run as Node.js CommonJS modules. Files with a
.mjs extension or
var could affect the global scope.
The safety analysis does not cover runtime performance, which can be vital if you work on hotspot areas of your application. Refactorings might negatively impact the application performance in some cases.
The safety analysis does not cover comments. P42 tries to retain comment associations as much as possible, but there can be cases where it is unclear which source code belongs to which comment.