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

feat: add solhint #19

Merged
merged 11 commits into from
Jan 11, 2024
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Hub of all open-sourced third-party static analyzers supported by DeepSource.
| :---------------------------------------------------------------------------- | :------------- | :--------------------- |
| [Azure/bicep](https://github.com/Azure/bicep) | v0.20.4 | Azure Resource Manager |
| [stackrox/kube-linter](https://github.com/stackrox/kube-linter) | 0.6.4 | Kubernetes, Helm |
| [crytic/slither](https://github.com/crytic/slither) | 0.10.0 | Solidity, Vyper |
| [aws-cloudformation/cfn-lint](https://github.com/aws-cloudformation/cfn-lint) | 0.83.3 | AWS CloudFormation |
| [dart-lang/linter](https://github.com/dart-lang/sdk/tree/main/pkg/linter) | 3.2.0 | Dart, Flutter |
| [crytic/slither](https://github.com/crytic/slither) | 0.10.0 | Solidity, Vyper |
| [protofire/solhint](https://github.com/protofire/solhint) | 0.10.0 | Solidity |

---

Expand Down
7 changes: 7 additions & 0 deletions analyzers/solhint/.deepsource/analyzer/analyzer.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Analyzer Profile
category = "lang"
name = "Solhint"
shortcode = "solhint"
status = "active"
tool_latest_version = "4.0.0" # TODO(@eshaan): fixme
description = "Open source project for linting solidity code by Protofire. This project provides both security and style guide validations."
5 changes: 5 additions & 0 deletions analyzers/solhint/.deepsource/analyzer/example_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version = 1

[[analyzers]]
name = "solhint"
type = "community"
49 changes: 49 additions & 0 deletions analyzers/solhint/.deepsource/analyzer/logo.svg
eshaan-deepsource marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions analyzers/solhint/.deepsource/analyzer/silencers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"extension": ".sol$",
"comment_identifier": "//"
}
]
44 changes: 44 additions & 0 deletions analyzers/solhint/.deepsource/issues/SOLHINT-W1001.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
title = "Function has cyclomatic complexity `current` but allowed no more than maxcompl"
eshaan-deepsource marked this conversation as resolved.
Show resolved Hide resolved
verbose_name = "code-complexity"
severity = "minor"
category = "antipattern"
weight = 40
description = """
Function has cyclomatic complexity `current` but allowed no more than maxcompl.
eshaan-deepsource marked this conversation as resolved.
Show resolved Hide resolved

<!--more-->

## Bad Practice
1. High code complexity
```solidity
if (a > b) {
if (b > c) {
if (c > d) {
if (d > e) {
} else {
}
}
}
}
for (i = 0; i < b; i += 1) { }
do { d++; } while (b > c);
while (d > e) { }
```

## Recommended
1. Low code complexity
```solidity
if (a > b) {
if (b > c) {
if (c > d) {
}
}
}
for (i = 0; i < b; i += 1) { }
do { d++; } while (b > c);
while (d > e) { }
```

## Learn more
[code-complexity](https://github.com/protofire/solhint/blob/develop/docs/rules/best-practises/code-complexity.md) on Solhint's documentation.
"""
40 changes: 40 additions & 0 deletions analyzers/solhint/.deepsource/issues/SOLHINT-W1002.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
title = "Enforces the use of Custom Errors over Require and Revert statements"
verbose_name = "custom-errors"
severity = "minor"
category = "antipattern"
weight = 40
description = """
Enforces the use of Custom Errors over Require and Revert statements

<!--more-->

## Bad Practice
1. Use of require statement
```solidity
require(userBalance >= availableAmount, "Insufficient Balance");
```

2. Use of plain revert statement
```solidity
revert();
```

3. Use of revert statement with message
```solidity
revert("Insufficient Balance");
```

## Recommended
1. Use of Custom Errors
```solidity
revert CustomErrorFunction();
```

2. Use of Custom Errors with arguments
```solidity
revert CustomErrorFunction({ msg: "Insufficient Balance" });
```

## Learn more
[custom-errors](https://github.com/protofire/solhint/blob/develop/docs/rules/best-practises/custom-errors.md) on Solhint's documentation.
"""
45 changes: 45 additions & 0 deletions analyzers/solhint/.deepsource/issues/SOLHINT-W1003.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
title = "Forbid or enforce explicit types (like uint256) that have an alias (like uint)"
verbose_name = "explicit-types"
severity = "minor"
category = "antipattern"
weight = 40
description = """
Forbid or enforce explicit types (like uint256) that have an alias (like uint).

<!--more-->

## Bad Practice
1. If explicit is selected
```solidity
uint public variableName
```

2. If implicit is selected
```solidity
uint256 public variableName
```

3. At any setting
```solidity
uint public variableName = uint256(5)
```

## Recommended
1. If explicit is selected
```solidity
uint256 public variableName
```

2. If implicit is selected
```solidity
uint public variableName
```

3. If explicit is selected
```solidity
uint256 public variableName = uint256(5)
```

## Learn more
[explicit-types](https://github.com/protofire/solhint/blob/develop/docs/rules/best-practises/explicit-types.md) on Solhint's documentation.
"""
13 changes: 13 additions & 0 deletions analyzers/solhint/.deepsource/issues/SOLHINT-W1004.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title = "Function body contains `count` lines but allowed no more than maxlines"
eshaan-deepsource marked this conversation as resolved.
Show resolved Hide resolved
verbose_name = "function-max-lines"
severity = "minor"
category = "antipattern"
weight = 40
description = """
Function body contains `count` lines but allowed no more than maxlines.
eshaan-deepsource marked this conversation as resolved.
Show resolved Hide resolved

<!--more-->

## Learn more
[function-max-lines](https://github.com/protofire/solhint/blob/develop/docs/rules/best-practises/function-max-lines.md) on Solhint's documentation.
"""
13 changes: 13 additions & 0 deletions analyzers/solhint/.deepsource/issues/SOLHINT-W1005.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title = "Line length must be no more than maxlen"
verbose_name = "max-line-length"
severity = "major"
category = "antipattern"
weight = 60
description = """
Line length must be no more than maxlen.

<!--more-->

## Learn more
[max-line-length](https://github.com/protofire/solhint/blob/develop/docs/rules/best-practises/max-line-length.md) on Solhint's documentation.
"""
73 changes: 73 additions & 0 deletions analyzers/solhint/.deepsource/issues/SOLHINT-W1006.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
title = "Contract has `some count` states declarations but allowed no more than maxstates"
verbose_name = "max-states-count"
severity = "minor"
category = "antipattern"
weight = 40
description = """
Contract has `some count` states declarations but allowed no more than maxstates.

<!--more-->

## Bad Practice
1. High number of states
```solidity

pragma solidity 0.4.4;


contract A {
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
}

```

## Recommended
1. Low number of states
```solidity

pragma solidity 0.4.4;


contract A {
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private a;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
uint private constant TEST = 1;
}

```

## Learn more
[max-states-count](https://github.com/protofire/solhint/blob/develop/docs/rules/best-practises/max-states-count.md) on Solhint's documentation.
"""
Loading