Skip to content

Commit

Permalink
set no-global-import as recommended
Browse files Browse the repository at this point in the history
I haven't seen global imports on recent codebases, and they're
[recommended against](https://docs.soliditylang.org/en/v0.8.17/layout-of-source-files.html#importing-other-source-files)
in the solidity documentation, so I think it's reasonable to have the
rule as recommended
  • Loading branch information
juanpcapurro committed Feb 8, 2023
1 parent 2fa6418 commit f371bad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/rules.md
Expand Up @@ -14,7 +14,7 @@ title: "Rule Index of Solhint"
| [max-states-count](./rules/best-practises/max-states-count.md) | Contract has "some count" states declarations but allowed no more than maxstates. | ✔️ |
| [no-console](./rules/best-practises/no-console.md) | No console.log/logInt/logBytesX/logString/etc & No hardhat and forge-std console.sol import statements | ✔️ |
| [no-empty-blocks](./rules/best-practises/no-empty-blocks.md) | Code contains empty block. | ✔️ |
| [no-global-import](./rules/best-practises/no-global-import.md) | Import statement includes an entire file instead of selected symbols | |
| [no-global-import](./rules/best-practises/no-global-import.md) | Import statement includes an entire file instead of selected symbols | ✔️ |
| [no-unused-vars](./rules/best-practises/no-unused-vars.md) | Variable "name" is unused. | ✔️ |
| [payable-fallback](./rules/best-practises/payable-fallback.md) | When fallback is not payable you will not be able to receive ethers. | ✔️ |
| [reason-string](./rules/best-practises/reason-string.md) | Require or revert statement must have a reason string and check that each reason string is at most N characters long. | ✔️ |
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/best-practises/no-global-import.md
Expand Up @@ -5,8 +5,11 @@ title: "no-global-import | Solhint"
---

# no-global-import
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practise%20Rules-informational)
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)
> The {"extends": "solhint:recommended"} property in a configuration file enables this rule.

## Description
Import statement includes an entire file instead of selected symbols
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/best-practises/no-global-import.js
Expand Up @@ -17,7 +17,7 @@ const meta = {
},

isDefault: false,
recommended: false,
recommended: true,
defaultSetup: 'warn',

schema: null,
Expand Down
10 changes: 10 additions & 0 deletions test/rules/best-practises/no-global-import.js
Expand Up @@ -27,6 +27,16 @@ describe('Linter - no-global-import', () => {
assertErrorMessage(report, 'global import')
assertErrorMessage(report, 'Specify names to import individually')
})
it('should raise warning when using solhint:recommended', () => {
const code = `pragma solidity ^0.5.8; import "./A.sol";`

const report = linter.processStr(code, {
extends: 'solhint:recommended',
})
assertWarnsCount(report, 1)
assertErrorMessage(report, 'global import')
assertErrorMessage(report, 'Specify names to import individually')
})
it('should report correct line', () => {
const code = `import {A} from './A.sol';
import './A.sol';`
Expand Down

0 comments on commit f371bad

Please sign in to comment.