no-undefined-identifier.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. function argumentsIsUndefinedString(argumentsArray) {
  3. return (
  4. argumentsArray.length === 1 &&
  5. argumentsArray[0].type === "Literal" &&
  6. argumentsArray[0].value === "undefined"
  7. );
  8. }
  9. module.exports = {
  10. meta: {
  11. schema: [],
  12. },
  13. create: function(context) {
  14. if (context.getFilename().indexOf("packages/babel-plugin-") === -1) {
  15. return {};
  16. }
  17. return {
  18. CallExpression: function(node) {
  19. const callee = node.callee;
  20. if (
  21. callee.type === "MemberExpression" &&
  22. argumentsIsUndefinedString(node.arguments)
  23. ) {
  24. const object = callee.object,
  25. property = callee.property;
  26. if (
  27. object.type === "Identifier" &&
  28. object.name === "t" &&
  29. property.type === "Identifier" &&
  30. property.name === "identifier"
  31. ) {
  32. context.report(
  33. node,
  34. "Use path.scope.buildUndefinedNode() to create an undefined identifier directly."
  35. );
  36. }
  37. }
  38. },
  39. };
  40. },
  41. };