'use strict';var _path = require('path');var _path2 = _interopRequireDefault(_path); var _readPkgUp = require('read-pkg-up');var _readPkgUp2 = _interopRequireDefault(_readPkgUp); var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve); var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor); var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType); var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };} function findNamedPackage(filePath) { var found = _readPkgUp2['default'].sync({ cwd: filePath, normalize: false }); if (found.pkg && !found.pkg.name) { return findNamedPackage(_path2['default'].join(found.path, '../..')); } return found; } function checkImportForRelativePackage(context, importPath, node) { var potentialViolationTypes = ['parent', 'index', 'sibling']; if (potentialViolationTypes.indexOf((0, _importType2['default'])(importPath, context)) === -1) { return; } var resolvedImport = (0, _resolve2['default'])(importPath, context); var resolvedContext = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); if (!resolvedImport || !resolvedContext) { return; } var importPkg = findNamedPackage(resolvedImport); var contextPkg = findNamedPackage(resolvedContext); if (importPkg.pkg && contextPkg.pkg && importPkg.pkg.name !== contextPkg.pkg.name) { var importBaseName = _path2['default'].basename(importPath); var importRoot = _path2['default'].dirname(importPkg.path); var properPath = _path2['default'].relative(importRoot, resolvedImport); var properImport = _path2['default'].join( importPkg.pkg.name, _path2['default'].dirname(properPath), importBaseName === _path2['default'].basename(importRoot) ? '' : importBaseName); context.report({ node: node, message: 'Relative import from another package is not allowed. Use `' + String(properImport) + '` instead of `' + String(importPath) + '`' }); } } module.exports = { meta: { type: 'suggestion', docs: { url: (0, _docsUrl2['default'])('no-relative-packages') }, schema: [(0, _moduleVisitor.makeOptionsSchema)()] }, create: function () {function create(context) { return (0, _moduleVisitor2['default'])(function (source) {return checkImportForRelativePackage(context, source.value, source);}, context.options[0]); }return create;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