123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- '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 };}
- const enumValues = { enum: ['always', 'ignorePackages', 'never'] };
- const patternProperties = {
- type: 'object',
- patternProperties: { '.*': enumValues } };
- const properties = {
- type: 'object',
- properties: {
- 'pattern': patternProperties,
- 'ignorePackages': { type: 'boolean' } } };
- function buildProperties(context) {
- const result = {
- defaultConfig: 'never',
- pattern: {},
- ignorePackages: false };
- context.options.forEach(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: {
- 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 (context) {
- const 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) {
- const extension = _path2.default.extname(file);
- const fileWithoutExtension = file.slice(0, -extension.length);
- const resolvedFileWithoutExtension = (0, _resolve2.default)(fileWithoutExtension, context);
- return resolvedFileWithoutExtension === (0, _resolve2.default)(file, context);
- }
- function isExternalRootModule(file) {
- const slashCount = file.split('/').length - 1;
- if (slashCount === 0) return true;
- if ((0, _importType.isScopedModule)(file) && slashCount <= 1) return true;
- return false;
- }
- function checkFileExtension(source) {
- // bail if the declaration doesn't have a source, e.g. "export { foo };"
- if (!source) return;
- const importPathWithQueryString = source.value;
- // don't enforce anything on builtins
- if ((0, _importType.isBuiltIn)(importPathWithQueryString, context.settings)) return;
- const 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;
- const resolvedPath = (0, _resolve2.default)(importPath, context);
- // get extension from resolved path, if possible.
- // for unresolved, use source value.
- const extension = _path2.default.extname(resolvedPath || importPath).substring(1);
- // determine if this is a module
- const isPackage = (0, _importType.isExternalModule)(
- importPath,
- context.settings,
- (0, _resolve2.default)(importPath, context),
- context) ||
- (0, _importType.isScoped)(importPath);
- if (!extension || !importPath.endsWith(`.${extension}`)) {
- const extensionRequired = isUseOfExtensionRequired(extension, isPackage);
- const extensionForbidden = isUseOfExtensionForbidden(extension);
- if (extensionRequired && !extensionForbidden) {
- context.report({
- node: source,
- message:
- `Missing file extension ${extension ? `"${extension}" ` : ''}for "${importPathWithQueryString}"` });
- }
- } else if (extension) {
- if (isUseOfExtensionForbidden(extension) && isResolvableWithoutExtension(importPath)) {
- context.report({
- node: source,
- message: `Unexpected use of file extension "${extension}" for "${importPathWithQueryString}"` });
- }
- }
- }
- return (0, _moduleVisitor2.default)(checkFileExtension, { commonjs: true });
- } };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHRlbnNpb25zLmpzIl0sIm5hbWVzIjpbImVudW1WYWx1ZXMiLCJlbnVtIiwicGF0dGVyblByb3BlcnRpZXMiLCJ0eXBlIiwicHJvcGVydGllcyIsImJ1aWxkUHJvcGVydGllcyIsImNvbnRleHQiLCJyZXN1bHQiLCJkZWZhdWx0Q29uZmlnIiwicGF0dGVybiIsImlnbm9yZVBhY2thZ2VzIiwib3B0aW9ucyIsImZvckVhY2giLCJvYmoiLCJ1bmRlZmluZWQiLCJPYmplY3QiLCJhc3NpZ24iLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJhbnlPZiIsIml0ZW1zIiwiYWRkaXRpb25hbEl0ZW1zIiwiY3JlYXRlIiwicHJvcHMiLCJnZXRNb2RpZmllciIsImV4dGVuc2lvbiIsImlzVXNlT2ZFeHRlbnNpb25SZXF1aXJlZCIsImlzUGFja2FnZSIsImlzVXNlT2ZFeHRlbnNpb25Gb3JiaWRkZW4iLCJpc1Jlc29sdmFibGVXaXRob3V0RXh0ZW5zaW9uIiwiZmlsZSIsInBhdGgiLCJleHRuYW1lIiwiZmlsZVdpdGhvdXRFeHRlbnNpb24iLCJzbGljZSIsImxlbmd0aCIsInJlc29sdmVkRmlsZVdpdGhvdXRFeHRlbnNpb24iLCJpc0V4dGVybmFsUm9vdE1vZHVsZSIsInNsYXNoQ291bnQiLCJzcGxpdC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kb2NzVXJsKCdleHRlbnNpb25zJyksXG4gICAgfSxcblxuICAgIHNjaGVtYToge1xuICAgICAgYW55T2Y6IFtcbiAgICAgICAge1xuICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgaXRlbXM6IFtlbnVtVmFsdWVzXSxcbiAgICAgICAgICBhZGRpdGlvbmFsSXRlbXM6IGZhbHNlLFxuICAgICAgICB9LFxuICAgICAgICB7XG4gICAgICAgICAgdHlwZTogJ2FycmF5JyxcbiAgICAgICAgICBpdGVtczogW1xuICAgICAgICAgICAgZW51bVZhbHVlcyxcbiAgICAgICAgICAgIHByb3BlcnRpZXMsXG4gICAgICAgICAgXSxcbiAgICAgICAgICBhZGRpdGlvbmFsSXRlbXM6IGZhbHNlLFxuICAgICAgICB9LFxuICAgICAgICB7XG4gICAgICAgICAgdHlwZTogJ2FycmF5JyxcbiAgICAgICAgICBpdGVtczogW3Byb3BlcnRpZXNdLFxuICAgICAgICAgIGFkZGl0aW9uYWxJdGVtczogZmFsc2UsXG4gICAgICAgIH0sXG4gICAgICAgIHtcbiAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgIGl0ZW1zOiBbcGF0dGVyblByb3BlcnRpZXNdLFxuICAgICAgICAgIGFkZGl0aW9uYWxJdGVtczogZmFsc2UsXG4gICAgICAgIH0sXG4gICAgICAgIHtcbiAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgIGl0ZW1zOiBbXG4gICAgICAgICAgICBlbnVtVmFsdWVzLFxuICAgICAgICAgICAgcGF0dGVyblByb3BlcnRpZXMsXG4gICAgICAgICAgXSxcbiAgICAgICAgICBhZGRpdGlvbmFsSXRlbXM6IGZhbHNlLFxuICAgICAgICB9LFxuICAgICAgXSxcbiAgICB9LFxuICB9LFxuXG4gIGNyZWF0ZTogZnVuY3Rpb24gKGNvbnRleHQpIHtcblxuICAgIGNvbnN0IHByb3BzID0gYnVpbGRQcm9wZXJ0aWVzKGNvbnRleHQp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