ESLint plugin that enforces importing BigNumber from 'bignumber.js' (prevents relying on a global BigNumber).
npm install eslint-plugin-no-global-bignumberThis 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
* Enforces that BigNumber must be explicitly imported from bignumber.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 --fix or eslint extension).
- ESLint: 8.x and 9.x (see peerDependencies). The rule uses only APIs supported in both versions (getSourceCode(), report({ loc, messageId, fix }), fixer.insertTextBeforeRange()).
See DEVELOPMENT.md for setup, scripts, tests, and how to try the plugin locally before publishing.
``bash`
npm i -D eslint-plugin-no-global-bignumber
`js
// eslint.config
import noGlobalBigNumber from 'eslint-plugin-no-global-bignumber'
export default [
{
plugins: {
'no-global-bignumber': noGlobalBigNumber,
},
rules: {
'no-global-bignumber/require-import': 'error',
},
},
]
`
`json`
{
"plugins": ["no-global-bignumber"],
"rules": {
"no-global-bignumber/require-import": "error"
}
}
- Reports when BigNumber is used but not imported from bignumber.js.import { BigNumber } from 'bignumber.js';
- Autofix: adds the missing import () when you run ESLint with --fix`.