close

no-with

Configuration

PresetConfigured Value
✅ js.configs.recommended"error"
rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-with': 'error',
    },
  },
]);

Rule Details

Disallow with statements.

The with statement is potentially problematic because it adds members of an object to the current scope, making it impossible to tell what a variable inside the block actually refers to. In strict mode, with statements are not allowed at all.

Examples of incorrect code for this rule:

with (point) {
  r = Math.sqrt(x * x + y * y); // is r a member of point?
}

Examples of correct code for this rule:

const r = Math.sqrt(point.x * point.x + point.y * point.y);

Original Documentation