There have been many changes to the P42 JavaScript Assistant for Visual Studio Code 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, you can also apply all safe refactorings with a single button click.
Mass Refactoring Safety Warnings
When running a 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, you can set the diagnostics severity to different levels and turn off refactoring suggestions.
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, you can configure a list of path globs in the p42.toml
file that should be excluded. Here is an example:
excludedPathPatterns = [
"**/node_modules/**",
"**/dist/**",
"some/other/directory/**",
"**/generateConfig.js"
]
Refactorings
Working with Strings and Template Literals
- New - Convert String to Template Literal: Convert a string to a basic template literal without expressions.
- New - 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: Replace for...of with a regular for loop that has an index variable.
- Improved - Convert Loop to .forEach() supports conversion from
for..of
loops and automatically introduces an element variable if it does not exist. - Improved - 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: Remove IIFEs and IIAFs without parameters.
- New - Push Parameter into IIFE/IIAF: 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 functions have become partially or fully redundant.
In January, several refactorings that help you modernize older Lodash code have been added to P42 Pro:
- New - Replace _.filter with Array.filter
- New - Replace _.map with Array .map
- New - Replace _.some with Array.some
- New - Replace _.every with Array.every
- New - Replace _.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.
Happy Coding!