eslint-plugin-no-global-bignumber
v1.0.0
Published
ESLint plugin that enforces importing BigNumber from 'bignumber.js' (prevents relying on a global BigNumber).
Readme
eslint-plugin-no-global-bignumber
This plugin prevents accidental reliance on a global BigNumber which can lead to runtime crashes when the global is missing. For example when imported in a typescript project.
Refer to these issues:
- Global namespace polluted in TypeScript projects
- Recommended modern way in TypeScript to import the library
What it does
- Enforces that
BigNumbermust be explicitly imported frombignumber.js(makes difference between type and value import). - The rule is fixable: when the import is missing, ESLint can add it for you (e.g. via
--fixor eslint extension).
Compatibility
- ESLint: 8.x and 9.x (see
peerDependencies). The rule uses only APIs supported in both versions (getSourceCode(),report({ loc, messageId, fix }),fixer.insertTextBeforeRange()).
Development
See DEVELOPMENT.md for setup, scripts, tests, and how to try the plugin locally before publishing.
Installation
npm i -D eslint-plugin-no-global-bignumberUsage
ESLint 9 (flat config)
// eslint.config
import noGlobalBigNumber from 'eslint-plugin-no-global-bignumber'
export default [
{
plugins: {
'no-global-bignumber': noGlobalBigNumber,
},
rules: {
'no-global-bignumber/require-import': 'error',
},
},
]ESLint 8 (.eslintrc)
{
"plugins": ["no-global-bignumber"],
"rules": {
"no-global-bignumber/require-import": "error"
}
}Rules
no-global-bignumber/require-import
- Reports when
BigNumberis used but not imported frombignumber.js. - Autofix: adds the missing import (
import { BigNumber } from 'bignumber.js';) when you run ESLint with--fix.
