no-sync.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @fileoverview Rule to check for properties whose identifier ends with the string Sync
  3. * @author Matt DuVall<http://mattduvall.com/>
  4. */
  5. /* jshint node:true */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. type: "suggestion",
  13. docs: {
  14. description: "disallow synchronous methods",
  15. category: "Node.js and CommonJS",
  16. recommended: false,
  17. url: "https://eslint.org/docs/rules/no-sync"
  18. },
  19. schema: [
  20. {
  21. type: "object",
  22. properties: {
  23. allowAtRootLevel: {
  24. type: "boolean",
  25. default: false
  26. }
  27. },
  28. additionalProperties: false
  29. }
  30. ]
  31. },
  32. create(context) {
  33. const selector = context.options[0] && context.options[0].allowAtRootLevel
  34. ? ":function MemberExpression[property.name=/.*Sync$/]"
  35. : "MemberExpression[property.name=/.*Sync$/]";
  36. return {
  37. [selector](node) {
  38. context.report({
  39. node,
  40. message: "Unexpected sync method: '{{propertyName}}'.",
  41. data: {
  42. propertyName: node.property.name
  43. }
  44. });
  45. }
  46. };
  47. }
  48. };