Repository: protofire/solhint (js)

Issue:
"no-global-import" should not apply to named global imports
Solhint correctly throws a warning for the following code:

```solidity
import "../../src/Helpers.sol";
```

But it incorrectly continues to throw a warning even when naming the global import, like this:

```solidity
import "../../src/Helpers.sol" as H;
```

Using global imports in this way should be completely acceptable since the global namespace is not polluted.

The use case, in my case, is a [`Helpers.sol`](https://github.com/PaulRBerg/prb-test/blob/48482b1be0ca1e3ad6c0f7dd568d13f79fbd4dba/src/Helpers.sol) file with lots of overloaded functions that cannot be imported individually (e.g. the `eq` functions). Another place where I use this technique is in [PRBMath](https://github.com/PaulRBerg/prb-math/blob/ea0ad4fcbc286d1dec490f07b93f3304ff94dda2/src/ud60x18/ValueType.sol#L4-L6).

Pull request description:
Do not raise error on named global import
fixes #414


Patch:
diff --git a/lib/rules/best-practises/no-global-import.js b/lib/rules/best-practises/no-global-import.js
index d9ae75f..2f3e27b 100644
--- a/lib/rules/best-practises/no-global-import.js
+++ b/lib/rules/best-practises/no-global-import.js
@@ -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"' },
+      ],
     },
   },
 
@@ -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)`
       )
     }
   }


Test patch:
diff --git a/test/rules/best-practises/no-global-import.js b/test/rules/best-practises/no-global-import.js
index 199f8c0..3ab26a1 100644
--- a/test/rules/best-practises/no-global-import.js
+++ b/test/rules/best-practises/no-global-import.js
@@ -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' },
     })