Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-redundant-undefined

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-redundant-undefined

ESlint rule for disallow redundant undefined

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26K
increased by12.85%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-redundant-undefined

Forbids optional parameters to include an explicit undefined in their type and requires to use undefined in optional properties.

GitHub license npm version GitHub Workflow Status (with branch) Coverage Status npm downloads

Installation

$ npm i eslint-plugin-redundant-undefined @typescript-eslint/parser --save-dev

Usage

Add redundant-undefined to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["redundant-undefined"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "redundant-undefined/redundant-undefined": "error"
  }
}

Rule Details

  • Avoid explicitly specifying undefined as a type for a parameter/property which is already optional

Options

  • followExactOptionalPropertyTypes - Requires explicitly specifying undefined as a type for a parameter which is already optional., this provides the correct semantics for people who have exactOptionalPropertyType: true

Examples

Examples of incorrect code:

function f(s?: undefined | string): void {}

function f(s?: number | undefined | string): void {}

interface I {
  a?: string | undefined;
}

class C {
  a?: string | undedined;
}

Examples of correct code:

function f(s?: string): void {}

interface I {
  a?: string;
}

interface I {
  a?: any;
}

class C {
  a?: string;
}

Examples of incorrect code for the { "followExactOptionalPropertyTypes": true }:

interface I {
  p?: string;
}

class C {
  private p?: number;
}

abstract class C {
  abstract p?: string;
}

Examples of correct code for the { "followExactOptionalPropertyTypes": true }:

interface I {
  p?: string | undefined;
}

interface I {
  p?: any;
}

class C {
  private p?: number | undefined;
}

abstract class C {
  abstract p?: string | undefined;
}

This software is released under the terms of the MIT license.

Keywords

FAQs

Package last updated on 07 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc