the-forest/client/node_modules/eslint-plugin-import/lib/rules/no-absolute-path.js
2024-09-17 20:35:18 -04:00

40 lines
5.6 KiB
JavaScript

'use strict';var _path = require('path');var _path2 = _interopRequireDefault(_path);
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
var _importType = require('../core/importType');
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Static analysis',
description: 'Forbid import of modules using absolute paths.',
url: (0, _docsUrl2['default'])('no-absolute-path') },
fixable: 'code',
schema: [(0, _moduleVisitor.makeOptionsSchema)()] },
create: function () {function create(context) {
function reportIfAbsolute(source) {
if ((0, _importType.isAbsolute)(source.value)) {
context.report({
node: source,
message: 'Do not import modules using an absolute path',
fix: function () {function fix(fixer) {
var resolvedContext = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
// node.js and web imports work with posix style paths ("/")
var relativePath = _path2['default'].posix.relative(_path2['default'].dirname(resolvedContext), source.value);
if (!relativePath.startsWith('.')) {
relativePath = './' + String(relativePath);
}
return fixer.replaceText(source, JSON.stringify(relativePath));
}return fix;}() });
}
}
var options = Object.assign({ esmodule: true, commonjs: true }, context.options[0]);
return (0, _moduleVisitor2['default'])(reportIfAbsolute, options);
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1hYnNvbHV0ZS1wYXRoLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJjYXRlZ29yeSIsImRlc2NyaXB0aW9uIiwidXJsIiwiZml4YWJsZSIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJyZXBvcnRJZkFic29sdXRlIiw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