mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
61 lines
8.3 KiB
JavaScript
61 lines
8.3 KiB
JavaScript
|
'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;}() };
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZWxhdGl2ZS1wYWNrYWdlcy5qcyJdLCJuYW1lcyI6WyJmaW5kTmFtZWRQYWNrYWdlIiwiZmlsZVBhdGgiLCJmb3VuZCIsInJlYWRQa2dVcCIsInN5bmMiLCJjd2QiLCJub3JtYWxpemUiLCJwa2ciLCJuYW1lIiwicGF0aCIsImpvaW4iLCJjaGVja0ltcG9ydEZvclJlbGF0aXZlUGFja2FnZSIsImNvbnRleHQiLCJpbXBvcnRQYXRoIiwibm9kZSIsInBvdGVudGlhbFZpb2xhdGlvblR5cGVzIiwiaW5kZXhPZiIsInJlc29sdmVkSW1wb3J0IiwicmVzb2x2ZWRDb250ZXh0IiwiZ2V0UGh5c2ljYWxGaWxlbmFtZSIsImdldEZpbGVuYW1lIiwiaW1wb3J0UGtnIiwiY29udGV4dFBrZyIsImltcG9ydEJhc2VOYW1lIiwiYmFzZW5h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