%PDF- %PDF-
Direktori : /var/www/html/node_modules/eslint-plugin-import/lib/rules/ |
Current File : /var/www/html/node_modules/eslint-plugin-import/lib/rules/no-relative-packages.js |
'use strict';var _path = require('path');var _path2 = _interopRequireDefault(_path); var _readPkgUp = require('eslint-module-utils/readPkgUp');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 = (0, _readPkgUp2['default'])({ cwd: filePath }); 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;}() }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZWxhdGl2ZS1wYWNrYWdlcy5qcyJdLCJuYW1lcyI6WyJmaW5kTmFtZWRQYWNrYWdlIiwiZmlsZVBhdGgiLCJmb3VuZCIsImN3ZCIsInBrZyIsIm5hbWUiLCJwYXRoIiwiam9pbiIsImNoZWNrSW1wb3J0Rm9yUmVsYXRpdmVQYWNrYWdlIiwiY29udGV4dCIsImltcG9ydFBhdGgiLCJub2RlIiwicG90ZW50aWFsVmlvbGF0aW9uVHlwZXMiLCJpbmRleE9mIiwicmVzb2x2ZWRJbXBvcnQiLCJyZXNvbHZlZENvbnRleHQiLCJnZXRQaHlzaWNhbEZpbGVuYW1lIiwiZ2V0RmlsZW5hbWUiLCJpbXBvcnRQa2ciLCJjb250ZXh0UGtnIiwiaW1wb3J0QmFzZU5hbWUiLCJiYXNlbmFtZSIsImltcG9ydFJvb3QiLCJkaXJuYW1lIiwicHJvcGVyUGF0aCIsInJlbGF0aXZlIiwicHJvcGVySW1wb3J0IiwicmVwb3J0IiwibWVzc2FnZSIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJjcmVhdGUiLCJzb3VyY2UiLCJ2YWx1ZSIsIm9wdGlvbnMiXSwibWFwcGluZ3MiOiJhQUFBLDRCO0FBQ0EsMEQ7O0FBRUEsc0Q7QUFDQSxrRTtBQUNBLGdEO0FBQ0EscUM7O0FBRUEsU0FBU0EsZ0JBQVQsQ0FBMEJDLFFBQTFCLEVBQW9DO0FBQ2xDLE1BQU1DLFFBQVEsNEJBQVUsRUFBRUMsS0FBS0YsUUFBUCxFQUFWL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