mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
177 lines
22 KiB
JavaScript
177 lines
22 KiB
JavaScript
'use strict';
|
|
|
|
|
|
|
|
|
|
var _minimatch = require('minimatch');var _minimatch2 = _interopRequireDefault(_minimatch);
|
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {arr2[i] = arr[i];}return arr2;} else {return Array.from(arr);}} /**
|
|
* @fileoverview Rule to disallow namespace import
|
|
* @author Radek Benkel
|
|
*/ //------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2['default'])('no-namespace') },
|
|
|
|
fixable: 'code',
|
|
schema: [{
|
|
type: 'object',
|
|
properties: {
|
|
ignore: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'string' },
|
|
|
|
uniqueItems: true } } }] },
|
|
|
|
|
|
|
|
|
|
|
|
create: function () {function create(context) {
|
|
var firstOption = context.options[0] || {};
|
|
var ignoreGlobs = firstOption.ignore;
|
|
|
|
return {
|
|
ImportNamespaceSpecifier: function () {function ImportNamespaceSpecifier(node) {
|
|
if (ignoreGlobs && ignoreGlobs.find(function (glob) {return (0, _minimatch2['default'])(node.parent.source.value, glob, { matchBase: true });})) {
|
|
return;
|
|
}
|
|
|
|
var scopeVariables = context.getScope().variables;
|
|
var namespaceVariable = scopeVariables.find(function (variable) {return variable.defs[0].node === node;});
|
|
var namespaceReferences = namespaceVariable.references;
|
|
var namespaceIdentifiers = namespaceReferences.map(function (reference) {return reference.identifier;});
|
|
var canFix = namespaceIdentifiers.length > 0 && !usesNamespaceAsObject(namespaceIdentifiers);
|
|
|
|
context.report({
|
|
node: node,
|
|
message: 'Unexpected namespace import.',
|
|
fix: canFix && function (fixer) {
|
|
var scopeManager = context.getSourceCode().scopeManager;
|
|
var fixes = [];
|
|
|
|
// Pass 1: Collect variable names that are already in scope for each reference we want
|
|
// to transform, so that we can be sure that we choose non-conflicting import names
|
|
var importNameConflicts = {};
|
|
namespaceIdentifiers.forEach(function (identifier) {
|
|
var parent = identifier.parent;
|
|
if (parent && parent.type === 'MemberExpression') {
|
|
var importName = getMemberPropertyName(parent);
|
|
var localConflicts = getVariableNamesInScope(scopeManager, parent);
|
|
if (!importNameConflicts[importName]) {
|
|
importNameConflicts[importName] = localConflicts;
|
|
} else {
|
|
localConflicts.forEach(function (c) {return importNameConflicts[importName].add(c);});
|
|
}
|
|
}
|
|
});
|
|
|
|
// Choose new names for each import
|
|
var importNames = Object.keys(importNameConflicts);
|
|
var importLocalNames = generateLocalNames(
|
|
importNames,
|
|
importNameConflicts,
|
|
namespaceVariable.name);
|
|
|
|
|
|
// Replace the ImportNamespaceSpecifier with a list of ImportSpecifiers
|
|
var namedImportSpecifiers = importNames.map(function (importName) {return (
|
|
importName === importLocalNames[importName] ?
|
|
importName : String(
|
|
importName) + ' as ' + String(importLocalNames[importName]));});
|
|
|
|
fixes.push(fixer.replaceText(node, '{ ' + String(namedImportSpecifiers.join(', ')) + ' }'));
|
|
|
|
// Pass 2: Replace references to the namespace with references to the named imports
|
|
namespaceIdentifiers.forEach(function (identifier) {
|
|
var parent = identifier.parent;
|
|
if (parent && parent.type === 'MemberExpression') {
|
|
var importName = getMemberPropertyName(parent);
|
|
fixes.push(fixer.replaceText(parent, importLocalNames[importName]));
|
|
}
|
|
});
|
|
|
|
return fixes;
|
|
} });
|
|
|
|
}return ImportNamespaceSpecifier;}() };
|
|
|
|
}return create;}() };
|
|
|
|
|
|
/**
|
|
* @param {Identifier[]} namespaceIdentifiers
|
|
* @returns {boolean} `true` if the namespace variable is more than just a glorified constant
|
|
*/
|
|
function usesNamespaceAsObject(namespaceIdentifiers) {
|
|
return !namespaceIdentifiers.every(function (identifier) {
|
|
var parent = identifier.parent;
|
|
|
|
// `namespace.x` or `namespace['x']`
|
|
return (
|
|
parent && parent.type === 'MemberExpression' && (
|
|
parent.property.type === 'Identifier' || parent.property.type === 'Literal'));
|
|
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {MemberExpression} memberExpression
|
|
* @returns {string} the name of the member in the object expression, e.g. the `x` in `namespace.x`
|
|
*/
|
|
function getMemberPropertyName(memberExpression) {
|
|
return memberExpression.property.type === 'Identifier' ?
|
|
memberExpression.property.name :
|
|
memberExpression.property.value;
|
|
}
|
|
|
|
/**
|
|
* @param {ScopeManager} scopeManager
|
|
* @param {ASTNode} node
|
|
* @return {Set<string>}
|
|
*/
|
|
function getVariableNamesInScope(scopeManager, node) {
|
|
var currentNode = node;
|
|
var scope = scopeManager.acquire(currentNode);
|
|
while (scope == null) {
|
|
currentNode = currentNode.parent;
|
|
scope = scopeManager.acquire(currentNode, true);
|
|
}
|
|
return new Set([].concat(_toConsumableArray(
|
|
scope.variables.map(function (variable) {return variable.name;})), _toConsumableArray(
|
|
scope.upper.variables.map(function (variable) {return variable.name;}))));
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} names
|
|
* @param {*} nameConflicts
|
|
* @param {*} namespaceName
|
|
*/
|
|
function generateLocalNames(names, nameConflicts, namespaceName) {
|
|
var localNames = {};
|
|
names.forEach(function (name) {
|
|
var localName = void 0;
|
|
if (!nameConflicts[name].has(name)) {
|
|
localName = name;
|
|
} else if (!nameConflicts[name].has(String(namespaceName) + '_' + String(name))) {
|
|
localName = String(namespaceName) + '_' + String(name);
|
|
} else {
|
|
for (var i = 1; i < Infinity; i++) {
|
|
if (!nameConflicts[name].has(String(namespaceName) + '_' + String(name) + '_' + String(i))) {
|
|
localName = String(namespaceName) + '_' + String(name) + '_' + String(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
localNames[name] = localName;
|
|
});
|
|
return localNames;
|
|
}
|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3J0TmFtZSkgPT4gKFxuICAgICAgICAgICAgICBpbXBvcnROYW1lID09PSBpbXBvcnRMb2NhbE5hbWVzW2ltcG9ydE5hbWVdXG4gICAgICAgICAgICAgICAgPyBpbXBvcnROYW1lXG4gICAgICAgICAgICAgICAgOiBgJHtpbXBvcnROYW1lfSBhcyAke2ltcG9ydExvY2FsTmFtZXNbaW1wb3J0TmFtZV19YFxuICAgICAgICAgICAgKSk7XG4gICAgICAgICAgICBmaXhlcy5wdXNoKGZpeGVyLnJlcGxhY2VUZXh0KG5vZGUsIGB7ICR7bmFtZWRJbXBvcnRTcGVjaWZpZXJzLmpvaW4oJywgJyl9IH1gKSk7XG5cbiAgICAgICAgICAgIC8vIFBhc3MgMjogUmVwbGFjZSByZWZlcmVuY2VzIHRvIHRoZSBuYW1lc3BhY2Ugd2l0aCByZWZlcmVuY2VzIHRvIHRoZSBuYW1lZCBpbXBvcnRzXG4gICAgICAgICAgICBuYW1lc3BhY2VJZGVudGlmaWVycy5mb3JFYWNoKChpZGVudGlmaWVyKSA9PiB7XG4gICAgICAgICAgICAgIGNvbnN0IHBhcmVudCA9IGlkZW50aWZpZXIucGFyZW50O1xuICAgICAgICAgICAgICBpZiAocGFyZW50ICYmIHBhcmVudC50eXBlID09PSAnTWVtYmVyRXhwcmVzc2lvbicpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBpbXBvcnROYW1lID0gZ2V0TWVtYmVyUHJvcGVydHlOYW1lKHBhcmVudCk7XG4gICAgICAgICAgICAgICAgZml4ZXMucHVzaChmaXhlci5yZXBsYWNlVGV4dChwYXJlbnQsIGltcG9ydExvY2FsTmFtZXNbaW1wb3J0TmFtZV0pKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgIHJldHVybiBmaXhlcztcbiAgICAgICAgICB9KSxcbiAgICAgICAgfSk7XG4gICAgICB9LFxuICAgIH07XG4gIH0sXG59O1xuXG4vKipcbiAqIEBwYXJhbSB7SWR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