mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
189 lines
19 KiB
JavaScript
189 lines
19 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: {
|
|
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) {
|
|
var 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 };", 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,
|
|
context.settings,
|
|
(0, _resolve2['default'])(importPath, context),
|
|
context) ||
|
|
(0, _importType.isScoped)(importPath);
|
|
|
|
if (!extension || !importPath.endsWith('.' + String(extension))) {
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHRlbnNpb25zLmpzIl0sIm5hbWVzIjpbImVudW1WYWx1ZXMiLCJwYXR0ZXJuUHJvcGVydGllcyIsInR5cGUiLCJwcm9wZXJ0aWVzIiwiYnVpbGRQcm9wZXJ0aWVzIiwiY29udGV4d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