no-commonjs.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 'use strict';
  2. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
  3. var EXPORT_MESSAGE = 'Expected "export" or "export default"'; /**
  4. * @fileoverview Rule to prefer ES6 to CJS
  5. * @author Jamund Ferguson
  6. */var IMPORT_MESSAGE = 'Expected "import" instead of "require()"';function normalizeLegacyOptions(options) {
  7. if (options.indexOf('allow-primitive-modules') >= 0) {
  8. return { allowPrimitiveModules: true };
  9. }
  10. return options[0] || {};
  11. }
  12. function allowPrimitive(node, options) {
  13. if (!options.allowPrimitiveModules) {return false;}
  14. if (node.parent.type !== 'AssignmentExpression') {return false;}
  15. return node.parent.right.type !== 'ObjectExpression';
  16. }
  17. function allowRequire(node, options) {
  18. return options.allowRequire;
  19. }
  20. function allowConditionalRequire(node, options) {
  21. return options.allowConditionalRequire !== false;
  22. }
  23. function validateScope(scope) {
  24. return scope.variableScope.type === 'module';
  25. }
  26. // https://github.com/estree/estree/blob/HEAD/es5.md
  27. function isConditional(node) {
  28. if (
  29. node.type === 'IfStatement' ||
  30. node.type === 'TryStatement' ||
  31. node.type === 'LogicalExpression' ||
  32. node.type === 'ConditionalExpression')
  33. {
  34. return true;
  35. }
  36. if (node.parent) {return isConditional(node.parent);}
  37. return false;
  38. }
  39. function isLiteralString(node) {
  40. return node.type === 'Literal' && typeof node.value === 'string' ||
  41. node.type === 'TemplateLiteral' && node.expressions.length === 0;
  42. }
  43. //------------------------------------------------------------------------------
  44. // Rule Definition
  45. //------------------------------------------------------------------------------
  46. var schemaString = { 'enum': ['allow-primitive-modules'] };
  47. var schemaObject = {
  48. type: 'object',
  49. properties: {
  50. allowPrimitiveModules: { type: 'boolean' },
  51. allowRequire: { type: 'boolean' },
  52. allowConditionalRequire: { type: 'boolean' } },
  53. additionalProperties: false };
  54. module.exports = {
  55. meta: {
  56. type: 'suggestion',
  57. docs: {
  58. category: 'Module systems',
  59. description: 'Forbid CommonJS `require` calls and `module.exports` or `exports.*`.',
  60. url: (0, _docsUrl2['default'])('no-commonjs') },
  61. schema: {
  62. anyOf: [
  63. {
  64. type: 'array',
  65. items: [schemaString],
  66. additionalItems: false },
  67. {
  68. type: 'array',
  69. items: [schemaObject],
  70. additionalItems: false }] } },
  71. create: function () {function create(context) {
  72. var options = normalizeLegacyOptions(context.options);
  73. return {
  74. MemberExpression: function () {function MemberExpression(node) {
  75. // module.exports
  76. if (node.object.name === 'module' && node.property.name === 'exports') {
  77. if (allowPrimitive(node, options)) {return;}
  78. context.report({ node: node, message: EXPORT_MESSAGE });
  79. }
  80. // exports.
  81. if (node.object.name === 'exports') {
  82. var isInScope = context.getScope().
  83. variables.
  84. some(function (variable) {return variable.name === 'exports';});
  85. if (!isInScope) {
  86. context.report({ node: node, message: EXPORT_MESSAGE });
  87. }
  88. }
  89. }return MemberExpression;}(),
  90. CallExpression: function () {function CallExpression(call) {
  91. if (!validateScope(context.getScope())) {return;}
  92. if (call.callee.type !== 'Identifier') {return;}
  93. if (call.callee.name !== 'require') {return;}
  94. if (call.arguments.length !== 1) {return;}
  95. if (!isLiteralString(call.arguments[0])) {return;}
  96. if (allowRequire(call, options)) {return;}
  97. if (allowConditionalRequire(call, options) && isConditional(call.parent)) {return;}
  98. // keeping it simple: all 1-string-arg `require` calls are reported
  99. context.report({
  100. node: call.callee,
  101. message: IMPORT_MESSAGE });
  102. }return CallExpression;}() };
  103. }return create;}() };
  104. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jb21tb25qcy5qcyJdLCJuYW1lcyI6WyJFWFBPUlRfTUVTU0FHRSIsIklNUE9SVF9NR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