Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"no-unsed-vars" rule does not detect variable usage before declaration #79

Open
1 of 2 tasks
travs opened this issue Jun 13, 2017 · 0 comments
Open
1 of 2 tasks

Comments

@travs
Copy link

travs commented Jun 13, 2017

Example input:

contract Owned {
    function setOwner(address _new) onlyOwner { NewOwner(owner, _new); owner = _new; }

    address public owner = msg.sender;    // declare after use
}

Gives error:

Variable 'owner' is declared but never used

The contract compiles/executes fine, but Solium does not detect that the variable is used.

Solium does not give an error here (expected):

contract Owned {
    address public owner = msg.sender;    // declare before use
    function setOwner(address _new) onlyOwner { NewOwner(owner, _new); owner = _new; }
}

Proposal

  • Update no-unused-vars to detect usage before declaration (not error), and
  • add a rule like no-use-before-define, because using before defining is probably still not best practice, but is a separate problem from not defining. Another technique can be applied along with this - ignore vars that are declared public - they're obviously made for outside reading.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants