Skip to content

Latest commit

 

History

History
46 lines (28 loc) · 1.25 KB

no-namespace-imports.md

File metadata and controls

46 lines (28 loc) · 1.25 KB

Prevent namespace import declarations. (no-namespace-imports)

Namespace imports grab all exported variables from a module as nested properties under a single variable name. This approach of importing everything, rather than only what is required from the module, hinders tree-shaking and is seen broadly as a bad practise.

Rule Details

This rule will report all namespace imports and will optionally fix them (with the --fix flag) by converting them to default imports.

Examples of incorrect code for this rule:

import * as Foo from 'foo';

Examples of correct code for this rule:

import Foo from 'foo';

allow

{
  "shopify/no-namespace-imports": [
    "error",
    {
      "allow": ["foo", "bar"]
    }
  ]
}

This array option can define either module names or regular expressions to match which namespaced module imports are ignored by this rule.

When Not To Use It

If you do not wish to prevent namespace imports, you can safely disable this rule.

Further Reading