Skip to content

math/prefer-math-pi

enforce the use of Math.PI instead of literal number

  • ⚙️ This rule is included in "plugin:math/recommended".
  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

📖 Rule Details

This rule aims to enforce the use of Math.PI instead of literal number representations of π (pi).

Using Math.PI instead of hardcoded numeric literals improves:

  • Readability: Makes the intention clear that you're using the mathematical constant π
  • Maintainability: Centralized definition reduces the risk of typos
  • Precision: Math.PI provides the most accurate representation available in JavaScript
  • Consistency: Standardizes how mathematical constants are used across your codebase
Now loading...

🔧 Options

Nothing.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-math v0.5.0

🔍 Implementation