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

e2e tests added #513

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Changelog and docs for `no-empty-blocks` rule to clarify its functionality

### Added
- `fixShow` option to show report. `fix` option skips showing report on screen
- `fix` option now shows the report on screen
- `save` option to store report on disk with the standard or the specified format
- Check for updates on Solhint version to keep users with the last versin available. There's an option to disable this check (`--disc`)
- Autofix for `explicit-types` rule [504](https://github.com/protofire/solhint/pull/504)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ Options:
-c, --config [file_name] file to use as your .solhint.json
-q, --quiet report errors only - default: false
--ignore-path [file_name] file to use as your .solhintignore
--fix automatically fix problems. Skip report
--fixShow automatically fix problems. Show report
--fix automatically fix problems and show report
--noPrompt do not suggest to backup files when any `fix` option is selected
--init create configuration file for solhint
--disc do not check for solhint updates
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practises/explicit-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This rule accepts an array of options:
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` or `--fixShow` option
- Solhint allows this rule to automatically fix the code with `--fix` option

## Examples
### 👍 Examples of **correct** code for this rule
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/naming/private-vars-leading-underscore.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: "private-vars-leading-underscore | Solhint"
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)

## Description
Non-external functions and state variables should start with a single underscore. Others, shouldn't.
Non-external functions and state variables should start with a single underscore. Others, shouldn't

## Options
This rule accepts an array of options:
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/security/avoid-sha3.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` or `--fixShow` option
- Solhint allows this rule to automatically fix the code with `--fix` option

## Examples
This rule does not have examples.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/security/avoid-throw.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` or `--fixShow` option
- Solhint allows this rule to automatically fix the code with `--fix` option

## Examples
This rule does not have examples.
Expand Down
5 changes: 5 additions & 0 deletions e2e/08-autofix/commands/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"explicit-types": ["error", "explicit"]
}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/commands/Foo1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/commands/Foo1AfterFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint256 public hola;
uint256 public hola2;
int256 public constant hola3 = 2;
ufixed128x18 hola4;
fixed128x18 internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/commands/Foo1BeforeFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
5 changes: 5 additions & 0 deletions e2e/08-autofix/explicit-types/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"explicit-types": ["error", "explicit"]
}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/explicit-types/Foo1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/explicit-types/Foo1AfterFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint256 public hola;
uint256 public hola2;
int256 public constant hola3 = 2;
ufixed128x18 hola4;
fixed128x18 internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/explicit-types/Foo1BeforeFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
5 changes: 5 additions & 0 deletions e2e/08-autofix/no-console/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": "error"
}
}
37 changes: 37 additions & 0 deletions e2e/08-autofix/no-console/Foo1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pragma solidity 0.8.0;

import 'hardhat/console.sol';
import 'forge-std/console.sol';
import 'forge-std/console2.sol';
import 'forge-std/xxxxx.sol';

contract Foo1 {
Console[] public consoleTest;
Console[] public console;

struct Console {
uint256 one;
uint256 two;
}

function a() public {
console.log('test');
// comment
console.logString('test logString');
uint256 declaration;
console.logBytes12('test logBytes12');
}

function b() public {
console2.log('test console 2');
// comment
console.logString('test logString');
uint256 declaration;
console.logBytes12('test');
}

function c() external {
consoleTest.push(0, 0);
console.push = (1, 1);
}
}
37 changes: 37 additions & 0 deletions e2e/08-autofix/no-console/Foo1AfterFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pragma solidity 0.8.0;




import 'forge-std/xxxxx.sol';

contract Foo1 {
Console[] public consoleTest;
Console[] public console;

struct Console {
uint256 one;
uint256 two;
}

function a() public {

// comment

uint256 declaration;

}

function b() public {

// comment

uint256 declaration;

}

function c() external {
consoleTest.push(0, 0);
console.push = (1, 1);
}
}
37 changes: 37 additions & 0 deletions e2e/08-autofix/no-console/Foo1BeforeFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pragma solidity 0.8.0;

import 'hardhat/console.sol';
import 'forge-std/console.sol';
import 'forge-std/console2.sol';
import 'forge-std/xxxxx.sol';

contract Foo1 {
Console[] public consoleTest;
Console[] public console;

struct Console {
uint256 one;
uint256 two;
}

function a() public {
console.log('test');
// comment
console.logString('test logString');
uint256 declaration;
console.logBytes12('test logBytes12');
}

function b() public {
console2.log('test console 2');
// comment
console.logString('test logString');
uint256 declaration;
console.logBytes12('test');
}

function c() external {
consoleTest.push(0, 0);
console.push = (1, 1);
}
}
5 changes: 5 additions & 0 deletions e2e/08-autofix/private-vars-underscore/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"private-vars-leading-underscore": ["error",{"strict":false}]
}
}
Loading
Loading