close

no-unused-expressions

Configuration

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

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

Rule Details

Disallow expression statements that do not affect program state.

Examples of incorrect code for this rule:

0;

a;

foo.bar;

a ? b() : c;

tag`template`;

Examples of correct code for this rule:

a = b;

new Foo();

foo();

delete foo.bar;

void foo();

Options

This rule has an object option:

  • allowShortCircuit (default: false): allow short-circuit expressions when the right-hand side has an accepted side effect.
  • allowTernary (default: false): allow ternary expressions when both branches have accepted side effects.
  • allowTaggedTemplates (default: false): allow tagged template expression statements.
  • enforceForJSX (default: false): report unused JSX expression statements.
  • ignoreDirectives (default: false): accepted for ESLint config compatibility; directive prologues are always allowed in rslint.

Examples of correct code for this rule with { "allowShortCircuit": true }:

{ "no-unused-expressions": ["error", { "allowShortCircuit": true }] }
condition && doSomething();

Examples of correct code for this rule with { "allowTernary": true }:

{ "no-unused-expressions": ["error", { "allowTernary": true }] }
condition ? doSomething() : doSomethingElse();

Examples of correct code for this rule with { "allowTaggedTemplates": true }:

{ "no-unused-expressions": ["error", { "allowTaggedTemplates": true }] }
tag`template`;

Examples of incorrect code for this rule with { "enforceForJSX": true }:

{ "no-unused-expressions": ["error", { "enforceForJSX": true }] }
<div />;

Original Documentation