Skip to content

Commit d4d6363

Browse files
Merge pull request #678 from protofire/config-multiple-folders
feat: config in multiple dirs
2 parents 8a22d3c + 82d3207 commit d4d6363

File tree

18 files changed

+864
-94
lines changed

18 files changed

+864
-94
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Options:
6262
-V, --version output the version number
6363
-f, --formatter [name] report formatter name (stylish, table, tap, unix, json, compact, sarif)
6464
-w, --max-warnings [maxWarningsNumber] number of allowed warnings, works in quiet mode as well
65-
-c, --config [file_name] file to use as your .solhint.json
65+
-c, --config [file_name] file to use as your rules configuration file (not compatible with multiple configs)
6666
-q, --quiet report errors only - default: false
6767
--ignore-path [file_name] file to use as your .solhintignore
6868
--fix automatically fix problems and show report
@@ -111,9 +111,37 @@ This file has the following format:
111111
"extends": "solhint:recommended"
112112
}
113113
```
114-
### Note
114+
### Note 1
115115
The `solhint:default` configuration contains only two rules: max-line-length & no-console
116116
It is now deprecated since version 5.1.0
117+
<br>
118+
119+
### Note 2
120+
Multiple configs files can be used at once. All config files should be named `.solhint.json`.
121+
If not done like this, multiple hierarchy configuration will not work.
122+
Solhint will go though all config files automatically.
123+
124+
Given this structure:
125+
```
126+
Project ROOT =>
127+
/contracts
128+
---> RootAndContractRules.sol
129+
---> .solhint.json
130+
131+
/src
132+
--->RootRules.sol
133+
--->interfaces/
134+
------->InterfaceRules.sol
135+
------->solhint.json
136+
137+
.solhint.json
138+
```
139+
- Solhint config located on `root` will be the main one.
140+
- When analyzing `RootRules.sol`, `root` file config will be used that file.
141+
- `InterfaceRules.sol` will be using the one inside its own folder taking precedence over the `root` folder one.
142+
- Rules not present in `interfaces/` folder and present in `root` will be active.
143+
- Rules not present in `root` folder and present in `interfaces/` folder will be active.
144+
- If rule is present in both files, the closest to the analyzed file will take precedence. Meaning when analyzing `InterfaceRules.sol` the config file located in `Interfaces/` will be used with the remaining rules of the `root` one.
117145
<br><br>
118146

119147

docs/rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ title: "Rule Index of Solhint"
9898

9999
## References
100100

101-
- [ConsenSys Guide for Smart Contracts](https://consensysdiligence.github.io/smart-contract-best-practices/development-recommendations/)
101+
- [ConsenSys Guide for Smart Contracts](https://consensys.github.io/smart-contract-best-practices/development-recommendations/)
102102
- [Solidity Style Guide](http://solidity.readthedocs.io/en/develop/style-guide.html)

docs/rules/miscellaneous/duplicated-imports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This rule accepts a string option for rule severity. Must be one of "error", "wa
3333
This rule does not have examples.
3434

3535
## Version
36-
This rule was introduced in the latest version.
36+
This rule was introduced in [Solhint 5.1.0](https://github.com/protofire/solhint/blob/v5.1.0)
3737

3838
## Resources
3939
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/miscellaneous/duplicated-imports.js)

docs/rules/miscellaneous/import-path-check.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This rule accepts an array of options:
5858
This rule does not have examples.
5959

6060
## Version
61-
This rule was introduced in the latest version.
61+
This rule was introduced in [Solhint 5.1.0](https://github.com/protofire/solhint/blob/v5.1.0)
6262

6363
## Resources
6464
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/miscellaneous/import-path-check.js)

docs/rules/naming/imports-order.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This rule accepts a string option for rule severity. Must be one of "error", "wa
3535
This rule does not have examples.
3636

3737
## Version
38-
This rule was introduced in the latest version.
38+
This rule was introduced in [Solhint 5.1.0](https://github.com/protofire/solhint/blob/v5.1.0)
3939

4040
## Resources
4141
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/order/imports-order.js)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rules": {
3+
"compiler-version": "off",
4+
"quotes": ["error", "double"],
5+
"no-console": "error"
6+
}
7+
}
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"rules": {
3+
"quotes": ["error", "single"],
4+
"compiler-version": "off"
5+
}
6+
}
7+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.0;
3+
4+
contract RootAndContractRules {
5+
string public test = 'this one should NOT fail';
6+
7+
constructor() {
8+
9+
console.log("error on no-console");
10+
}
11+
}
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.0;
3+
4+
contract RootRules {
5+
string public test = 'this one should fail';
6+
7+
constructor() {
8+
9+
console.log("error on no-console");
10+
}
11+
}
12+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"rules": {
3+
"compiler-version": "off",
4+
"quotes": ["error", "single"],
5+
"no-console": "off",
6+
"no-empty-blocks": "error"
7+
}
8+
}
9+

0 commit comments

Comments
 (0)