no-sync.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. docs: {
  13. description: "disallow synchronous methods",
  14. category: "Node.js and CommonJS",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-sync"
  17. },
  18. schema: [
  19. {
  20. type: "object",
  21. properties: {
  22. allowAtRootLevel: {
  23. type: "boolean"
  24. }
  25. },
  26. additionalProperties: false
  27. }
  28. ]
  29. },
  30. create(context) {
  31. const selector = context.options[0] && context.options[0].allowAtRootLevel
  32. ? ":function MemberExpression[property.name=/.*Sync$/]"
  33. : "MemberExpression[property.name=/.*Sync$/]";
  34. return {
  35. [selector](node) {
  36. context.report({
  37. node,
  38. message: "Unexpected sync method: '{{propertyName}}'.",
  39. data: {
  40. propertyName: node.property.name
  41. }
  42. });
  43. }
  44. };
  45. }
  46. };