Skip to content

mathMethods

Prefer modern Math methods over legacy patterns.

✅ This rule is included in the ts stylisticStrict presets.

ES2015 introduced several new Math methods that simplify common mathematical operations. Using these modern methods improves code readability and intent.

This rule flags legacy patterns that can be replaced with:

  • Math.log10(): Calculates the base-10 logarithm
  • Math.log2(): Calculates the base-2 logarithm
  • Math.hypot(): Calculates the Euclidean distance (square root of sum of squares)
  • Math.abs(): Returns the absolute value
const
const log10Value: number
log10Value
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.log(x: number): number

Returns the natural logarithm (base e) of a number.

@paramx A numeric expression.

log
(
const x: any
x
) *
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.LOG10E: number

The base-10 logarithm of e.

LOG10E
;
const
const log10Value: number
log10Value
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.log(x: number): number

Returns the natural logarithm (base e) of a number.

@paramx A numeric expression.

log
(
const x: any
x
) /
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.LN10: number

The natural logarithm of 10.

LN10
;
const
const log2Value: number
log2Value
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.log(x: number): number

Returns the natural logarithm (base e) of a number.

@paramx A numeric expression.

log
(
const x: any
x
) *
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.LOG2E: number

The base-2 logarithm of e.

LOG2E
;
const
const log2Value: number
log2Value
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.log(x: number): number

Returns the natural logarithm (base e) of a number.

@paramx A numeric expression.

log
(
const x: any
x
) /
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.LN2: number

The natural logarithm of 2.

LN2
;
const
const absolute: number
absolute
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.sqrt(x: number): number

Returns the square root of a number.

@paramx A numeric expression.

sqrt
(
const x: any
x
** 2);
const
const distance: number
distance
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.sqrt(x: number): number

Returns the square root of a number.

@paramx A numeric expression.

sqrt
(
const x: any
x
** 2 +
const y: any
y
** 2);

This rule is not configurable.

If you need to support JavaScript environments without ES2015 Math methods, you may need to disable this rule.

For projects with existing codebases that use these legacy patterns consistently, refactoring may not be worthwhile.

Made with ❤️‍🔥 around the world by the Flint team and contributors.