Skip to content

ddd-ts-kit/purity-no-environment

Architecture id: purity/no-environment. Default severity: error in recommended, error in strict.

Applies to: domain/ and application/ of a context, tests excluded.

Configuration, logs, files and the network are the outside world. Reached directly they make a use case depend on the machine it runs on; behind a port they are a parameter.

  • process.env, argv, cwd, exit, stdout, stderr, stdin
  • any member of console
  • a call of the global fetch, new XMLHttpRequest, new WebSocket, new EventSource
  • an import of fs, http, https, http2, net, dgram, dns, tls, child_process, worker_threads, os, readline, axios, node-fetch, undici, got, dotenv

Incorrect:

const url = process.env['PAYMENT_URL'];
console.log('charging', amount);
await fetch(url);

Correct:

await this.paymentGateway.charge(amount);

None.

rules."purity/no-environment" in ddd-ts-kit.config.json set to off silences the rule, and // ddd-ts-kit-disable-next-line purity/no-environment -- <reason> silences one line, exactly as for ddd-ts-kit check.

  • A wrapper around the forbidden access (a helper of the platform that calls Date.now()) is not seen here; the layer rules stop the import of that helper.
  • A local declaration that shadows the global (const process = ...) is not reported.

ddd-ts-kit check looks for the same names with regular expressions. This rule is the authority: it knows a shadowed name from the global, and code from a string.