Configuration

P42 can be configured in the Visual Studio Code settings, using a p42.toml configuration file, and using source code annotations.

Visual Studio Code Settings

Refactorings suggestions can be configured in the Visual Studio Code settings. For each refactoring, the diagnostics severity (hint, information, warning, error) can be set, and the refactoring suggestion can be turned off.

Visual Studio Code configuration

When refactorings are turned off in the p42.toml configuration (see below), the Visual Studio Configuration is overridden and the project/team settings from p42.toml take precedence.

Configuration File

The p42.toml file in the workspace root contains P42 configuration that can be shared in a project. Just check it into your repository and share it with other team members.

Currently, individual refactorings can be enabled and disabled. By default, all refactorings are enabled.

Excluded Path Patterns

You can exclude directories, files and file patterns with the excludedPathPatterns setting. The setting is an array of minimatch (npm) glob pattern.

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

The exclusions apply to in-editor refactorings and to mass refactoring. If no exclusions are specified, the default exclusions **/dist/** and **/node_modules/** are used.

Platform Version

In the [platform] configuration section, you can specify the versions you are targeting. Only refactorings that are supported in your platform will be active and recommended. In particular, code modernizations that are not supported by your platform will be disabled. For example, if you set the ECMAScript version to ES2016, then ES2021 modernizations will not be shown.

ECMAScript

You can set the ECMAScript version that you can use in your source code. Possible values are ES5,ES2015, ES2016, ES2017, ES2018, ES2019, ES2020, ES2021, ES2022, ESNEXT (default).

Ideally, you have transpilation and polyfilling set up to produce production output code for your desired target and use ESNEXT in your source code. However, if your tooling, for example, only supports ES2016 syntax and functions, you can set the value to ES2016 and will be able to use ES5, ES2015, and ES2015 code modernizations.

[platform]
ecmaScriptVersion = "ES2016"

Disabling Refactorings

To disable a refactoring, add a section "refactoring.$refactoring-id" and set enabled to false, for example:

[refactoring.add-numeric-separator]
enabled = false

The refactoring ids are displayed as grayed-out text in parentheses in the hover messages.

Source Code Annotations

You can annotate your source code to ignore statements or files.

Ignoring Statements

You can add a // p42:ignore-next-statement comment in a separate line before a statement to prevent P42 (for VS Code and for GitHub) from analyzing the next statement and anything contained in it.

Example

if (example) {
  // p42:ignore-next-statement
  x = stringify(schema, { space: 2 }) + "\n";
}

In the above snippet, P42 will not analyse the statement x = stringify(schema, { space: 2 }) + "\n";.

Ignoring Files

You can add a // p42:ignore-file comment at the beginning of the file (before the first code line). No suggestions etc. will be shown for ignored files.