Skip to content

Commit

Permalink
don't cause error on named global import
Browse files Browse the repository at this point in the history
fixes #414
update docs as well
  • Loading branch information
juanpcapurro committed Feb 28, 2023
1 parent 769e171 commit c62387a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/rules/best-practises/no-global-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ const meta = {
{ description: 'import all members from a file', code: 'import * from "foo.sol"' },
{ description: 'import an entire file', code: 'import "foo.sol"' },
],
good: [{ description: 'import names explicitly', code: 'import {A} from "./A.sol"' }],
good: [
{ description: 'import names explicitly', code: 'import {A} from "./A.sol"' },
{ description: 'import entire file into a name', code: 'import "./A.sol" as A' },
{ description: 'import entire file into a name', code: 'import * as A from "./A.sol"' },
],
},
},

Expand All @@ -29,10 +33,10 @@ class NoGlobalImportsChecker extends BaseChecker {
}

ImportDirective(node) {
if (!node.symbolAliases) {
if (!(node.symbolAliases || node.unitAlias)) {
this.error(
node,
`global import of path ${node.path} is not allowed. Specify names to import individually`
`global import of path ${node.path} is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)`
)
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/rules/best-practises/no-global-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe('Linter - no-global-import', () => {
it('should not raise on import {identifier} from "path"', () => {
const code = `import {A} from './A.sol';`

const report = linter.processStr(code, {
rules: { 'no-global-import': 'warn' },
})
assertNoWarnings(report)
})
it('should not raise on import from "path" as NAME', () => {
const code = `import "../../src/Helpers.sol" as H;`

const report = linter.processStr(code, {
rules: { 'no-global-import': 'warn' },
})
assertNoWarnings(report)
})
it('should not raise on import * as NAME from "path" as NAME', () => {
const code = `import * as H from "../../src/Helpers.sol";`

const report = linter.processStr(code, {
rules: { 'no-global-import': 'warn' },
})
Expand Down

0 comments on commit c62387a

Please sign in to comment.