Skip to content

Commit

Permalink
feat: Support arbitrary module namespace names in the quotes rule (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Jan 5, 2022
1 parent 5563c45 commit 3549571
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit 3549571

Please sign in to comment.