close

Require var declarations at the top of their scope (vars-on-top)

Unreleased

Configuration

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

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

The vars-on-top rule requires var declarations to appear before executable statements in the program or in a function body. Directive strings and imports may appear before the declarations. Declarations inside nested blocks and loop headers are reported; declarations at the start of a class static block are also allowed.

Rule Details

Examples of incorrect code:

function example() {
  doSomething();
  var value = 1;
}

Examples of correct code:

function example() {
  "use strict";
  var value = 1;
  doSomething(value);
}

Differences from ESLint

rslint applies the same rule behavior to JavaScript and TypeScript syntax. As with ESLint, the rule has no options and reports the complete declaration.