no-sync.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. deprecated: true,
  13. replacedBy: [],
  14. type: "suggestion",
  15. docs: {
  16. description: "disallow synchronous methods",
  17. category: "Node.js and CommonJS",
  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. };