Various eslint rules I wrote to reduce bugs in my bitburner scripts.
Current TODOS:
- Require async functions (excluding main) to end with Async
- Require await before NS functions: hack, grow, weaken, sleep, prompt, wget, scp, write, writePort
- Require await before async functions (functions ending with Async)
- Require guards
- Require that js files export a function with their filename
- Automatically fix js files that are missing a function with their filename
- Automatically add guard statements
- Require constants in constants.js to use SCREAMING_SNAKE_CASE
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-bitburning
:
npm install eslint-plugin-bitburning --save-dev
Add bitburning
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"bitburning"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"bitburning/rule-name": 2
}
}
Requires that functions ending in Async are awaited. I know there's a lot more you can do with promises besides awaiting them, but in the context of bitburner it's rare.
Requires that ns functions that return promises are awaited. Since the game makes that mandatory.
Requires that a file define a function or class that matches its filename.
Requires that async functions end with Async. This helps prevent dangling promises as we're not using typescript.
Requires that all arguments without default values are checked for undefined. This helps prevent errors when you call functions with the wrong number of arguments.