0.2.4 • Published 2 years ago

eslint-plugin-unary-minus v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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"
  }
}
0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago