sfcc/no-dw-api
Disallows SFCC dw/* APIs in portable JavaScript modules.
This rule is opt-in and is not part of the recommended config or a storefront architecture preset. Apply it to domain, utility, or shared cartridges that must run without the SFCC runtime.
What it checks
- Reports static
require("dw/*")calls - Reports static
import("dw/*")expressions - Ignores relative, cartridge, and bare modules outside the
dw/namespace - Ignores dynamic module paths because they cannot be checked reliably against the allow list
Configuration
Register the built-in plugin and apply the rule only to portable cartridges:
eslint.config.js
js
import sfccConfig, { sfcc } from "@commerce-klaus/eslint-config-sfcc"
export default [
...sfccConfig.configs.recommended,
{
files: ["cartridges/lib_domain/**/*.js"],
plugins: { sfcc },
rules: {
"sfcc/no-dw-api": "error",
},
},
]Options
The optional allow array accepts exact module paths and namespace entries ending in /*:
eslint.config.js
js
export default {
rules: {
"sfcc/no-dw-api": [
"error",
{
allow: ["dw/value/Money", "dw/util/*"],
},
],
},
}dw/value/Moneyallows only that exact module.dw/util/*allows every module belowdw/util/.dw/utilis not treated as a prefix; wildcard behavior must be explicit.
Default behavior
- Severity: off (opt-in)
- Allowed modules: none
- Auto-fix: none
Example
Invalid
js
const Transaction = require("dw/system/Transaction")
module.exports = Transaction