12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- '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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZWxhdGl2ZS1wYXJlbnQtaW1wb3J0cy5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwibm9SZWxhd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