Skip to content

Commit

Permalink
✨ add es/no-export-ns-from rule (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Jun 19, 2020
1 parent 023415c commit 90f5e0e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ There is no config which enables all rules in this category.
|:--------|:------------|:--:|
| [es/no-bigint](./no-bigint.md) | disallow `bigint` syntax and built-ins. | |
| [es/no-dynamic-import](./no-dynamic-import.md) | disallow `import()` syntax. | |
| [es/no-export-ns-from](./no-export-ns-from.md) | disallow `export * as ns`. | |
| [es/no-global-this](./no-global-this.md) | disallow the `globalThis` variable. | |
| [es/no-import-meta](./no-import-meta.md) | disallow `new.target` meta property. | |
| [es/no-nullish-coalescing-operators](./no-nullish-coalescing-operators.md) | disallow nullish coalescing operators. | |
Expand Down
16 changes: 16 additions & 0 deletions docs/rules/no-export-ns-from.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow `export * as ns` (es/no-export-ns-from)

This rule reports ES2020 [`export * as ns`](https://github.com/tc39/proposal-export-ns-from) as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-export-ns-from: error */
export * as ns from &quot;mod&quot;
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v3.0.1/lib/rules/no-export-ns-from.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v3.0.1/tests/lib/rules/no-export-ns-from.js)
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ module.exports = {
"no-destructuring": require("./rules/no-destructuring"),
"no-dynamic-import": require("./rules/no-dynamic-import"),
"no-exponential-operators": require("./rules/no-exponential-operators"),
"no-export-ns-from": require("./rules/no-export-ns-from"),
"no-for-of-loops": require("./rules/no-for-of-loops"),
"no-generators": require("./rules/no-generators"),
"no-global-this": require("./rules/no-global-this"),
Expand Down
30 changes: 30 additions & 0 deletions lib/rules/no-export-ns-from.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"

module.exports = {
meta: {
docs: {
description: "disallow `export * as ns`.",
category: "ES2020",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-export-ns-from.html",
},
fixable: null,
messages: {
forbidden: "ES2020 'export * as ns' are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ExportAllDeclaration[exported!=null]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
35 changes: 35 additions & 0 deletions tests/lib/rules/no-export-ns-from.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"

const RuleTester = require("../../tester")
const rule = require("../../../lib/rules/no-export-ns-from.js")

if (!RuleTester.isSupported(2020)) {
//eslint-disable-next-line no-console
console.log("Skip the tests of no-export-ns-from.")
return
}

new RuleTester({
parserOptions: { sourceType: "module" },
}).run("no-export-ns-from", rule, {
valid: [
'export * from "mod"',
"export default foo",
'export {foo} from "mod"',
'export {foo as bar} from "mod"',
'import * as foo from "mod"',
'import foo from "mod"',
'import {foo} from "mod"',
'import {foo as bar} from "mod"',
],
invalid: [
{
code: 'export * as ns from "mod"',
errors: ["ES2020 'export * as ns' are forbidden."],
},
],
})

0 comments on commit 90f5e0e

Please sign in to comment.