no-commonjs.js 13 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. const EXPORT_MESSAGE = 'Expected "export" or "export default"'; /**
  4. * @fileoverview Rule to prefer ES6 to CJS
  5. * @author Jamund Ferguson
  6. */const 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/master/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. const schemaString = { enum: ['allow-primitive-modules'] };
  45. const 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 (context) {
  68. const options = normalizeLegacyOptions(context.options);
  69. return {
  70. 'MemberExpression': function (node) {
  71. // module.exports
  72. if (node.object.name === 'module' && node.property.name === 'exports') {
  73. if (allowPrimitive(node, options)) return;
  74. context.report({ node, message: EXPORT_MESSAGE });
  75. }
  76. // exports.
  77. if (node.object.name === 'exports') {
  78. const isInScope = context.getScope().
  79. variables.
  80. some(variable => variable.name === 'exports');
  81. if (!isInScope) {
  82. context.report({ node, message: EXPORT_MESSAGE });
  83. }
  84. }
  85. },
  86. 'CallExpression': function (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. } };
  99. } };
  100. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1jb21tb25qcy5qcyJdLCJuYW1lcyI6WyJFWFBPUlRfTUVTU0FHRSIsIklNUE9SVF9NRVNTQUdFIiwibm9ybWFsaXplTGVnYWN5T3B0aW9ucyIsIm9wdGlvbnMiLCJpbmRleE9mIiwiYWxsb3dQcmltaXRpdmVNb2R1bGVzIiwiYWxsb3dQcmltaXRpdmUiLCJub2RlIiwicGFyZW50IiwidH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iAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgIGl0ZW1zOiBbc2NoZW1hT2JqZWN0XSxcbiAgICAgICAgICBhZGRpdGlvbmFsSXRlbXM6IGZhbHNlLFxuICAgICAgICB9LFxuICAgICAgXSxcbiAgICB9LFxuICB9LFxuXG4gIGNyZWF0ZTogZnVuY3Rpb24gKGNvbnRleHQpIHtcbiAgICBjb25zdCBvcHRpb25zID0gbm9ybWFsaXplTGVnYWN5T3B0aW9ucyhjb250ZXh0Lm9wdGlvbnMpO1xuXG4gICAgcmV0dXJuIHtcblxuICAgICAgJ01lbWJlckV4cHJlc3Npb24nOiBmdW5jdGlvbiAobm9kZSkge1xuXG4gICAgICAgIC8vIG1vZHVsZS5leHBvcnRzXG4gICAgICAgIGlmIChub2RlLm9iamVjdC5uYW1lID09PSAnbW9kdWxlJyAmJiBub2RlLnByb3BlcnR5Lm5hbWUgPT09ICdleHBvcnRzJykge1xuICAgICAgICAgIGlmIChhbGxvd1ByaW1pdGl2ZShub2RlLCBvcHRpb25zKSkgcmV0dXJuO1xuICAgICAgICAgIGNvbnRleHQucmVwb3J0KHsgbm9kZSwgbWVzc2FnZTogRVhQT1JUX01FU1NBR0UgfSk7XG4gICAgICAgIH1cblxuICAgICAgICAvLyBleHBvcnRzLlxuICAgICAgICBpZiAobm9kZS5vYmplY3QubmFtZSA9PT0gJ2V4cG9ydHMnKSB7XG4gICAgICAgICAgY29uc3QgaXNJblNjb3BlID0gY29udGV4dC5nZXRTY29wZSgpXG4gICAgICAgICAgICAudmFyaWFibGVzXG4gICAgICAgICAgICAuc29tZSh2YXJpYWJsZSA9PiB2YXJpYWJsZS5uYW1lID09PSAnZXhwb3J0cycpO1xuICAgICAgICAgIGlmICghIGlzSW5TY29wZSkge1xuICAgICAgICAgICAgY29udGV4dC5yZXBvcnQoeyBub2RlLCBtZXNzYWdlOiBFWFBPUlRfTUVTU0FHRSB9KTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICA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