-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Radek Benkel
authored and
Radek Benkel
committed
Apr 8, 2016
1 parent
de93a27
commit 933d110
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# no-namespace | ||
|
||
Reports if namespace import is used. | ||
|
||
## Rule Details | ||
|
||
Valid: | ||
|
||
```js | ||
import defaultExport from './foo' | ||
import { a, b } from './bar' | ||
import defaultExport, { a, b } from './foobar' | ||
``` | ||
|
||
...whereas here imports will be reported: | ||
|
||
```js | ||
import * as foo from 'foo'; | ||
import defaultExport, * as foo from 'foo'; | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you want to use namespaces, you don't want to use this rule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @fileoverview Rule to disallow namespace import | ||
* @author Radek Benkel | ||
*/ | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
module.exports = function (context) { | ||
return { | ||
'ImportNamespaceSpecifier': function (node) { | ||
context.report(node, `Unexpected namespace import.`) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { RuleTester } from 'eslint' | ||
|
||
const ERROR_MESSAGE = 'Unexpected namespace import.'; | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
ruleTester.run('no-namespace', require('rules/no-namespace'), { | ||
valid: [ | ||
{ code: "import { a, b } from 'foo';", parserOptions: { sourceType: 'module' } }, | ||
{ code: "import { a, b } from './foo';", parserOptions: { sourceType: 'module' } }, | ||
{ code: "import bar from 'bar';", parserOptions: { sourceType: 'module' } }, | ||
{ code: "import bar from './bar';", parserOptions: { sourceType: 'module' } } | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "import * as foo from 'foo';", | ||
errors: [ { | ||
line: 1, | ||
column: 8, | ||
message: ERROR_MESSAGE | ||
} ], | ||
parserOptions: { sourceType: 'module' } | ||
}, | ||
{ | ||
code: "import defaultExport, * as foo from 'foo';", | ||
errors: [ { | ||
line: 1, | ||
column: 23, | ||
message: ERROR_MESSAGE | ||
} ], | ||
parserOptions: { sourceType: 'module' } | ||
}, | ||
{ | ||
code: "import * as foo from './foo';", | ||
errors: [ { | ||
line: 1, | ||
column: 8, | ||
message: ERROR_MESSAGE | ||
} ], | ||
parserOptions: { sourceType: 'module' } | ||
} | ||
] | ||
}); |
933d110
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for wanting this rule?
There are a plethora of cases where there simply is no other way to import all exports other then using asterisk-alias.
933d110
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gajus see discussion below PR #239
Also, rule is optional and it's usage depends on your code style :)
Could you please provide an example of mentioned cases, when you don't have other way? We looked into our code base and realised, that there's was no good reason to use asterisk-alias - hence the PR to enforce that on our side.