Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/rules/no-arbitrary-module-namespace-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# es/no-arbitrary-module-namespace-names
> disallow arbitrary module namespace names

- ✅ The following configurations enable this rule: `plugin:es/no-new-in-esnext`

This rule reports ES2022 arbitrary module namespace names as errors.

## Examples

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

<eslint-playground type="bad" code="/*eslint es/no-arbitrary-module-namespace-names: error */
export * as &quot;ns&quot; from &quot;mod&quot;
export {foo as &quot;bar&quot;} from &quot;mod&quot;
import {&quot;foo&quot; as bar} from &quot;mod&quot;
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v4.1.0/lib/rules/no-arbitrary-module-namespace-names.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v4.1.0/tests/lib/rules/no-arbitrary-module-namespace-names.js)
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = {
},
rules: {
"no-accessor-properties": require("./rules/no-accessor-properties"),
"no-arbitrary-module-namespace-names": require("./rules/no-arbitrary-module-namespace-names"),
"no-array-from": require("./rules/no-array-from"),
"no-array-isarray": require("./rules/no-array-isarray"),
"no-array-of": require("./rules/no-array-of"),
Expand Down
35 changes: 35 additions & 0 deletions lib/rules/no-arbitrary-module-namespace-names.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"

module.exports = {
meta: {
docs: {
description: "disallow arbitrary module namespace names.",
category: "ES2022",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-arbitrary-module-namespace-names.html",
},
fixable: null,
messages: {
forbidden: "ES2022 arbitrary module namespace names are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ExportAllDeclaration > Literal.exported, ExportSpecifier > Literal.local, ExportSpecifier > Literal.exported, ImportSpecifier > Literal.imported"(
node,
) {
context.report({
node,
messageId: "forbidden",
})
},
}
},
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
"@mysticatea/eslint-plugin": "^13.0.0",
"@typescript-eslint/parser": "^4.8.2",
"@vuepress/plugin-pwa": "^1.2.0",
"acorn": "^7.1.0",
"codecov": "^3.8.1",
"eslint": "^7.10.0",
"eslint": "^8.6.0",
"eslint4b": "^7.10.0",
"espree": "^7.0.0",
"espree": "^9.3.0",
"globals": "^12.0.0",
"mocha": "^6.2.0",
"npm-run-all": "^4.1.5",
Expand Down
51 changes: 51 additions & 0 deletions tests/lib/rules/no-arbitrary-module-namespace-names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @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-arbitrary-module-namespace-names.js")

if (!RuleTester.isSupported(2022)) {
//eslint-disable-next-line no-console
console.log("Skip the tests of no-arbitrary-module-namespace-names.")
return
}

new RuleTester({
parserOptions: { sourceType: "module" },
}).run("no-arbitrary-module-namespace-names", rule, {
valid: [
'export * from "mod"',
'export * as ns 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: ["ES2022 arbitrary module namespace names are forbidden."],
},
{
code: 'export {foo as "bar"} from "mod"',
errors: ["ES2022 arbitrary module namespace names are forbidden."],
},
{
code: 'export {"foo" as "bar"} from "mod"',
errors: [
"ES2022 arbitrary module namespace names are forbidden.",
"ES2022 arbitrary module namespace names are forbidden.",
],
},
{
code: 'import {"foo" as bar} from "mod"',
errors: ["ES2022 arbitrary module namespace names are forbidden."],
},
],
})
1 change: 1 addition & 0 deletions tests/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const semver = require("semver")
const eslintVersion = new Linter().version
const ecmaVersion =
/*eslint-disable @mysticatea/prettier */
semver.gte(eslintVersion, "8.0.0") ? 2022 :
semver.gte(eslintVersion, "7.8.0") ? 2021 :
semver.gte(eslintVersion, "6.2.0") ? 2020 :
semver.gte(eslintVersion, "5.0.0") ? 2019 :
Expand Down