no-commonjs.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. return true;
  34. if (node.parent) return isConditional(node.parent);
  35. return false;
  36. }
  37. function isLiteralString(node) {
  38. return node.type === 'Literal' && typeof node.value === 'string' ||
  39. node.type === 'TemplateLiteral' && node.expressions.length === 0;
  40. }
  41. //------------------------------------------------------------------------------
  42. // Rule Definition
  43. //------------------------------------------------------------------------------
  44. var schemaString = { 'enum': ['allow-primitive-modules'] };
  45. var schemaObject = {
  46. type: 'object',
  47. properties: {
  48. allowPrimitiveModules: { 'type': 'boolean' },
  49. allowRequire: { 'type': 'boolean' },
  50. allowConditionalRequire: { 'type': 'boolean' } },
  51. additionalProperties: false };
  52. module.exports = {
  53. meta: {
  54. type: 'suggestion',
  55. docs: {
  56. url: (0, _docsUrl2['default'])('no-commonjs') },
  57. schema: {
  58. anyOf: [
  59. {
  60. type: 'array',
  61. items: [schemaString],
  62. additionalItems: false },
  63. {
  64. type: 'array',
  65. items: [schemaObject],
  66. additionalItems: false }] } },
  67. create: function () {function create(context) {
  68. var options = normalizeLegacyOptions(context.options);
  69. return {
  70. 'MemberExpression': function () {function MemberExpression(node) {
  71. // module.exports
  72. if (node.object.name === 'module' && node.property.name === 'exports') {
  73. if (allowPrimitive(node, options)) return;
  74. context.report({ node: node, message: EXPORT_MESSAGE });
  75. }
  76. // exports.
  77. if (node.object.name === 'exports') {
  78. var isInScope = context.getScope().
  79. variables.
  80. some(function (variable) {return variable.name === 'exports';});
  81. if (!isInScope) {
  82. context.report({ node: node, message: EXPORT_MESSAGE });
  83. }
  84. }
  85. }return MemberExpression;}(),
  86. 'CallExpression': function () {function CallExpression(call) {
  87. if (!validateScope(context.getScope())) return;
  88. if (call.callee.type !== 'Identifier') return;
  89. if (call.callee.name !== 'require') return;
  90. if (call.arguments.length !== 1) return;
  91. if (!isLiteralString(call.arguments[0])) return;
  92. if (allowRequire(call, options)) return;
  93. if (allowConditionalRequire(call, options) && isConditional(call.parent)) return;
  94. // keeping it simple: all 1-string-arg `require` calls are reported
  95. context.report({
  96. node: call.callee,
  97. message: IMPORT_MESSAGE });
  98. }return CallExpression;}() };
  99. }return create;}() };
  100. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jb21tb25qcy5qcyJdLCJuYW1lcyI6WyJFWFBPUlRfTUVTU0FHRSIsIklNUE9SVF9NRVNTQUdFIiwibm9ybWFsaXplTGVnYWN5T3B0aW9ucyIsIm9wdGlvbnMiLCJpbmRleE9mIiwiYWxsb3dQc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hOiB7XG4gICAgICBhbnlPZjogW1xuICAgICAgICB7XG4gICAgICAgICAgdHlwZTogJ2FycmF5JyxcbiAgICAgICAgICBpdGVtczogW3NjaGVtYVN0cmluZ10sXG4gICAgICAgICAgYWRkaXRpb25hbEl0ZW1zOiBmYWxzZSxcbiAgICAgICAgfSxcbiAgICAgICAge1xuICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgaXRlbXM6IFtzY2hlbWFPYmplY3RdLFxuICAgICAgICAgIGFkZGl0aW9uYWxJdGVtczogZmFsc2UsXG4gICAgICAgIH0sXG4gICAgICBdLFxuICAgIH0sXG4gIH0sXG5cbiAgY3JlYXRlKGNvbnRleHQpIHtcbiAgICBjb25zdCBvcHRpb25zID0gbm9ybWFsaXplTGVnYWN5T3B0aW9ucyhjb250ZXh0Lm9wdGlvbnMpO1xuXG4gICAgcmV0dXJuIHtcblxuICAgICAgJ01lbWJlckV4cHJlc3Npb24nOiBmdW5jdGlvbiAobm9kZSkge1xuXG4gICAgICAgIC8vIG1vZHVsZS5leHBvcnRzXG4gICAgICAgIGlmIChub2RlLm9iamVjdC5uYW1lID09PSAnbW9kdWxlJyAmJiBub2RlLnByb3BlcnR5Lm5hbWUgPT09ICdleHBvcnRzJykge1xuICAgICAgICAgIGlmIChhbGxvd1ByaW1pdGl2ZShub2RlLCBvcHRpb25zKSkgcmV0dXJuO1xuICAgICAgICAgIGNvbnRleHQucmVwb3J0KHsgbm9kZSwgbWVzc2FnZTogRVhQT1JUX01FU1NBR0UgfSk7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBleHBvcnRzLlxuICAgICAgICBpZiAobm9kZS5vYmplY3QubmFtZSA9PT0gJ2V4cG9ydHMnKSB7XG4gICAgICAgICAgY29uc3QgaXNJblNjb3BlID0gY29udGV4dC5nZXRTY29wZSgpXG4gICAgICAgICAgICAudmFyaWFibGVzXG4gICAgICAgICAgICAuc29tZSh2YXJpYWJsZSA9PiB2YXJpYWJsZS5uYW1lID09PS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