close

no-redeclare

Configuration

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

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

Rule Details

This rule disallows declaring the same variable more than once in the same scope.

Examples of incorrect code for this rule:

var a = 3;
var a = 10;
function a() {}
function a() {}

Examples of correct code for this rule:

var a = 3;
var b = function () {
  var a = 10;
};
if (foo) {
  let a = 1;
} else {
  let a = 2;
}

Options

builtinGlobals (default: true)

When true, this rule reports redeclarations of ECMAScript built-in globals. Configured languageOptions.globals also participate as built-ins. Active /* global */ directives participate as declarations in either mode; a final :off setting removes that inline global.

{ "no-redeclare": ["error", { "builtinGlobals": true }] }
var Object = 0;

Set builtinGlobals to false to allow redeclaring built-in global names.

{ "no-redeclare": ["error", { "builtinGlobals": false }] }
var Object = 0;

Original Documentation