Skip to content

new rule: import-path-check #657

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

Merged
merged 19 commits into from
May 5, 2025
Merged
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
1 change: 1 addition & 0 deletions conf/rulesets/solhint-all.js
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ module.exports = Object.freeze({
'gas-struct-packing': 'warn',
'comprehensive-interface': 'warn',
'duplicated-imports': 'warn',
'import-path-check': ['warn', ['[~dependenciesPath]']],
quotes: ['error', 'double'],
'const-name-snakecase': 'warn',
'contract-name-capwords': 'warn',
1 change: 1 addition & 0 deletions conf/rulesets/solhint-recommended.js
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ module.exports = Object.freeze({
},
],
'gas-custom-errors': 'warn',
'import-path-check': ['warn', ['[~dependenciesPath]']],
quotes: ['error', 'double'],
'const-name-snakecase': 'warn',
'contract-name-capwords': 'warn',
11 changes: 3 additions & 8 deletions docs/rules.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ layout: "default"
title: "Rule Index of Solhint"
---

## Best Practice Rules
## Best Practices Rules

| Rule Id | Error | Recommended | Deprecated |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | ---------- |
@@ -21,6 +21,7 @@ title: "Rule Index of Solhint"
| [one-contract-per-file](./rules/best-practices/one-contract-per-file.md) | Enforces the use of ONE Contract per file see [here](https://docs.soliditylang.org/en/v0.8.21/style-guide.html#contract-and-library-names) | $~~~~~~~~$✔️ | |
| [payable-fallback](./rules/best-practices/payable-fallback.md) | When fallback is not payable and there is no receive function you will not be able to receive currency. | $~~~~~~~~$✔️ | |
| [reason-string](./rules/best-practices/reason-string.md) | Require or revert statement must have a reason string and check that each reason string is at most N characters long. | $~~~~~~~~$✔️ | |
| [constructor-syntax](./rules/best-practices/constructor-syntax.md) | Constructors should use the new constructor keyword. | | |


## Style Guide Rules
@@ -48,13 +49,6 @@ title: "Rule Index of Solhint"
| [visibility-modifier-order](./rules/order/visibility-modifier-order.md) | Visibility modifier must be first in list of modifiers. | $~~~~~~~~$✔️ | |


## Best Practices Rules

| Rule Id | Error | Recommended | Deprecated |
| ------------------------------------------------------------------ | ---------------------------------------------------- | ----------- | ---------- |
| [constructor-syntax](./rules/best-practices/constructor-syntax.md) | Constructors should use the new constructor keyword. | | |


## Gas Consumption Rules

| Rule Id | Error | Recommended | Deprecated |
@@ -76,6 +70,7 @@ title: "Rule Index of Solhint"
| Rule Id | Error | Recommended | Deprecated |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- |
| [comprehensive-interface](./rules/miscellaneous/comprehensive-interface.md) | Check that all public or external functions are overridden. This is useful to make sure that the whole API is extracted in an interface. | | |
| [import-path-check](./rules/miscellaneous/import-path-check.md) | Check if an import file exits in target path | $~~~~~~~~$✔️ | |
| [quotes](./rules/miscellaneous/quotes.md) | Enforces the use of double or simple quotes as configured for string literals. Values must be 'single' or 'double'. | $~~~~~~~~$✔️ | |


2 changes: 1 addition & 1 deletion docs/rules/best-practices/code-complexity.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ title: "code-complexity | Solhint"
---

# code-complexity
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%20Rules-informational)
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)

## Description
2 changes: 1 addition & 1 deletion docs/rules/best-practices/explicit-types.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "explicit-types | Solhint"

# explicit-types
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

2 changes: 1 addition & 1 deletion docs/rules/best-practices/function-max-lines.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ title: "function-max-lines | Solhint"
---

# function-max-lines
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%20Rules-informational)
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)

## Description
2 changes: 1 addition & 1 deletion docs/rules/best-practices/max-line-length.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ title: "max-line-length | Solhint"
---

# max-line-length
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%20Rules-informational)
![Default Severity Badge error](https://img.shields.io/badge/Default%20Severity-error-red)
> The {"extends": "solhint:default"} property in a configuration file enables this rule. THIS IS DEPRECATED SINCE VERSION 5.1.0

2 changes: 1 addition & 1 deletion docs/rules/best-practices/max-states-count.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "max-states-count | Solhint"

# max-states-count
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-console.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "no-console | Solhint"

# no-console
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%20Rules-informational)
![Default Severity Badge error](https://img.shields.io/badge/Default%20Severity-error-red)
> The {"extends": "solhint:default"} property in a configuration file enables this rule. THIS IS DEPRECATED SINCE VERSION 5.1.0

2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-empty-blocks.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "no-empty-blocks | Solhint"

# no-empty-blocks
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-global-import.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ 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%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-unused-import.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "no-unused-import | Solhint"

# no-unused-import
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.
2 changes: 1 addition & 1 deletion docs/rules/best-practices/no-unused-vars.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "no-unused-vars | Solhint"

# no-unused-vars
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

2 changes: 1 addition & 1 deletion docs/rules/best-practices/one-contract-per-file.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "one-contract-per-file | Solhint"

# one-contract-per-file
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

2 changes: 1 addition & 1 deletion docs/rules/best-practices/payable-fallback.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "payable-fallback | Solhint"

# payable-fallback
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

2 changes: 1 addition & 1 deletion docs/rules/best-practices/reason-string.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ title: "reason-string | Solhint"

# reason-string
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Best%20Practice%20Rules-informational)
![Category Badge](https://img.shields.io/badge/-Best%20Practices%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.

66 changes: 66 additions & 0 deletions docs/rules/miscellaneous/import-path-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "import-path-check | Solhint"
---

# import-path-check
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen)
![Category Badge](https://img.shields.io/badge/-Miscellaneous-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
Check if an import file exits in target path

## Options
This rule accepts an array of options:

| Index | Description | Default Value |
| ----- | ----------------------------------------------------- | ------------- |
| 0 | Rule severity. Must be one of "error", "warn", "off". | warn |


### Example Config
```json
{
"rules": {
"import-path-check": ["warn",["[~dependenciesPath]"]]
}
}
```

### Notes
- Rule checks relative and absolute path first. Then checks for each dependency path in config file
- `searchOn`: an array of paths to check in specified order
- If `searchOn` is empty only `DEFAULT_LOCATIONS` are used.
- If `searchOn` has value, will be concatenated with DEFAULT_LOCATIONS.
- If config has `extends:recommended` or `all` and rule is overwritten with `searchOn`, values are concatenated with DEFAULT_LOCATIONS.

*Default Locations:*
- /[`~current-project`]
- /[`~current-project`]/contracts
- /[`~current-project`]/src
- /[`~current-project`]/node_modules
- /[`~current-project`]/artifacts
- /[`~current-project`]/cache
- /[`~current-project`]/lib
- /[`~current-project`]/out
- /usr/local/lib/node_modules
- /home/[`~user`]/.nvm/versions/node/[~node-version]/lib/node_modules
- /home/[`~user`]/.yarn/global/node_modules
- /npm/node_modules (for Windows)
- /Yarn/Data/global/node_modules (for Windows)
- WINDOWS OS file structure has not been thoroughly tested.

## Examples
This rule does not have examples.

## Version
This rule was introduced in the latest version.

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/miscellaneous/import-path-check.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/miscellaneous/import-path-check.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/miscellaneous/import-path-check.js)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rules": { "import-path-check": [ "error", [] ] }
}
15 changes: 15 additions & 0 deletions e2e/10-import-path-check/filesystem01/project/contracts/Lib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;

contract Foo {
uint256 public constant test1 = 1;
uint256 TEST2;

constructor() {}

function TEST() {}

modifier ZAR_tok() {}

uint256 SOSO;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Lib.sol";

contract Test {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rules": { "import-path-check": [ "error", ["/blockchain"] ] }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Helper} from "../shared/Helper.sol";

contract Test {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Lib.sol";

contract Test {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rules": { "import-path-check": [ "error", [] ] }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Test {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rules": { "import-path-check": [ "error", [] ] }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Missing.sol";

contract Test {}
19 changes: 0 additions & 19 deletions e2e/package.json

This file was deleted.

Loading