source: frontend/node_modules/eslint-plugin-import/docs/rules/no-unassigned-import.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.0 KB
Line 
1# import/no-unassigned-import
2
3<!-- end auto-generated rule header -->
4
5With both CommonJS' `require` and the ES6 modules' `import` syntax, it is possible to import a module but not to use its result. This can be done explicitly by not assigning the module to as variable. Doing so can mean either of the following things:
6
7 - The module is imported but not used
8 - The module has side-effects (like [`should`](https://www.npmjs.com/package/should)). Having side-effects, makes it hard to know whether the module is actually used or can be removed. It can also make it harder to test or mock parts of your application.
9
10This rule aims to remove modules with side-effects by reporting when a module is imported but not assigned.
11
12## Options
13
14This rule supports the following option:
15
16`allow`: An Array of globs. The files that match any of these patterns would be ignored/allowed by the linter. This can be useful for some build environments (e.g. css-loader in webpack).
17
18Note that the globs start from the where the linter is executed (usually project root), but not from each file that includes the source. Learn more in both the pass and fail examples below.
19
20## Fail
21
22```js
23import 'should'
24require('should')
25
26// In <PROJECT_ROOT>/src/app.js
27import '../styles/app.css'
28// {"allow": ["styles/*.css"]}
29```
30
31## Pass
32
33```js
34import _ from 'foo'
35import _, {foo} from 'foo'
36import _, {foo as bar} from 'foo'
37import {foo as bar} from 'foo'
38import * as _ from 'foo'
39
40const _ = require('foo')
41const {foo} = require('foo')
42const {foo: bar} = require('foo')
43const [a, b] = require('foo')
44const _ = require('foo')
45
46// Module is not assigned, but it is used
47bar(require('foo'))
48require('foo').bar
49require('foo').bar()
50require('foo')()
51
52// With allow option set
53import './style.css' // {"allow": ["**/*.css"]}
54import 'babel-register' // {"allow": ["babel-register"]}
55
56// In <PROJECT_ROOT>/src/app.js
57import './styles/app.css'
58import '../scripts/register.js'
59// {"allow": ["src/styles/**", "**/scripts/*.js"]}
60```
Note: See TracBrowser for help on using the repository browser.