internet-programming/lab3/node_modules/eslint-plugin-import/lib/rules/extensions.js

193 lines
20 KiB
JavaScript

'use strict';var _path = require('path');var _path2 = _interopRequireDefault(_path);
var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
var _importType = require('../core/importType');
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
var enumValues = { 'enum': ['always', 'ignorePackages', 'never'] };
var patternProperties = {
type: 'object',
patternProperties: { '.*': enumValues } };
var properties = {
type: 'object',
properties: {
pattern: patternProperties,
ignorePackages: { type: 'boolean' } } };
function buildProperties(context) {
var result = {
defaultConfig: 'never',
pattern: {},
ignorePackages: false };
context.options.forEach(function (obj) {
// If this is a string, set defaultConfig to its value
if (typeof obj === 'string') {
result.defaultConfig = obj;
return;
}
// If this is not the new structure, transfer all props to result.pattern
if (obj.pattern === undefined && obj.ignorePackages === undefined) {
Object.assign(result.pattern, obj);
return;
}
// If pattern is provided, transfer all props
if (obj.pattern !== undefined) {
Object.assign(result.pattern, obj.pattern);
}
// If ignorePackages is provided, transfer it to result
if (obj.ignorePackages !== undefined) {
result.ignorePackages = obj.ignorePackages;
}
});
if (result.defaultConfig === 'ignorePackages') {
result.defaultConfig = 'always';
result.ignorePackages = true;
}
return result;
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Style guide',
description: 'Ensure consistent use of file extension within the import path.',
url: (0, _docsUrl2['default'])('extensions') },
schema: {
anyOf: [
{
type: 'array',
items: [enumValues],
additionalItems: false },
{
type: 'array',
items: [
enumValues,
properties],
additionalItems: false },
{
type: 'array',
items: [properties],
additionalItems: false },
{
type: 'array',
items: [patternProperties],
additionalItems: false },
{
type: 'array',
items: [
enumValues,
patternProperties],
additionalItems: false }] } },
create: function () {function create(context) {
var props = buildProperties(context);
function getModifier(extension) {
return props.pattern[extension] || props.defaultConfig;
}
function isUseOfExtensionRequired(extension, isPackage) {
return getModifier(extension) === 'always' && (!props.ignorePackages || !isPackage);
}
function isUseOfExtensionForbidden(extension) {
return getModifier(extension) === 'never';
}
function isResolvableWithoutExtension(file) {
var extension = _path2['default'].extname(file);
var fileWithoutExtension = file.slice(0, -extension.length);
var resolvedFileWithoutExtension = (0, _resolve2['default'])(fileWithoutExtension, context);
return resolvedFileWithoutExtension === (0, _resolve2['default'])(file, context);
}
function isExternalRootModule(file) {
if (file === '.' || file === '..') {return false;}
var slashCount = file.split('/').length - 1;
if (slashCount === 0) {return true;}
if ((0, _importType.isScoped)(file) && slashCount <= 1) {return true;}
return false;
}
function checkFileExtension(source, node) {
// bail if the declaration doesn't have a source, e.g. "export { foo };", or if it's only partially typed like in an editor
if (!source || !source.value) {return;}
var importPathWithQueryString = source.value;
// don't enforce anything on builtins
if ((0, _importType.isBuiltIn)(importPathWithQueryString, context.settings)) {return;}
var importPath = importPathWithQueryString.replace(/\?(.*)$/, '');
// don't enforce in root external packages as they may have names with `.js`.
// Like `import Decimal from decimal.js`)
if (isExternalRootModule(importPath)) {return;}
var resolvedPath = (0, _resolve2['default'])(importPath, context);
// get extension from resolved path, if possible.
// for unresolved, use source value.
var extension = _path2['default'].extname(resolvedPath || importPath).substring(1);
// determine if this is a module
var isPackage = (0, _importType.isExternalModule)(
importPath,
(0, _resolve2['default'])(importPath, context),
context) ||
(0, _importType.isScoped)(importPath);
if (!extension || !importPath.endsWith('.' + String(extension))) {
// ignore type-only imports and exports
if (node.importKind === 'type' || node.exportKind === 'type') {return;}
var extensionRequired = isUseOfExtensionRequired(extension, isPackage);
var extensionForbidden = isUseOfExtensionForbidden(extension);
if (extensionRequired && !extensionForbidden) {
context.report({
node: source,
message: 'Missing file extension ' + (
extension ? '"' + String(extension) + '" ' : '') + 'for "' + String(importPathWithQueryString) + '"' });
}
} else if (extension) {
if (isUseOfExtensionForbidden(extension) && isResolvableWithoutExtension(importPath)) {
context.report({
node: source,
message: 'Unexpected use of file extension "' + String(extension) + '" for "' + String(importPathWithQueryString) + '"' });
}
}
}
return (0, _moduleVisitor2['default'])(checkFileExtension, { commonjs: true });
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHRlbnNpb25zLmpzIl0sIm5hbWVzIjpbImVudW1WYWx1ZXMiLCJwYXR0ZXJuUHJvcGVydGllcyIsInR5cGUiLCJwcm9wZXJ0aWVzIiwicGF0dGVybiIsImlnbm9yZVBhY2thZ2VzIiwiYnVpbGRQcm9wZXJ0aWVzIiwiY29udGV4dCIsInJlc3VsdCIsImRlZmF1bHRDb25maWciLCJvcHRpb25zIiwiZm9yRWFjaCIsIm9iaiIsInVuZGVmaW5lZCIsIk9iamVjdCIsImFzc2lnbiIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwiZG9jcyIsImNhdGVnb3J5IiwiZGVzY3JpcHRpb24iLCJ1cmwiLCJzY2hlbWEiLCJhbnlPZiIsIml0ZW1zIiwiYWRkaXRpb25hbEl0ZW1zIiwiY3JlYXRlIiwicHJvcHMiLCJnZXRNb2RpZmllciIsImV4dGVuc2lvbiIsImlzVXNlT2ZFeHRlbnNpb25SZXF1aXJlZCIsImlzUGFja2FnZSIsImlzVXNlT2ZFeHRlbnNpb25Gb3JiaWRkZW4iLCJpc1Jlc29sdmFibGVXaXRob3V0RXh0ZW5zaW9uIiwiZmlsZSIsInBhdGgiLCJleHRuYW1lIiwiZmlsZVdpdGhvdXRFeHRlbnNpb24iLCJzbGljZSIsImxlbmd0aCIsInJlc29sdmVkRmlsZVdpdGhvdXRFeHRlbnNpb24iLCJpc0V4dGVybmFsUm9vdE1vZHVsZSIsInNsYXNoQ291bnQiLCJzcGxpdCIsImNoZWNrRmlsZUV4dGVuc2lvbiIsInNvdXJjZSIsIm5vZGUiLCJ2Y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