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

eslint-plugin-unary-minus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-unary-minus

A typescript-eslint plugin restricting unary negation to numbers.

  • 0.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-unary-minus npm license Build

DEPRECATION NOTICE: This plugin is no longer necessary as of typescript-eslint v6.14.0. Use the @typescript-eslint/no-unsafe-unary-minus rule instead of this package.


A typescript-eslint plugin restricting unary negation to numbers. Requires TypeScript v5.1+.

As explained on Stack Overflow, TypeScript does not prevent you from putting a minus sign before things other than numbers:

const f = (a: string) => -a; // OK
const g = (a: {}) => -a; // also OK

console.log(f("hi there")); // NaN
console.log(g({})); // NaN

This ESLint plugin catches that sort of bug by checking that every usage of unary negation has an argument with type assignable to number | bigint.

Installation

You'll first need to install ESLint, TypeScript, and typescript-eslint:

npm i --save-dev eslint typescript @typescript-eslint/eslint-plugin

Next, install eslint-plugin-unary-minus:

npm i --save-dev eslint-plugin-unary-minus

Usage

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

{
  "plugins": ["unary-minus"]
}

Then add this rule under the rules section.

{
  "rules": {
    "unary-minus/only-numbers": "error"
  }
}

Keywords

FAQs

Package last updated on 11 Dec 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