source: frontend/node_modules/eslint-plugin-import/docs/rules/no-absolute-path.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: 1.5 KB
Line 
1# import/no-absolute-path
2
3🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
4
5<!-- end auto-generated rule header -->
6
7Node.js allows the import of modules using an absolute path such as `/home/xyz/file.js`. That is a bad practice as it ties the code using it to your computer, and therefore makes it unusable in packages distributed on `npm` for instance.
8
9This rule forbids the import of modules using absolute paths.
10
11## Rule Details
12
13### Fail
14
15```js
16import f from '/foo';
17import f from '/some/path';
18
19var f = require('/foo');
20var f = require('/some/path');
21```
22
23### Pass
24
25```js
26import _ from 'lodash';
27import foo from 'foo';
28import foo from './foo';
29
30var _ = require('lodash');
31var foo = require('foo');
32var foo = require('./foo');
33```
34
35### Options
36
37By default, only ES6 imports and CommonJS `require` calls will have this rule enforced.
38
39You may provide an options object providing true/false for any of
40
41 - `esmodule`: defaults to `true`
42 - `commonjs`: defaults to `true`
43 - `amd`: defaults to `false`
44
45If `{ amd: true }` is provided, dependency paths for AMD-style `define` and `require`
46calls will be resolved:
47
48```js
49/*eslint import/no-absolute-path: [2, { commonjs: false, amd: true }]*/
50define(['/foo'], function (foo) { /*...*/ }) // reported
51require(['/foo'], function (foo) { /*...*/ }) // reported
52
53const foo = require('/foo') // ignored because of explicit `commonjs: false`
54```
Note: See TracBrowser for help on using the repository browser.