no-nodejs-modules.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType);
  2. var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
  3. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  4. function reportIfMissing(context, node, allowed, name) {
  5. if (allowed.indexOf(name) === -1 && (0, _importType2.default)(name, context) === 'builtin') {
  6. context.report(node, 'Do not import Node.js builtin module "' + name + '"');
  7. }
  8. }
  9. module.exports = {
  10. meta: {
  11. type: 'suggestion',
  12. docs: {
  13. url: (0, _docsUrl2.default)('no-nodejs-modules') },
  14. schema: [
  15. {
  16. type: 'object',
  17. properties: {
  18. allow: {
  19. type: 'array',
  20. uniqueItems: true,
  21. items: {
  22. type: 'string' } } },
  23. additionalProperties: false }] },
  24. create: function (context) {
  25. const options = context.options[0] || {};
  26. const allowed = options.allow || [];
  27. return (0, _moduleVisitor2.default)((source, node) => {
  28. reportIfMissing(context, node, allowed, source.value);
  29. }, { commonjs: true });
  30. } };
  31. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1ub2RlanMtbW9kdWxlcy5qcyJdLCJuYW1lcyI6WyJyZXBvcnRJZk1pc3NpbmciLCJjb250ZXh0Iiwibm9kZSIsImFsbG93ZWQiLCJuYW1lIiwiaW5kZXhPZiIsInJlcG9ydCIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aWVzIiwiYWxsb3ciLCJ1bmlxdWVJdGVtcyIsIml0ZW1zIiwiYWRkaXRpb25hbFByb3BlcnRpZXMiLCJjcmVhdGUiLCJvc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nc3RyaW5nJyxcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgfSxcbiAgICAgICAgfSxcbiAgICAgICAgYWRkaXRpb25hbFByb3BlcnRpZXM6IGZhbHNlLFxuICAgICAgfSxcbiAgICBdLFxuICB9LFxuXG4gIGNyZWF0ZTogZnVuY3Rpb24gKGNvbnRleHQpIHtcbiAgICBjb25zdCBvcHRpb25zID0gY29udGV4dC5vcHRpb25zWzBdIHx8IHt9O1xuICAgIGNvbnN0IGFsbG93ZWQgPSBvcHRpb25zLmFsbG93IHx8IFtdO1xuXG4gICAgcmV0dXJuIG1vZHVsZVZpc2l0b3IoKHNvdXJjZSwgbm9kZSkgPT4ge1xuICAgICAgcmVwb3J0SWZNaXNzaW5nKGNvbnRleHQsIG5vZGUsIGFsbG93ZWQsIHNvdXJjZS52YWx1ZSk7XG4gICAgfSwgeyBjb21tb25qczogdHJ1ZSB9KTtcbiAgfSxcbn07XG4iXX0=