1.0.1 • Published 2 years ago

@chainlink/solhint-plugin-chainlink-solidity v1.0.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Chainlink Solhint Rules

A set of Solhint rules for Chainlink's Solidity Style Guide.

You can find a working Foundry example here.

Install to a new project

npm init && npm install solhint solhint-plugin-chainlink-solidity@npm:@chainlink/solhint-plugin-chainlink-solidity --save

Create a .solhint.json in your root project directory:

{
  "extends": "solhint:recommended",
  "plugins": ["chainlink-solidity"],
  "rules": {
    "compiler-version": ["off", "^0.7.0"],
    "const-name-snakecase": "off",
    "constructor-syntax": "error",
    "var-name-mixedcase": "off",
    "func-visibility": [
      "error",
      {
        "ignoreConstructors": true
      }
    ],
    "max-line-length": ["error", 160],
    "not-rely-on-time": "off",
    "no-empty-blocks": "off",
    "quotes": ["error", "single"],
    "reason-string": [
      "warn",
      {
        "maxLength": 64
      }
    ],
    "chainlink-solidity/prefix-internal-functions-with-underscore": "warn",
    "chainlink-solidity/prefix-private-functions-with-underscore": "warn",
    "chainlink-solidity/prefix-storage-variables-with-s-underscore": "warn",
    "chainlink-solidity/prefix-immutable-variables-with-i": "warn",
    "chainlink-solidity/all-caps-constant-storage-variables": "warn",
    "chainlink-solidity/no-hardhat-imports": "warn",
    "chainlink-solidity/inherited-constructor-args-not-in-contract-definition": "warn",
    "chainlink-solidity/explicit-imports": "warn",
    "chainlink-solidity/no-require-statements": "warn",
    "chainlink-solidity/no-block-single-if-reverts": "warn"
  }
}

Add the following to your package.json:

  "scripts": {
    "solhint": "solhint --config .solhint.json \"src/*.sol\""
  },

Then, run:

npm solhint

src/Counter.sol
  4:1  warning  Internal function increment is not prefixed with underscore (_)  chainlink-solidity/prefix-internal-functions-with-underscore
  4:1  warning  Private / internal variable number is not prefixed with s_       chainlink-solidity/prefix-storage-variables-with-s-underscore
  8:9  warning  Use custom errors instead of revert statements                   chainlink-solidity/no-require-statements
  8:9  warning  Provide an error message for require                             reason-string

Rules

Rule IdDescription
prefix-internal-functions-with-underscoreNaming convention
prefix-private-functions-with-underscoreNaming convention
prefix-storage-variables-with-s-underscoreNaming convention
prefix-immutable-variables-with-iNaming convention
all-caps-constant-storage-variablesNaming convention
no-hardhat-importsLeftover hardhat/*.sol imports not allowed
inherited-constructor-args-not-in-contract-definitionInherited contract constructor arguments should be specified in the constructor block
explicit-importsimport {Foo} from 'Foo.sol'
no-require-statementsUse custom errors instead
no-block-single-if-revertsOmit curly braces for single-line guard clauses