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

feature: duplicated import rule #626

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
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
Expand Up @@ -36,6 +36,7 @@ module.exports = Object.freeze({
'gas-strict-inequalities': 'warn',
'gas-struct-packing': 'warn',
'comprehensive-interface': 'warn',
'duplicated-imports': 'warn',
quotes: ['error', 'double'],
'const-name-snakecase': 'warn',
'contract-name-capwords': 'warn',
Expand Down
1 change: 1 addition & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ title: "Rule Index of Solhint"
| Rule Id | Error | Recommended | Deprecated |
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ------------ | ----------- |
| [interface-starts-with-i](./rules/naming/interface-starts-with-i.md) | Solidity Interfaces names should start with an `I` | | |
| [duplicated-imports](./rules/miscellaneous/duplicated-imports.md) | Check if an import is done twice in the same file and there is no alias | | |
| [const-name-snakecase](./rules/naming/const-name-snakecase.md) | Constant name must be in capitalized SNAKE_CASE. (Does not check IMMUTABLES, use immutable-vars-naming) | $~~~~~~~~$✔️ | |
| [contract-name-capwords](./rules/naming/contract-name-capwords.md) | Contract, Structs and Enums should be in CapWords. | $~~~~~~~~$✔️ | |
| [event-name-capwords](./rules/naming/event-name-capwords.md) | Event name must be in CapWords. | $~~~~~~~~$✔️ | |
Expand Down
41 changes: 41 additions & 0 deletions docs/rules/miscellaneous/duplicated-imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "duplicated-imports | Solhint"
---

# duplicated-imports
![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
Check if an import is done twice in the same file and there is no alias

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

### Example Config
```json
{
"rules": {
"duplicated-imports": "warn"
}
}
```

### Notes
- Rule reports "(inline) duplicated" if the same object is imported more than once in the same import statement
- Rule reports "(globalSamePath) duplicated" if the same object is imported on another import statement from same location
- Rule reports "(globalDiffPath) duplicated" if the same object is imported on another import statement, from other location, but no alias
- Rule does NOT support this kind of import "import * as Alias from "./filename.sol"

## Examples
This rule does not have examples.

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

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/miscellaneous/duplicated-imports.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/miscellaneous/duplicated-imports.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/miscellaneous/duplicated-imports.js)
24 changes: 12 additions & 12 deletions e2e/autofix-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('e2e', function () {

const reportLines = stdout.split('\n')
const finalLine = '5 problems (5 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)

result = compareTextFiles(currentFile, afterFixFile)
expect(result).to.be.true
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('e2e', function () {
it('should get the right report (2)', () => {
const reportLines = stdout.split('\n')
const finalLine = '27 problems (27 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -240,7 +240,7 @@ describe('e2e', function () {
it('should get the right report (3)', () => {
const reportLines = stdout.split('\n')
const finalLine = '9 problems (9 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -286,7 +286,7 @@ describe('e2e', function () {
it('should get the right report (4)', () => {
const reportLines = stdout.split('\n')
const finalLine = '19 problems (19 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -332,7 +332,7 @@ describe('e2e', function () {
it('should get the right report (5)', () => {
const reportLines = stdout.split('\n')
const finalLine = '11 problems (11 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -379,7 +379,7 @@ describe('e2e', function () {
it('should get the right report (6)', () => {
const reportLines = stdout.split('\n')
const finalLine = '8 problems (8 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -419,7 +419,7 @@ describe('e2e', function () {
it('should get the right report (6)', () => {
const reportLines = stdout.split('\n')
const finalLine = '8 problems (8 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -466,7 +466,7 @@ describe('e2e', function () {
it('should get the right report (7)', () => {
const reportLines = stdout.split('\n')
const finalLine = '3 problems (3 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -512,7 +512,7 @@ describe('e2e', function () {
it('should get the right report (8)', () => {
const reportLines = stdout.split('\n')
const finalLine = '5 problems (5 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -558,7 +558,7 @@ describe('e2e', function () {
it('should get the right report (9)', () => {
const reportLines = stdout.split('\n')
const finalLine = '6 problems (6 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -604,7 +604,7 @@ describe('e2e', function () {
it('should get the right report (10)', () => {
const reportLines = stdout.split('\n')
const finalLine = '18 problems (18 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
})
})

Expand Down Expand Up @@ -649,7 +649,7 @@ describe('e2e', function () {
// it('should get the right report (11)', () => {
// const reportLines = stdout.split('\n')
// const finalLine = '12 problems (12 errors, 0 warnings)'
// expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
// expect(reportLines[reportLines.length - 7]).to.contain(finalLine)
// })
// })

Expand Down
Loading
Loading