solhint-community

no-unused-vars

Recommended Badge Category Badge Default Severity Badge warn

The {“extends”: “solhint:recommended”} property in a configuration file enables this rule.

Description

Ensure defined names are used

Options

This rule accepts a string option of rule severity. Must be one of “error”, “warn”, “off”. Default to warn.

Example Config

{
  "rules": {
    "no-unused-vars": "warn"
  }
}

Examples

👍 Examples of correct code for this rule

imported name is used


            import {A} from './A.sol';
            contract Foo is A{ }
            

defined stack variable is used


      pragma solidity 0.4.4;
        
        
      contract A {
        function fun(uint a) public { uint b = bytes32(a); b += 1; }
      }
    

note: function parameters of functions with empty blocks are not checked


      pragma solidity 0.4.4;
        
        
      contract A {
        function fun(uint d) public returns (uint c) { }
      }
    

note: function parameters of functions without blocks are not checked


      pragma solidity 0.4.4;
        
        
      contract A {
        function fun(uint a, uint b) public returns (uint c);
      }
    

note: state variables are not checked


      pragma solidity 0.4.4;
        
        
      contract A {
        uint public foo;
      }
    

👎 Examples of incorrect code for this rule

imported name is not used


            import {A} from './A.sol';
            contract Foo { }
            

stack variable is not used


      pragma solidity 0.4.4;
        
        
      contract A {
        
        function b() public {
          uint a = 0;
        }
    
      }
    

function parameter is not used


      pragma solidity 0.4.4;
        
        
      contract A {
        function fun(uint a) public returns (uint){ return 42; }
      }
    

Version

This rule was introduced in Solhint 1.1.5

Resources