Giter Site home page Giter Site logo

eslint-plugin-o1js's Introduction

eslint-plugin-o1js

o1js rules for ESLint to detect bugs and invalid patterns in your Smart Contract code.

Rules

  • The maximum allowed state variables in a Smart Contract is 8
  • Throw statements should not be used in a Circuit method
  • If statements should not be used in a Circuit method
  • Ternary statements should not be used in a Circuit method
  • JavaScript JSON functions should not be used in a Circuit method
  • JavaScript random functions should not be used in a Circuit method
  • Overriding the constructor in a SmartContract is disallowed

Installation

# npm
npm install eslint-plugin-o1js --save-dev

# yarn
yarn add eslint-plugin-o1js --dev

Add eslint-plugin-o1js to the plugins option in your eslint config:

{
  "plugins": ["o1js"]
}
  • Then extend the recommended eslint config:
{
  extends: ['plugin:o1js/recommended'],
}
  • You can enable specific rules manually:
{
  "rules": {
    "o1js/no-greater-storage-limit-in-circuit": "error",
    "o1js/no-throw-in-circuit": "error"
    ...
  }
}
  • An example ESLint configuration looks like:
module.exports = {
  parser: '@typescript-eslint/parser',
  plugins: ['o1js'],
  extends: ['plugin:o1js/recommended'],
};

Valid and Invalid Examples

Please refer to the project tests to learn more about the usage of the rules.

eslint-plugin-o1js's People

Contributors

martinminkov avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

eslint-plugin-o1js's Issues

"snarkyjs/no-greater-storage-limit-in-circuit" crashes

Crash experienced here: https://github.com/jackryanservia/mastermind
on this version of the source file: https://github.com/jackryanservia/mastermind/blob/2fdf3f6b7f8f09edf29a2c87c7f464c59782d629/src/Mastermind-recursive.ts

Oops! Something went wrong! :(

ESLint: 8.7.0

TypeError: Cannot read properties of undefined (reading 'size')
Occurred while linting /home/gregor/o1/mastermind/src/Mastermind-recursive.ts:37
Rule: "snarkyjs/no-greater-storage-limit-in-circuit"
    at Object.enter (/home/gregor/o1/mastermind/node_modules/eslint-plugin-snarkyjs/build/src/rules/no-greater-storage-limit-in-circuit.js:110:91)
    at SimpleTraverser.traverse (/home/gregor/o1/mastermind/node_modules/@typescript-eslint/typescript-estree/dist/simple-traverse.js:28:28)
    at SimpleTraverser.traverse (/home/gregor/o1/mastermind/node_modules/@typescript-eslint/typescript-estree/dist/simple-traverse.js:41:26)
    at SimpleTraverser.traverse (/home/gregor/o1/mastermind/node_modules/@typescript-eslint/typescript-estree/dist/simple-traverse.js:45:22)
    at simpleTraverse (/home/gregor/o1/mastermind/node_modules/@typescript-eslint/typescript-estree/dist/simple-traverse.js:51:53)
    at ClassDeclaration:has(Identifier[name="CircuitValue"]) (/home/gregor/o1/mastermind/node_modules/eslint-plugin-snarkyjs/build/src/rules/no-greater-storage-limit-in-circuit.js:101:56)
    at ruleErrorHandler (/home/gregor/o1/mastermind/node_modules/eslint/lib/linter/linter.js:1079:28)
    at /home/gregor/o1/mastermind/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/gregor/o1/mastermind/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
husky - pre-commit hook exited with code 1 (error)

[BUG] - no-greater-storage-limit-in-circuit rule does not count state for transitive CircuitValues

Description
When users define @state in a Smart Contract that is defined on a CircuitValue and that CircuitValue that is defined in another CircuitValue, the state counting algorithm does not work.
A -> B -> C

Minimal code to reproduce

class C extends CircuitValue {
    @prop prop1: Field;
    @prop prop2: Field;

}
class B extends CircuitValue {
    @arrayProp(C, 1) values: C[];
}
class A extends SmartContract {
    @state(B) state1: State<B>;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.