170 lines
16 KiB
JavaScript
170 lines
16 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 _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;
|
|
}
|
|
});
|
|
|
|
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, isPackageMain) {
|
|
return getModifier(extension) === 'always' && (!props.ignorePackages || !isPackageMain);
|
|
}
|
|
|
|
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 checkFileExtension(node) {
|
|
const source = node.source;
|
|
|
|
// bail if the declaration doesn't have a source, e.g. "export { foo };"
|
|
|
|
if (!source) return;
|
|
|
|
const importPath = source.value;
|
|
|
|
// don't enforce anything on builtins
|
|
if ((0, _importType.isBuiltIn)(importPath, context.settings)) 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 isPackageMain = (0, _importType.isExternalModuleMain)(importPath, context.settings) || (0, _importType.isScopedMain)(importPath);
|
|
|
|
if (!extension || !importPath.endsWith(`.${extension}`)) {
|
|
const extensionRequired = isUseOfExtensionRequired(extension, isPackageMain);
|
|
const extensionForbidden = isUseOfExtensionForbidden(extension);
|
|
if (extensionRequired && !extensionForbidden) {
|
|
context.report({
|
|
node: source,
|
|
message: `Missing file extension ${extension ? `"${extension}" ` : ''}for "${importPath}"`
|
|
});
|
|
}
|
|
} else if (extension) {
|
|
if (isUseOfExtensionForbidden(extension) && isResolvableWithoutExtension(importPath)) {
|
|
context.report({
|
|
node: source,
|
|
message: `Unexpected use of file extension "${extension}" for "${importPath}"`
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
ImportDeclaration: checkFileExtension,
|
|
ExportNamedDeclaration: checkFileExtension
|
|
};
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHRlbnNpb25zLmpzIl0sIm5hbWVzIjpbImVudW1WYWx1ZXMiLCJlbnVtIiwicGF0dGVyblByb3BlcnRpZXMiLCJ0eXBlIiwicHJvcGVydGllcyIsImJ1aWxkUHJvcGVydGllcyIsImNvbnRleHQiLCJyZXN1bHQiLCJkZWZhdWx0Q29uZmlnIiwicGF0dGVybiIsImlnbm9yZVBhY2thZ2VzIiwib3B0aW9ucyIsImZvckVhY2giLCJvYmoiLCJ1bmRlZmluZWQiLCJPYmplY3QiLCJhc3NpZ24iLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJhbnlPZiIsIml0ZW1zIiwiYWRkaXRpb25hbEl0ZW1zIiwiY3JlYXRlIiwicHJvcHMiLCJnZXRNb2RpZmllciIsImV4dGVuc2lvbiIsImlzVXNlT2ZFeHRlbnNpb25SZXF1aXJlZCIsImlzUGFja2FnZU1haW4iLCJpc1VzZU9mRXh0ZW5zaW9uRm9yYmlkZGVuIiwiaXNSZXNvbHZhYmxlV2l0aG91dEV4dGVuc2lvbiIsImZpbGUiLCJwYXRoIiwiZXh0bmFtZSIsImZpbGVXaXRob3V0RXh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25vcmVQYWNrYWdlcyAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgIHJlc3VsdC5pZ25vcmVQYWNrYWdlcyA9IG9iai5pZ25vcmVQYWNrYWdlc1xuICAgICAgfVxuICAgIH0pXG5cbiAgICByZXR1cm4gcmVzdWx0XG59XG5cbm1vZHVsZS5leHBvcnRzID0ge1xuICBtZXRhOiB7XG4gICAgdHlwZTogJ3N1Z2dlc3Rpb24nLFxuICAgIGRvY3M6IHtcbiAgICAgIHVybDogZG9jc1VybCgnZXh0ZW5zaW9ucycpLFxuICAgIH0sXG5cbiAgICBzY2hlbWE6IHtcbiAgICAgIGFueU9mOiBbXG4gICAgICAgIHtcbiAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgIGl0ZW1zOiBbZW51bVZhbHVlc10sXG4gICAgICAgICAgYWRkaXRpb25hbEl0ZW1zOiBmYWxzZSxcbiAgICAgICAgfSxcbiAgICAgICAge1xuICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgaXRlbXM6IFtcbiAgICAgICAgICAgIGVudW1WYWx1ZXMsXG4gICAgICAgICAgICBwcm9wZXJ0aWVzLFxuICAgICAgICAgIF0sXG4gICAgICAgICAgYWRkaXRpb25hbEl0ZW1zOiBmYWxzZSxcbiAgICAgICAgfSxcbiAgICAgICAge1xuICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgaXRlbXM6IFtwcm9wZXJ0aWVzXSxcbiAgICAgICAgICBhZGRpdGlvbmFsSXRlbXM6IGZhbHNlLFxuICAgICAgICB9LFxuICAgICAgICB7XG4gICAgICAgICAgdHlwZTogJ2FycmF5JyxcbiAgICAgICAgICBpdGVtczogW3BhdHRlcm5Qcm9wZXJ0aWVzXSxcbiAgICAgICAgICBhZGRpdGlvbmFsSXRlbXM6IGZhbHNlLFxuICAgICAgICB9LFxuICAgICAgICB7XG4gICAgICAgICAgdHlwZTogJ2FycmF5JyxcbiAgICAgICAgICBpdGVt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