securityos/node_modules/eslint-plugin-import/lib/rules/no-commonjs.js

141 lines
14 KiB
JavaScript

'use strict';
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
var EXPORT_MESSAGE = 'Expected "export" or "export default"'; /**
* @fileoverview Rule to prefer ES6 to CJS
* @author Jamund Ferguson
*/var IMPORT_MESSAGE = 'Expected "import" instead of "require()"';function normalizeLegacyOptions(options) {
if (options.indexOf('allow-primitive-modules') >= 0) {
return { allowPrimitiveModules: true };
}
return options[0] || {};
}
function allowPrimitive(node, options) {
if (!options.allowPrimitiveModules) {return false;}
if (node.parent.type !== 'AssignmentExpression') {return false;}
return node.parent.right.type !== 'ObjectExpression';
}
function allowRequire(node, options) {
return options.allowRequire;
}
function allowConditionalRequire(node, options) {
return options.allowConditionalRequire !== false;
}
function validateScope(scope) {
return scope.variableScope.type === 'module';
}
// https://github.com/estree/estree/blob/HEAD/es5.md
function isConditional(node) {
if (
node.type === 'IfStatement' ||
node.type === 'TryStatement' ||
node.type === 'LogicalExpression' ||
node.type === 'ConditionalExpression')
{
return true;
}
if (node.parent) {return isConditional(node.parent);}
return false;
}
function isLiteralString(node) {
return node.type === 'Literal' && typeof node.value === 'string' ||
node.type === 'TemplateLiteral' && node.expressions.length === 0;
}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
var schemaString = { 'enum': ['allow-primitive-modules'] };
var schemaObject = {
type: 'object',
properties: {
allowPrimitiveModules: { type: 'boolean' },
allowRequire: { type: 'boolean' },
allowConditionalRequire: { type: 'boolean' } },
additionalProperties: false };
module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Module systems',
description: 'Forbid CommonJS `require` calls and `module.exports` or `exports.*`.',
url: (0, _docsUrl2['default'])('no-commonjs') },
schema: {
anyOf: [
{
type: 'array',
items: [schemaString],
additionalItems: false },
{
type: 'array',
items: [schemaObject],
additionalItems: false }] } },
create: function () {function create(context) {
var options = normalizeLegacyOptions(context.options);
return {
MemberExpression: function () {function MemberExpression(node) {
// module.exports
if (node.object.name === 'module' && node.property.name === 'exports') {
if (allowPrimitive(node, options)) {return;}
context.report({ node: node, message: EXPORT_MESSAGE });
}
// exports.
if (node.object.name === 'exports') {
var isInScope = context.getScope().
variables.
some(function (variable) {return variable.name === 'exports';});
if (!isInScope) {
context.report({ node: node, message: EXPORT_MESSAGE });
}
}
}return MemberExpression;}(),
CallExpression: function () {function CallExpression(call) {
if (!validateScope(context.getScope())) {return;}
if (call.callee.type !== 'Identifier') {return;}
if (call.callee.name !== 'require') {return;}
if (call.arguments.length !== 1) {return;}
if (!isLiteralString(call.arguments[0])) {return;}
if (allowRequire(call, options)) {return;}
if (allowConditionalRequire(call, options) && isConditional(call.parent)) {return;}
// keeping it simple: all 1-string-arg `require` calls are reported
context.report({
node: call.callee,
message: IMPORT_MESSAGE });
}return CallExpression;}() };
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jb21tb25qcy5qcyJdLCJuYW1lcyI6WyJFWFBPUlRfTUVTU0FHRSIsIklNUE9SVF9NRVNTQUdFIiwibm9ybWFsaXplTGVnYWN5T3B0aW9ucyIsIm9wdGlvbnMiLCJpbmRleE9mIiwiYWxsb3dQcmltaXRpdmVNb2R1bGVzIiwiYWxsb3dQcmltaXRpdmUiLCJub2RlIiwicGFyZW50IiwidHlwZSIsInJpZ2h0IiwiYWxsb3dSZXF1aXJlIiwiYWxsb3dDb25kaXRpb25hbFJlcXVpcmUiLCJ2YWxpZGF0ZVNjb3BlIiwic2NvcGUiLCJ2YXJpYWJsZVNjb3BlIiwiaXNDb25kaXRpb25hbCIsImlzTGl0ZXJhbFN0cmluZyIsInZhbHVlIiwiZXhwcmVzc2lvbnMiLCJsZW5ndGgiLCJzY2hlbWFTdHJpbmciLCJzY2hlbWFPYmplY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