---
url: /commerce-klaus/packages/eslint-config-sfcc/rules/sfcc/no-empty-global.md
---
# 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.

```js [Invalid]
// [!code error:1]
if (empty(product)) {
  return
}
```

```js{1} [Valid: nullable references]
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

```js [Invalid]
// [!code error:1]
if (empty(productIds)) {
  return
}
```

```js{1} [Valid: arrays and strings]
if (productIds.length === 0) {
  return
}
```

```js{1} [Valid: plain objects]
if (Object.keys(product).length === 0) {
  return
}
```

```js{1} [Valid: SFCC collections]
if (collection.isEmpty()) {
  return
}
```
