no-sync.js 1.6 KB

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