Skip to content

Commit 9de0535

Browse files
Merge pull request #626 from protofire/feature/duplicated-imports
feature: duplicated import rule
2 parents 0494368 + fa1d56c commit 9de0535

File tree

9 files changed

+642
-13
lines changed

9 files changed

+642
-13
lines changed

conf/rulesets/solhint-all.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = Object.freeze({
3636
'gas-strict-inequalities': 'warn',
3737
'gas-struct-packing': 'warn',
3838
'comprehensive-interface': 'warn',
39+
'duplicated-imports': 'warn',
3940
quotes: ['error', 'double'],
4041
'const-name-snakecase': 'warn',
4142
'contract-name-capwords': 'warn',

docs/rules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ title: "Rule Index of Solhint"
2828
| Rule Id | Error | Recommended | Deprecated |
2929
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ------------ | ----------- |
3030
| [interface-starts-with-i](./rules/naming/interface-starts-with-i.md) | Solidity Interfaces names should start with an `I` | | |
31+
| [duplicated-imports](./rules/miscellaneous/duplicated-imports.md) | Check if an import is done twice in the same file and there is no alias | | |
3132
| [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) | $~~~~~~~~$✔️ | |
3233
| [contract-name-capwords](./rules/naming/contract-name-capwords.md) | Contract, Structs and Enums should be in CapWords. | $~~~~~~~~$✔️ | |
3334
| [event-name-capwords](./rules/naming/event-name-capwords.md) | Event name must be in CapWords. | $~~~~~~~~$✔️ | |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
warning: "This is a dynamically generated file. Do not edit manually."
3+
layout: "default"
4+
title: "duplicated-imports | Solhint"
5+
---
6+
7+
# duplicated-imports
8+
![Category Badge](https://img.shields.io/badge/-Style%20Guide%20Rules-informational)
9+
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)
10+
11+
## Description
12+
Check if an import is done twice in the same file and there is no alias
13+
14+
## Options
15+
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Defaults to warn.
16+
17+
### Example Config
18+
```json
19+
{
20+
"rules": {
21+
"duplicated-imports": "warn"
22+
}
23+
}
24+
```
25+
26+
### Notes
27+
- Rule reports "(inline) duplicated" if the same object is imported more than once in the same import statement
28+
- Rule reports "(globalSamePath) duplicated" if the same object is imported on another import statement from same location
29+
- Rule reports "(globalDiffPath) duplicated" if the same object is imported on another import statement, from other location, but no alias
30+
- Rule does NOT support this kind of import "import * as Alias from "./filename.sol"
31+
32+
## Examples
33+
This rule does not have examples.
34+
35+
## Version
36+
This rule is introduced in the latest version.
37+
38+
## Resources
39+
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/miscellaneous/duplicated-imports.js)
40+
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/miscellaneous/duplicated-imports.md)
41+
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/miscellaneous/duplicated-imports.js)

e2e/autofix-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('e2e', function () {
145145

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)