close

no-unreadable-new-expression

Added in v0.9.1

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-unreadable-new-expression': 'error',
    },
  },
]);

Rule Details

Disallow accessing a member directly from a new expression and disallow complex expressions as constructors. Keeping construction separate from later member access avoids JavaScript's precedence-sensitive new syntax.

Examples of incorrect code for this rule:

const timestamp = new Date().getTime();
const value = new (factory().Constructor)();
const item = new constructors[Kind]();

Examples of correct code for this rule:

const date = new Date();
const timestamp = date.getTime();

const { Constructor } = factory();
const value = new Constructor();

const ConstructorForKind = constructors[Kind];
const item = new ConstructorForKind();

Identifier constructors and static member constructors such as new Namespace.Constructor() are allowed.

Original Documentation