Constnium/node_modules/eslint-plugin-import/lib/rules/no-nodejs-modules.js

42 lines
4.4 KiB
JavaScript
Raw Normal View History

2022-06-23 02:27:43 +02:00
'use strict';var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_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 };}
function reportIfMissing(context, node, allowed, name) {
if (allowed.indexOf(name) === -1 && (0, _importType2['default'])(name, context) === 'builtin') {
context.report(node, 'Do not import Node.js builtin module "' + name + '"');
}
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2['default'])('no-nodejs-modules') },
schema: [
{
type: 'object',
properties: {
allow: {
type: 'array',
uniqueItems: true,
items: {
type: 'string' } } },
additionalProperties: false }] },
create: function () {function create(context) {
var options = context.options[0] || {};
var allowed = options.allow || [];
return (0, _moduleVisitor2['default'])(function (source, node) {
reportIfMissing(context, node, allowed, source.value);
}, { commonjs: true });
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1ub2RlanMtbW9kdWxlcy5qcyJdLCJuYW1lcyI6WyJyZXBvcnRJZk1pc3NpbmciLCJjb250ZXh0Iiwibm9kZSIsImFsbG93ZWQiLCJuYW1lIiwiaW5kZXhPZiIsInJlcG9ydCIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aWVzIiwiYWxsb3ciLCJ1bmlxdWVJdGVtcyIsIml0ZW1zIiwiYWRkaXRpb25hbFByb3BlcnRpZXMiLCJjcmVhdGUiLCJvcHRpb25zIiwic291cmNlIiwidmFsdWUiLCJjb21tb25qcyJd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