Skip to content

Commit

Permalink
recognize aliased imports
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpcapurro committed Feb 28, 2023
1 parent 94cab60 commit 6f569ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/best-practises/no-unused-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NoUnusedImportsChecker extends BaseChecker {

ImportDirective(node) {
node.symbolAliasesIdentifiers.forEach((it) => {
this.importedNames[it[0].name] = { node: it[0], used: false }
this.importedNames[(it[1] || it[0]).name] = { node: it[0], used: false }
})
}

Expand Down
9 changes: 9 additions & 0 deletions test/rules/best-practises/no-unused-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ describe('Linter - no-unused-import', () => {
assertNoErrors(report)
})

it('should not raise when aliased contract name is used', () => {
const code = `import {A as B} from './A.sol'; contract C is B {}`

const report = linter.processStr(code, {
rules: { 'no-unused-import': 'error' },
})
assertNoErrors(report)
})

it('should not raise when libary name is used in a using ... for statement', () => {
const code = `import {A} from './A.sol'; contract B { using A for uint256; }`

Expand Down

0 comments on commit 6f569ed

Please sign in to comment.