sfcc/no-empty-global
Disallows the SFCC-specific empty(...) global in JavaScript files. Use explicit checks instead, such as .length === 0, Object.keys(...).length === 0, or .isEmpty().
What it checks
- Flags calls to the global
empty(...) - Applies only to JavaScript-like inputs:
.js,.mjs,.cjs,.ds, and<input> - When TypeScript parser services with type information are available, suggestions are narrowed to the most likely replacement for the value type
Why this rule exists
empty() is an SFCC-specific global, not standard JavaScript. It can be confusing when code is meant to read like normal JavaScript, and explicit checks are easier to understand for the underlying type.
Default behavior
- Severity:
error - Auto-fix: none
- Suggestions: yes
Nullable references
When you know a value is only a nullable object reference, for example dw.catalog.Product | null, a null check can be the clearest replacement.
if (empty(product)) {
return
}if (!product) {
return
}The rule may offer this as an additional suggestion for identifiers and member expressions, but it is intentionally not the only recommendation because empty(...) is also used for strings, arrays, plain objects, and SFCC collections.
With type information enabled, the rule narrows suggestions for identifier/member-expression arguments to reduce noisy alternatives.
Examples
if (empty(productIds)) {
return
}if (productIds.length === 0) {
return
}if (Object.keys(product).length === 0) {
return
}if (collection.isEmpty()) {
return
}