New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@putout/plugin-math

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/plugin-math

🐊Putout plugin helps with Math

  • 3.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@putout/plugin-math NPM version

🐊Putout plugin helps with Math.

Install

npm i @putout/plugin-math -D

Rules

{
    "rules": {
        "math/apply-exponentiation": "on",
        "math/apply-multiplication": "on",
        "math/apply-numeric-separators": "on",
        "math/convert-sqrt-to-hypot": "on",
        "math/declare": "on",
        "math/remove-unchanged-zero-declarations": "on"
    }
}

convert-sqrt-to-hypot

The Math.hypot() function returns the square root of the sum of squares of its arguments.

(c) MDN

Convert Math.sqrt() to Math.hypot(). Check out in 🐊Putout Editor.

❌ Example of incorrect code

Math.sqrt(a ** 2, b ** 2);

✅ Example of correct code

Math.hypot(a, b);

apply-exponentiation

  • The Math.pow() static method, given two arguments, base and exponent, returns baseexponent.
  • The exponentiation operator (**) returns the result of raising the first operand to the power of the second operand. It is equivalent to Math.pow, except it also accepts BigInts as operands.

(c) MDN

❌ Example of incorrect code

Math.pow(2, 4);

✅ Example of correct code

2 ** 4;

Comparison

LinterRuleFix
🐊 Putoutconvert-math-pow
ESLintprefer-exponentiation-operator

apply-multiplication

Multiplying two numbers stored internally as integers (which is only possible with AsmJS with imul is the only potential circumstance where Math.imul() may prove performant in current browsers.

(c) MDN

Check out in 🐊Putout Editor.

❌ Example of incorrect code

const a = Math.imul(b, c);

✅ Example of correct code

const a = b * c;

apply-numeric-separators

To improve readability for numeric literals, underscores (_) can be used as separators.

(c) MDN

❌ Example of incorrect code

const t = 10000000;

✅ Example of correct code

const t = 10_000_000;

declare

The Math.round() static method returns the value of a number rounded to the nearest integer.

(c) MDN

❌ Example of incorrect code

round(bLength / aLength) > 3;

✅ Example of correct code

const {round} = Math;
round(bLength / aLength) > 3;

remove-unchanged-zero-declarations

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

for (let index = 0; index < n; index++) {
    const tokenDelta = 0;
    const templateDelta = 0;
    
    for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
        const currentTokenIndex = index + templateIndex - tokenDelta;
        const currentToken = tokens[currentTokenIndex];
        
        end = currentTokenIndex + tokenDelta;
    }
}

✅ Example of correct code

for (let index = 0; index < n; index++) {
    for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
        const currentTokenIndex = index + templateIndex;
        const currentToken = tokens[currentTokenIndex];
        
        end = currentTokenIndex;
    }
}

License

MIT

Keywords

FAQs

Package last updated on 03 Jan 2025

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