Diagnostics & Quick Fixes

Type-aware script checks, SFCC-specific diagnostics, let and const fixes for Rhino, diagnostic-driven code actions, and current editing limitations

Diagnostics connect the code you write to the types the server knows. They appear as editor underlines and entries in VS Code's Problems panel. The checker uses bundled SFCC types, indexed project modules, and generated metadata types

Script checks

The engine reports syntax errors, type errors, and suggestions for recognized server-side scripts. SFCC-specific filtering keeps selected legacy patterns from producing irrelevant TypeScript errors; this is not an unfiltered TypeScript project's diagnostic set

The language server checks the call against the resolved SFCC type: the squiggle, its hover and the Problems entry all carry the same message and its intellij-sfcc(2339) code
cartridge/scripts/helpers/productLabel.js
var ProductMgr = require('dw/catalog/ProductMgr');
var product = ProductMgr.getProduct('demo-product');

if (product) {
    product.notARealMethod();
    // The Product type has no member named notARealMethod.
}

Try Go to Definition on ProductMgr to inspect the API declaration behind the check. Changing a required module's exported shape can also affect diagnostics in its consumers

SFCC-specific checks

let and const in server code

B2C Commerce runs server scripts on Rhino, which doesn't scope let and const as ES2015 does. A block let lives on after its block, and a const holds for the whole function and keeps the first value it gets in each call. var works the same on every runtime, so the server reports each let and const and offers var

It runs in .ds files, in .js files in a cartridge outside its static, js, client, front-end and front folders, and in template code: <isscript> and ${...}. Client scripts, .ts sources and node_modules are not checked

cartridge/controllers/Cart.js
server.get('Show', function (req, res, next) {
    const basket = BasketMgr.getCurrentBasket();
    for (let i = 0; i < basket.productLineItems.length; i++) {
        let note;
        // ...
    }
    next();
});
MessageFix
Use 'var': Rhino's 'let' does not follow ES6 block scopeReplace 'let' with 'var'
Use 'var': Rhino's 'const' is function scoped and set once per callReplace 'const' with 'var'
'total' is assigned again, which Rhino ignores for a 'const': fix that, then use 'var'None
Rename 'item' first: as a 'var' it would merge with another 'item' this function usesNone
  • The diagnostics show as Information: a blue underline and an entry in Problems
  • Replace every 'let' and 'const' with 'var' in the file converts the whole file from the lightbulb and skips the two cases with no fix
  • A let without a value in a block that runs again, such as a loop body or template code, becomes var note = undefined, because Rhino resets it on each pass
  • TypeScript's own fixes that write let or const, such as Convert 'const' to 'let', are hidden in server code

Fix on save

The whole-file fix is also the source.fixAll.intellij-sfcc source action, which VS Code's Fix All runs. If editor.codeActionsOnSave turns on "source.fixAll", saving a server script converts its let and const too. To keep other fix-all actions on save and skip this one, turn its kind off:

.vscode/settings.json
{
    "editor.codeActionsOnSave": {
        "source.fixAll": "explicit",
        "source.fixAll.intellij-sfcc": "never"
    }
}

Diagnostic-driven code actions

Place the caret on a diagnostic and run Quick Fix… from the Command Palette or use VS Code's lightbulb. The language server asks the TypeScript service for fixes relevant to that diagnostic and exposes the resulting actions

Available actions depend on the error, file, and current index state. Inspect the proposed edit and verify its result, particularly if the suggestion changes imports or more than one file. Apart from the let and const fixes, there is no guaranteed catalogue of SFCC fixes

Current editing limits

Extract-function and other refactoring commands do not yet have a completed execution path in this release. Do not rely on refactoring entries, organize imports, file-rename edits, or script-symbol rename as supported SFCC editing workflows. Use manual edits and check references afterward. ISML template variables are the exception: F2 renames them across connected templates, see Rename a template variable

What diagnostics cannot verify

Static analysis cannot establish that a sandbox has the same code version, cartridge path, metadata, or data as your workspace. Dynamically assembled module names and loosely typed values can also prevent a useful check

Use debugging for runtime behavior, XML validation for supported SFCC metadata schemas, and the ISML diagnostics guide for template linting. Watching a JSON, XML, YAML, or properties file for indexing does not imply full validation of that file format by the scripting engine

On this page