source: frontend/node_modules/eslint-plugin-import/docs/rules/no-unresolved.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: 4.2 KB
Line 
1# import/no-unresolved
2
3💼 This rule is enabled in the following configs: ❗ `errors`, ☑️ `recommended`.
4
5<!-- end auto-generated rule header -->
6
7Ensures an imported module can be resolved to a module on the local filesystem,
8as defined by standard Node `require.resolve` behavior.
9
10See [settings](../../README.md#settings) for customization options for the resolution (i.e.
11additional filetypes, `NODE_PATH`, etc.)
12
13This rule can also optionally report on unresolved modules in CommonJS `require('./foo')` calls and AMD `require(['./foo'], function (foo) {...})` and `define(['./foo'], function (foo) {...})`.
14
15To enable this, send `{ commonjs: true/false, amd: true/false }` as a rule option.
16Both are disabled by default.
17
18If you are using Webpack, see the section on [resolvers](../../README.md#resolvers).
19
20## Rule Details
21
22### Options
23
24By default, only ES6 imports will be resolved:
25
26```js
27/*eslint import/no-unresolved: 2*/
28import x from './foo' // reports if './foo' cannot be resolved on the filesystem
29```
30
31If `{commonjs: true}` is provided, single-argument `require` calls will be resolved:
32
33```js
34/*eslint import/no-unresolved: [2, { commonjs: true }]*/
35const { default: x } = require('./foo') // reported if './foo' is not found
36
37require(0) // ignored
38require(['x', 'y'], function (x, y) { /*...*/ }) // ignored
39```
40
41Similarly, if `{ amd: true }` is provided, dependency paths for `define` and `require`
42calls will be resolved:
43
44```js
45/*eslint import/no-unresolved: [2, { amd: true }]*/
46define(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
47require(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
48
49const { default: x } = require('./foo') // ignored
50```
51
52Both may be provided, too:
53
54```js
55/*eslint import/no-unresolved: [2, { commonjs: true, amd: true }]*/
56const { default: x } = require('./foo') // reported if './foo' is not found
57define(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
58require(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
59```
60
61#### `ignore`
62
63This rule has its own ignore list, separate from [`import/ignore`]. This is because you may want to know whether a module can be located, regardless of whether it can be parsed for exports: `node_modules`, CoffeeScript files, etc. are all good to resolve properly, but will not be parsed if configured as such via [`import/ignore`].
64
65To suppress errors from files that may not be properly resolved by your [resolver settings](../../README.md#resolver-plugins), you may add an `ignore` key with an array of `RegExp` pattern strings:
66
67```js
68/*eslint import/no-unresolved: [2, { ignore: ['\\.img$'] }]*/
69
70import { x } from './mod' // may be reported, if not resolved to a module
71
72import coolImg from '../../img/coolImg.img' // will not be reported, even if not found
73```
74
75#### `caseSensitive`
76
77By default, this rule will report paths whose case do not match the underlying filesystem path, if the FS is not case-sensitive. To disable this behavior, set the `caseSensitive` option to `false`.
78
79```js
80/*eslint import/no-unresolved: [2, { caseSensitive: true (default) | false }]*/
81const { default: x } = require('./foo') // reported if './foo' is actually './Foo' and caseSensitive: true
82```
83
84#### `caseSensitiveStrict`
85
86The `caseSensitive` option does not detect case for the current working directory. The `caseSensitiveStrict` option allows checking `cwd` in resolved path. By default, the option is disabled.
87
88```js
89/*eslint import/no-unresolved: [2, { caseSensitiveStrict: true }]*/
90
91// Absolute paths
92import Foo from `/Users/fOo/bar/file.js` // reported, /Users/foo/bar/file.js
93import Foo from `d:/fOo/bar/file.js` // reported, d:/foo/bar/file.js
94
95// Relative paths, cwd is Users/foo/
96import Foo from `./../fOo/bar/file.js` // reported
97```
98
99## When Not To Use It
100
101If you're using a module bundler other than Node or Webpack, you may end up with a lot of false positive reports of missing dependencies.
102
103## Further Reading
104
105 - [Resolver plugins](../../README.md#resolvers)
106 - [Node resolver](https://npmjs.com/package/eslint-import-resolver-node) (default)
107 - [Webpack resolver](https://npmjs.com/package/eslint-import-resolver-webpack)
108 - [`import/ignore`] global setting
109
110[`import/ignore`]: ../../README.md#importignore
Note: See TracBrowser for help on using the repository browser.