1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');
var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
var _path = require('path');
var _resolve = require('eslint-module-utils/resolve');
var _resolve2 = _interopRequireDefault(_resolve);
var _importType = require('../core/importType');
var _importType2 = _interopRequireDefault(_importType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2.default)('no-relative-parent-imports')
},
schema: [(0, _moduleVisitor.makeOptionsSchema)()]
},
create: function noRelativePackages(context) {
const myPath = context.getFilename();
if (myPath === '<text>') return {}; // can't check a non-file
function checkSourceValue(sourceNode) {
const depPath = sourceNode.value;
if ((0, _importType2.default)(depPath, context) === 'external') {
// ignore packages
return;
}
const absDepPath = (0, _resolve2.default)(depPath, context);
if (!absDepPath) {
// unable to resolve path
return;
}
const relDepPath = (0, _path.relative)((0, _path.dirname)(myPath), absDepPath);
if ((0, _importType2.default)(relDepPath, context) === 'parent') {
context.report({
node: sourceNode,
message: 'Relative imports from parent directories are not allowed. ' + `Please either pass what you're importing through at runtime ` + `(dependency injection), move \`${(0, _path.basename)(myPath)}\` to same ` + `directory as \`${depPath}\` or consider making \`${depPath}\` a package.`
});
}
}
return (0, _moduleVisitor2.default)(checkSourceValue, context.options[0]);
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25vLXJlbGF0aXZlLXBhcmVudC1pbXBvcnRzLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHl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