ESLint plugin providing rules for the CKB JavaScript VM environment. This plugin helps enforce best practices when developing on-chain scripts for the CKB blockchain using the ckb-js-vm runtime.
npm install --save-dev @ckb-js-std/eslint-plugin
Add @ckb-js-std
to the plugins section of your ESLint configuration:
// eslint.config.mjs
import { defineConfig } from "eslint/config";
import ckbJsStd from "@ckb-js-std/eslint-plugin";
export default defineConfig([
{
files: ["**/*.{js,ts}"],
plugins: { ckbJsStd },
extends: ["ckbJsStd/recommended"],
},
]);
Or manually configure rules:
// eslint.config.mjs
import ckbJsStd from "@ckb-js-std/eslint-plugin";
export default [
{
plugins: {
"@ckb-js-std": ckbJsStd,
},
rules: {
"@ckb-js-std/enforce-bindings-exit-main": "error",
"@ckb-js-std/no-mount-in-main": "error",
"@ckb-js-std/no-commonjs-modules": "error",
"@ckb-js-std/no-eval-js-script": "error",
},
},
];
Name | Description |
---|---|
enforce-bindings-exit-main | Enforce that index.ts (or index.js ) exits via a top-level bindings.exit(main()); call. |
no-mount-in-main | Disallow bindings.mount calls in main entry files (e.g., index.js , index.bc ). Suggest using init.js or init.bc instead. |
no-commonjs-modules | Disallow CommonJS module patterns (require , module.exports , exports.xxx ) as ckb-js-vm exclusively supports ECMAScript Modules (ESM). |
no-eval-js-script | Disallow the use of bindings.evalJsScript() due to significant security risks when loading code from untrusted sources. |
The ckb-js-vm environment has specific requirements that differ from traditional JavaScript applications:
- Module System: ckb-js-vm exclusively supports ECMAScript Modules (ESM) and does not support CommonJS
- File System Management: Mounting operations must be performed in initialization files to avoid race conditions
-
Exit Handling: Scripts need to properly terminate with the correct exit code using
bindings.exit(main())
-
Security Concerns: Dynamically loading code with
evalJsScript()
introduces significant security risks
Following these rules ensures that your on-chain scripts will run reliably in the CKB-VM environment.