Skip to content

Commit

Permalink
add: import-order rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Jul 1, 2024
1 parent 6c33840 commit 0ae84e3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conf/rulesets/solhint-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = Object.freeze({
immutablesAsConstants: true,
},
],
'import-order': ['warn', 4],
'import-order': 'warn',
'modifier-name-mixedcase': 'warn',
'named-parameters-mapping': 'warn',
'private-vars-leading-underscore': [
Expand Down
1 change: 1 addition & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ title: "Rule Index of Solhint"
| [func-named-parameters](./rules/naming/func-named-parameters.md) | Enforce named parameters for function calls with 4 or more arguments. This rule may have some false positives | | |
| [func-param-name-mixedcase](./rules/naming/func-param-name-mixedcase.md) | Function param name must be in mixedCase. | | |
| [immutable-vars-naming](./rules/naming/immutable-vars-naming.md) | Check Immutable variables. Capitalized SNAKE_CASE or mixedCase depending on configuration. | $~~~~~~~~$✔️ | |
| [import-order](./rules/naming/import-order.md) | Order the imports of the contract to follow a certain hierarchy | | |
| [modifier-name-mixedcase](./rules/naming/modifier-name-mixedcase.md) | Modifier name must be in mixedCase. | | |
| [named-parameters-mapping](./rules/naming/named-parameters-mapping.md) | Solidity v0.8.18 introduced named parameters on the mappings definition. | | |
| [private-vars-leading-underscore](./rules/naming/private-vars-leading-underscore.md) | Non-external functions and state variables should start with a single underscore. Others, shouldn't | | |
Expand Down
40 changes: 40 additions & 0 deletions docs/rules/naming/import-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "import-order | Solhint"
---

# import-order
![Category Badge](https://img.shields.io/badge/-Style%20Guide%20Rules-informational)
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)

## Description
Order the imports of the contract to follow a certain hierarchy

## Options
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn.

### Example Config
```json
{
"rules": {
"import-order": "warn"
}
}
```

### Notes
- Order by hierarchy of directories first, e.g. ../../ comes before ../, which comes before ./, which comes before ./foo
- Order alphabetically for each file at the same level, e.g. ./bar comes before ./foo
- Rule support up to 10 folder levels "../../../../../../../../../../"

## Examples
This rule does not have examples.

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

## Resources
- [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/naming/import-order.js)
- [Document source](https://github.com/protofire/solhint/tree/master/docs/rules/naming/import-order.md)
- [Test cases](https://github.com/protofire/solhint/tree/master/test/rules/naming/import-order.js)

0 comments on commit 0ae84e3

Please sign in to comment.