Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support arbitrary module namespace names in the quotes rule #15479

Merged
merged 1 commit into from Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/rules/quotes.js
Expand Up @@ -223,9 +223,20 @@ module.exports = {
// ModuleSpecifier.
case "ImportDeclaration":
case "ExportNamedDeclaration":
case "ExportAllDeclaration":
return parent.source === node;

// ModuleExportName or ModuleSpecifier.
case "ExportAllDeclaration":
return parent.exported === node || parent.source === node;

// ModuleExportName.
case "ImportSpecifier":
return parent.imported === node;

// ModuleExportName.
case "ExportSpecifier":
return parent.local === node || parent.exported === node;

// Others don't allow.
default:
return false;
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/quotes.js
Expand Up @@ -77,6 +77,16 @@ ruleTester.run("quotes", rule, {
{ code: "import a from \"a\"; import b from 'b';", options: ["backtick"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },
{ code: "export * from \"a\"; export * from 'b';", options: ["backtick"], parserOptions: { ecmaVersion: 6, sourceType: "module" } },

// `backtick` should not warn module export names.
{ code: "import { \"a\" as b, 'c' as d } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
{ code: "let a, c; export { a as \"b\", c as 'd' };", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
{ code: "export { \"a\", 'b' } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
{ code: "export { a as \"b\", c as 'd' } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
{ code: "export { \"a\" as b, 'c' as d } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
{ code: "export { \"a\" as \"b\", 'c' as 'd' } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
{ code: "export * as \"a\" from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },
{ code: "export * as 'a' from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } },

// `backtick` should not warn property/method names (not computed).
{ code: "var obj = {\"key0\": 0, 'key1': 1};", options: ["backtick"], parserOptions: { ecmaVersion: 6 } },
{ code: "class Foo { 'bar'(){} }", options: ["backtick"], parserOptions: { ecmaVersion: 6 } },
Expand Down