123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- 'use strict';var _declaredScope = require('eslint-module-utils/declaredScope');var _declaredScope2 = _interopRequireDefault(_declaredScope);
- var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
- var _importDeclaration = require('../importDeclaration');var _importDeclaration2 = _interopRequireDefault(_importDeclaration);
- var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
- module.exports = {
- meta: {
- type: 'problem',
- docs: {
- url: (0, _docsUrl2.default)('namespace') },
- schema: [
- {
- type: 'object',
- properties: {
- allowComputed: {
- description: 'If `false`, will report computed (and thus, un-lintable) references to namespace members.',
- type: 'boolean',
- default: false } },
- additionalProperties: false }] },
- create: function namespaceRule(context) {
- // read options
- var _ref =
- context.options[0] || {},_ref$allowComputed = _ref.allowComputed;const allowComputed = _ref$allowComputed === undefined ? false : _ref$allowComputed;
- const namespaces = new Map();
- function makeMessage(last, namepath) {
- return `'${last.name}' not found in ${namepath.length > 1 ? 'deeply ' : ''}imported namespace '${namepath.join('.')}'.`;
- }
- return {
- // pick up all imports at body entry time, to properly respect hoisting
- Program(_ref2) {let body = _ref2.body;
- function processBodyStatement(declaration) {
- if (declaration.type !== 'ImportDeclaration') return;
- if (declaration.specifiers.length === 0) return;
- const imports = _ExportMap2.default.get(declaration.source.value, context);
- if (imports == null) return null;
- if (imports.errors.length) {
- imports.reportErrors(context, declaration);
- return;
- }
- for (const specifier of declaration.specifiers) {
- switch (specifier.type) {
- case 'ImportNamespaceSpecifier':
- if (!imports.size) {
- context.report(
- specifier,
- `No exported names found in module '${declaration.source.value}'.`);
- }
- namespaces.set(specifier.local.name, imports);
- break;
- case 'ImportDefaultSpecifier':
- case 'ImportSpecifier':{
- const meta = imports.get(
- // default to 'default' for default http://i.imgur.com/nj6qAWy.jpg
- specifier.imported ? specifier.imported.name : 'default');
- if (!meta || !meta.namespace) {break;}
- namespaces.set(specifier.local.name, meta.namespace);
- break;
- }}
- }
- }
- body.forEach(processBodyStatement);
- },
- // same as above, but does not add names to local map
- ExportNamespaceSpecifier(namespace) {
- const declaration = (0, _importDeclaration2.default)(context);
- const imports = _ExportMap2.default.get(declaration.source.value, context);
- if (imports == null) return null;
- if (imports.errors.length) {
- imports.reportErrors(context, declaration);
- return;
- }
- if (!imports.size) {
- context.report(
- namespace,
- `No exported names found in module '${declaration.source.value}'.`);
- }
- },
- // todo: check for possible redefinition
- MemberExpression(dereference) {
- if (dereference.object.type !== 'Identifier') return;
- if (!namespaces.has(dereference.object.name)) return;
- if ((0, _declaredScope2.default)(context, dereference.object.name) !== 'module') return;
- if (dereference.parent.type === 'AssignmentExpression' && dereference.parent.left === dereference) {
- context.report(
- dereference.parent,
- `Assignment to member of namespace '${dereference.object.name}'.`);
- }
- // go deep
- let namespace = namespaces.get(dereference.object.name);
- const namepath = [dereference.object.name];
- // while property is namespace and parent is member expression, keep validating
- while (namespace instanceof _ExportMap2.default && dereference.type === 'MemberExpression') {
- if (dereference.computed) {
- if (!allowComputed) {
- context.report(
- dereference.property,
- `Unable to validate computed reference to imported namespace '${dereference.object.name}'.`);
- }
- return;
- }
- if (!namespace.has(dereference.property.name)) {
- context.report(
- dereference.property,
- makeMessage(dereference.property, namepath));
- break;
- }
- const exported = namespace.get(dereference.property.name);
- if (exported == null) return;
- // stash and pop
- namepath.push(dereference.property.name);
- namespace = exported.namespace;
- dereference = dereference.parent;
- }
- },
- VariableDeclarator(_ref3) {let id = _ref3.id,init = _ref3.init;
- if (init == null) return;
- if (init.type !== 'Identifier') return;
- if (!namespaces.has(init.name)) return;
- // check for redefinition in intermediate scopes
- if ((0, _declaredScope2.default)(context, init.name) !== 'module') return;
- // DFS traverse child namespaces
- function testKey(pattern, namespace) {let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [init.name];
- if (!(namespace instanceof _ExportMap2.default)) return;
- if (pattern.type !== 'ObjectPattern') return;
- for (const property of pattern.properties) {
- if (
- property.type === 'ExperimentalRestProperty' ||
- property.type === 'RestElement' ||
- !property.key)
- {
- continue;
- }
- if (property.key.type !== 'Identifier') {
- context.report({
- node: property,
- message: 'Only destructure top-level names.' });
- continue;
- }
- if (!namespace.has(property.key.name)) {
- context.report({
- node: property,
- message: makeMessage(property.key, path) });
- continue;
- }
- path.push(property.key.name);
- const dependencyExportMap = namespace.get(property.key.name);
- // could be null when ignored or ambiguous
- if (dependencyExportMap !== null) {
- testKey(property.value, dependencyExportMap.namespace, path);
- }
- path.pop();
- }
- }
- testKey(id, namespaces.get(init.name));
- },
- JSXMemberExpression(_ref4) {let object = _ref4.object,property = _ref4.property;
- if (!namespaces.has(object.name)) return;
- const namespace = namespaces.get(object.name);
- if (!namespace.has(property.name)) {
- context.report({
- node: property,
- message: makeMessage(property, [object.name]) });
- }
- } };
- } };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uYW1lc3BhY2UuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsInByb3BlcnRpZXMiLCJhbGxvd0NvbXB1dGVkIiwiZGVzY3JpcHRpb24iLCJkZWZhdWx0IiwiYWRkaXRpb25hbFByb3BlcnRpZXMiLCJjcmVhdGUiLCJuYW1lc3BhY2VSdWxlIiwiY29udGV4dCIsIm9wdGlvbnMiLCJuYW1lc3BhY2VzIiwiTWFwIiwibWFrZU1lc3NhZ2UiLCJsYXN0IiwibmFtZXBhdGgiLCJuYW1lIiwibGV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ghaW1wb3J0cy5zaXplKSB7XG4gICAgICAgICAgICAgICAgY29udGV4dC5yZXBvcnQoXG4gICAgICAgICAgICAgICAgICBzcGVjaWZpZXIsXG4gICAgICAgICAgICAgICAgICBgTm8gZXhwb3J0ZWQgbmFtZXMgZm91bmQgaW4gbW9kdWxlICcke2RlY2xhcmF0aW9uLnNvdXJjZS52YWx1ZX0nLmBcbiAgICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIG5hbWVzcGFjZXMuc2V0KHNwZWNpZmllci5sb2NhbC5uYW1lLCBpbXBvcnRzKTtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICBjYXNlICdJbXBvcnREZWZhdWx0U3BlY2lmaWVyJzpcbiAgICAgICAgICAgIGNhc2UgJ0ltcG9ydFNwZWNpZmllcic6IHtcbiAgICAgICAgICAgICAgY29uc3QgbWV0YSA9IGltcG9ydHMuZ2V0KFxuICAgICAgICAgICAgICAgIC8vIGRlZmF1bHQgdG8gJ2RlZmF1bHQnIGZvciBkZWZhdWx0IGh0dHA6Ly9pLmltZ3VyLmNvbS9uajZxQVd5LmpwZ1xuICAgICAgICAgICAgICAgIHNwZWNpZmllci5pbXBvcnRlZCA/IHNwZWNpZmllci5pbXBvcnRlZC5uYW1lIDogJ2RlZmF1bHQnXG4gICAgICAgICAgICAgICk7XG4gICAgICAgICAgICAgIGlmICghbWV0YSB8fCAhbWV0YS5uYW1lc3BhY2UpIHsgYnJlYWs7IH1cbiAgICAgICAgICAgICAgbmFtZXNwYWNlcy5zZXQoc3BlY2lmaWVyLmxvY2FsLm5hbWUsIG1ldGEubmFtZXNwYWNlKTtcbiAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGJvZHkuZm9yRWFjaChwcm9jZXNzQm9keVN0YXRlbWVudCk7XG4gICAgICB9LFxuXG4gICAgICAvL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WJsZSB0byB2YWxpZGF0ZSBjb21wdXRlZCByZWZlcmVuY2UgdG8gaW1wb3J0ZWQgbmFtZXNwYWNlICcke2RlcmVmZXJlbmNlLm9iamVjdC5uYW1lfScuYFxuICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmICghbmFtZXNwYWNlLmhhcyhkZXJlZmVyZW5jZS5wcm9wZXJ0eS5uYW1lKSkge1xuICAgICAgICAgICAgY29udGV4dC5yZXBvcnQoXG4gICAgICAgICAgICAgIGRlcmVmZXJlbmNlLnByb3BlcnR5LFxuICAgICAgICAgICAgICBtYWtlTWVzc2FnZShkZXJlZmVyZW5jZS5wcm9wZXJ0eSwgbmFtZXBhdGgpXG4gICAgICAgICAgICApO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgY29uc3QgZXhwb3J0ZWQgPSBuYW1lc3BhY2UuZ2V0KGRlcmVmZXJlbmNlLnByb3BlcnR5Lm5hbWUpO1xuICAgICAgICAgIGlmIChleHBvcnRlZCA9PSBudWxsKSByZXR1cm47XG5cbiAgICAgICAgICAvLyBzdGFzaCBhbmQgcG9wXG4gICAgICAgICAgbmFtZXBhdGgucHVzaChkZXJlZmVyZW5jZS5wcm9wZXJ0eS5uYW1lKTtcbiAgICAgICAgICBuYW1lc3BhY2UgPSBleHBvcnRlZC5uYW1lc3BhY2U7XG4gICAgICAgICAgZGVyZWZlcmVuY2UgPSBkZXJlZmVyZW5jZS5wYXJlbnQ7XG4gICAgICAgIH1cblxuICAgICAgfSxcblxuICAgICAgVmFyaWFibGVEZWNsYXJhdG9yKHsgaWQsIGluaXQgfSkge1xuICAgICAgICBpZiAoaW5pdCA9PSBudWxsKSByZXR1cm47XG4gICAgICAgIGlmIChpbml0LnR5cGUgIT09ICdJZGVudGlmaWVyJykgcmV0dXJuO1xuICAgICAgICBpZiAoIW5hbWVzcGFjZXMuaGFzKGluaXQubmFtZSkpIHJldHVybjtcblxuICAgICAgICAvLyBjaGVjayBmb3IgcmVkZWZpbml0aW9uIGluIGludGVybWVkaWF0ZSBzY29wZXNcbiAgICAgICAgaWYgKGRlY2xhcmVkU2NvcGUoY29udGV4dCwgaW5pdC5uYW1lKSAhPT0gJ21vZHVsZScpIHJldHVybjtcblxuICAgICAgICAvLyBERlMgdHJhdmVyc2UgY2hpbGQgbmFtZXNwYWNlc1xuICAgICAgICBmdW5jdGlvbiB0ZXN0S2V5KHBhdHRlcm4sIG5hbWVzcGFjZSwgcGF0aCA9IFtpbml0Lm5hbWVdKSB7XG4gICAgICAgICAgaWYgKCEobmFtZXNwYWNlIGluc3RhbmNlb2YgRXhwb3J0cykpIHJldHVybjtcblxuICAgICAgICAgIGlmIChwYXR0ZXJuLnR5cGUgIT09ICdPYmplY3RQYXR0ZXJuJykgcmV0dXJuO1xuXG4gICAgICAgICAgZm9yIChjb25zdCBwcm9wZXJ0eSBvZiBwYXR0ZXJuLnByb3BlcnRpZXMpIHtcbiAgICAgICAgICAgIGlmIChcbiAgICAgICAgICAgICAgcHJvcGVydHkudHlwZSA9PT0gJ0V4cGVyaW1lbnRhbFJlc3RQcm9wZXJ0eSdcbiAgICAgICAgICAgICAgfHwgcHJvcGVydHkudHlwZSA9PT0gJ1Jlc3RFbGVtZW50J1xuICAgICAgICAgICAgICB8fCAhcHJvcGVydHkua2V5XG4gICAgICAgICAgICApIHtcbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChwcm9wZXJ0eS5rZXkudHlwZSAhPT0gJ0lkZW50aWZpZXInKSB7XG4gICAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgICAgICBub2RlOiBwcm9wZXJ0eSxcbiAgICAgICAgICAgICAgICBtZXNzYWdlOiAnT25seSBkZXN0cnVjdHVyZSB0b3AtbGV2ZWwgbmFtZXMuJyxcbiAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoIW5hbWVzcGFjZS5oYXMocHJvcGVydHkua2V5Lm5hbWUpKSB7XG4gICAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgICAgICBub2RlOiBwcm9wZXJ0eSxcbiAgICAgICAgICAgICAgICBtZXNzYWdlOiBtYWtlTWVzc2FnZShwcm9wZXJ0eS5rZXksIHBhdGgpLFxuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHBhdGgucHVzaChwcm9wZXJ0eS5rZXkubmFtZSk7XG4gICAgICAgICAgICBjb25zdCBkZXBlbmRlbmN5RXhwb3J0TWFwID0gbmFtZXNwYWNlLmdldChwcm9wZXJ0eS5rZXkubmFtZSk7XG4gICAgICAgICAgICAvLyBjb3VsZCBiZSBudWxsIHdoZW4gaWdub3JlZCBvciBhbWJpZ3VvdXNcbiAgICAgICAgICAgIGlmIChkZXBlbmRlbmN5RXhwb3J0TWFwICE9PSBudWxsKSB7XG4gICAgICAgICAgICAgIHRlc3RLZXkocHJvcGVydHkudmFsdWUsIGRlcGVuZGVuY3lFeHBvcnRNYXAubmFtZXNwYWNlLCBwYXRoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhdGgucG9wKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdGVzdEtleShpZCwgbmFtZXNwYWNlcy5nZXQoaW5pdC5uYW1lKSk7XG4gICAgICB9LFxuXG4gICAgICBKU1hNZW1iZXJFeHByZXNzaW9uKHsgb2JqZWN0LCBwcm9wZXJ0eSB9KSB7XG4gICAgICAgIGlmICghbmFtZXNwYWNlcy5oYXMob2JqZWN0Lm5hbWUpKSByZXR1cm47XG4gICAgICAgIGNvbnN0IG5hbWVzcGFjZSA9IG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