What's new in P42? Winter 2022 Summary
Tags: javascript, vscode, webdev, typescript
Published: 2022-02-01 11:49:22

There have been many changes to the [P42 JavaScript Assistant for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=p42ai.refactor) in January 2022:

## User Interface
### Suggestions Sidebar Panel
The P42 sidebar now contains a **panel with refactoring suggestions** for the content of the currently active editor. You can get more details on the suggestions and apply them directly from the panel. With [P42 Pro](https://p42.ai/plans), you can also [**apply all safe refactorings**](https://p42.ai/documentation/p42-for-vscode/p42-pro-and-business#apply-all-safe-suggestions) with a single button click.

![P42 Refactoring Suggestions Sidebar Panel](https://p42.ai/image/blog/2022-02-01-whats-new-in-p42-january-2022-roundup/p42-refactoring-suggestions-sidebar-panel.gif)

### Mass Refactoring Safety Warnings
When running a [mass refactoring](https://p42.ai/documentation/p42-for-vscode/p42-pro-and-business#mass-refactoring), it is crucial to verify the changes before committing. The mass refactoring output now contains the list of changed files and any safety warnings for refactorings that have been applied to make this easier for you to spot potential issues.

## Configuration

### Refactoring Suggestion Settings
Are there refactoring suggestions that you think should be warnings or errors? Do you want to turn off some hints that annoy you?

With the new **[refactorings suggestions settings](https://p42.ai/documentation/p42-for-vscode/configuration#visual-studio-code-settings)**, you can set the diagnostics severity to different levels and turn off refactoring suggestions.

![P42 Refactoring Configuration in VS Code Settings](https://p42.ai/image/blog/2022-02-01-whats-new-in-p42-january-2022-roundup/p42-refactoring-configuration-in-vscode-settings.gif)

### Path Exclusion Patterns

Repositories are often complicated, and there can be many files that you want to exclude from P42 mass refactorings and refactoring suggestions. Common examples include node modules, distribution and output files, configuration files, and 3rd party code that's checked into the repository.

With the new **[excluded path patterns](https://p42.ai/documentation/p42-for-vscode/configuration#excluded-path-patterns)**, you can configure a list of path globs in the `p42.toml` file that should be excluded. Here is an example:

```toml
excludedPathPatterns = [
    "**/node_modules/**",
    "**/dist/**",
    "some/other/directory/**",
    "**/generateConfig.js"
]
```

## Refactorings

### Working with Strings and Template Literals
* *New* - **[Convert String to Template Literal](https://p42.ai/documentation/code-action/convert-string-to-template-literal)**: Convert a string to a basic template literal without expressions.
* *New* - **[Convert Template Literal to String](https://p42.ai/documentation/code-action/convert-template-literal-to-string)**: Convert a simple template literal without expressions into a string.

### Working with Loops
* *New* - **[Convert Loop to For with Index Variable](https://p42.ai/documentation/code-action/convert-loop-to-for-with-index)**: Replace for...of with a regular for loop that has an index variable.
* *Improved* - **[Convert Loop to .forEach()](https://p42.ai/documentation/code-action/convert-loop-to-for-each)** supports conversion from `for..of` loops and automatically introduces an element variable if it does not exist.
* *Improved* - **[Convert Loop to for..of](https://p42.ai/documentation/code-action/convert-loop-to-for-of)** automatically introduces an element variable if it does not exist.

### Simplifying and Removing IIFEs/IIAFs
Immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) are common in older code to hide state in closures, secure the scope of `var` declarations, alias global variables, and access loop variables from async functions.

With the introduction of the block scoped `let` and `const` in ES6, many use cases have become obsolete. P42 can help you remove older IIFEs safety.

* *New* - **[Remove IIFE/IIAF](https://p42.ai/documentation/code-action/remove-iife)**: Remove IIFEs and IIAFs without parameters.
* *New* - **[Push Parameter into IIFE/IIAF](https://p42.ai/documentation/code-action/push-parameter-into-iife)**: Push a parameter of an IIFE or IIAF into its function body.

### Modernizing Lodash Usages
With the introduction of various collection helpers and new syntax in ES6 and more recent JavaScript versions, many [Lodash](https://lodash.com/) functions have become partially or fully redundant.

In January, several refactorings that help you modernize older Lodash code have been added to [P42 Pro](https://p42.ai/plans):

* *New* - **[Replace _.filter with Array.filter](https://p42.ai/documentation/code-action/replace-lodash-filter-with-javascript-array-filter)**
* *New* - **[Replace _.map with Array .map](https://p42.ai/documentation/code-action/replace-lodash-map-with-javascript-array-map)**
* *New* - **[Replace _.some with Array.some](https://p42.ai/documentation/code-action/replace-lodash-some-with-javascript-array-some)**
* *New* - **[Replace _.every with Array.every](https://p42.ai/documentation/code-action/replace-lodash-every-with-javascript-array-every)**
* *New* - **[Replace _.noop with arrow function](https://p42.ai/documentation/code-action/replace-lodash-noop-with-arrow-function)**

Those are all the new features and updates from January 2022. If you want to know about new features as soon as they are published, you can follow [@p42ai on Twitter](https://twitter.com/p42ai).

Happy Coding!