You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

eslint-plugin-use-numeric-separator

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-use-numeric-separator

An ESLint plugin to enforce usage of the numeric separator for long numeric literals

3.0.0
latest
Source
npm
Version published
Weekly downloads
7
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-use-numeric-separator

use-numeric-separator is an ESLint plugin to enforce usage of the numeric separator (that '_' that can go in the middle of numbers) for large numbers.

// Hard to read:
10000000
// Easy to read:
10_000_000

This plugin has support for decimal, hexadecimal, octal, and binary literals, and has separate configurable options for each base to specify the threshold at which to start applying the rule, and the number of digits per group.

With default options:

// Incorrect:
10000000
0xDEADBEEF
0b10101010

// Correct:
10_000_000
0xDE_AD_BE_EF
0b1010_1010

// Also correct:
1000 // short number
100.0000001 // decimals are not split
6.02214e+23 // scientific notation is ignored

Options

Each base has its own rule with threshold and groupSize options, with defaults. threshold is the number of digits above which the rule should apply, and groupSize is the number of digits between each separator. Here is an example .eslintrc.json with every rule on and set to the default values:

{
  ...
  "rules": {
    "use-numeric-separator/decimal": [
      "error",
      {
        "threshold": 5,
        "groupSize": 3
      }
    ],
    "use-numeric-separator/hexadecimal": [
      "error",
      {
        "threshold": 7,
        "groupSize": 2
      }
    ],
    "use-numeric-separator/binary": [
      "error",
      {
        "threshold": 5,
        "groupSize": 4
      }
    ],
    "use-numeric-separator/octal": [
      "error",
      {
        "threshold": 5,
        "groupSize": 3
      }
    ]
  }
}

Keywords

eslint

FAQs

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