source: frontend/node_modules/eslint-plugin-import/docs/rules/named.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.5 KB
LineΒ 
1# import/named
2
3πŸ’ΌπŸš« This rule is enabled in the following configs: ❗ `errors`, β˜‘οΈ `recommended`. This rule is _disabled_ in the ⌨️ `typescript` config.
4
5<!-- end auto-generated rule header -->
6
7Verifies that all named imports are part of the set of named exports in the referenced module.
8
9For `export`, verifies that all named exports exist in the referenced module.
10
11Note: for packages, the plugin will find exported names
12from [`jsnext:main`] (deprecated) or `module`, if present in `package.json`.
13Redux's npm module includes this key, and thereby is lintable, for example.
14
15A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported. Note that type imports and exports, as used by [Flow], are always ignored.
16
17[ignored]: ../../README.md#importignore
18[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
19[Flow]: https://flow.org/
20
21## Rule Details
22
23Given:
24
25```js
26// ./foo.js
27export const foo = "I'm so foo"
28```
29
30The following is considered valid:
31
32```js
33// ./bar.js
34import { foo } from './foo'
35
36// ES7 proposal
37export { foo as bar } from './foo'
38
39// node_modules without jsnext:main are not analyzed by default
40// (import/ignore setting)
41import { SomeNonsenseThatDoesntExist } from 'react'
42```
43
44...and the following are reported:
45
46```js
47// ./baz.js
48import { notFoo } from './foo'
49
50// ES7 proposal
51export { notFoo as defNotBar } from './foo'
52
53// will follow 'jsnext:main', if available
54import { dontCreateStore } from 'redux'
55```
56
57### Settings
58
59[`import/ignore`] can be provided as a setting to ignore certain modules (node_modules,
60CoffeeScript, CSS if using Webpack, etc.).
61
62Given:
63
64```yaml
65# .eslintrc (YAML)
66---
67settings:
68 import/ignore:
69 - node_modules # included by default, but replaced if explicitly configured
70 - *.coffee$ # can't parse CoffeeScript (unless a custom polyglot parser was configured)
71```
72
73and
74
75```coffeescript
76# ./whatever.coffee
77exports.whatever = (foo) -> console.log foo
78```
79
80then the following is not reported:
81
82```js
83// ./foo.js
84
85// can't be analyzed, and ignored, so not reported
86import { notWhatever } from './whatever'
87```
88
89## When Not To Use It
90
91If you are using CommonJS and/or modifying the exported namespace of any module at
92runtime, you will likely see false positives with this rule.
93
94## Further Reading
95
96 - [`import/ignore`] setting
97 - [`jsnext:main`] deprecation
98 - [`pkg.module`] (Rollup)
99
100[`jsnext:main`]: https://github.com/jsforum/jsforum/issues/5
101[`pkg.module`]: https://github.com/rollup/rollup/wiki/pkg.module
102[`import/ignore`]: ../../README.md#importignore
Note: See TracBrowser for help on using the repository browser.