no-sync.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @author Matt DuVall<http://mattduvall.com/>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. module.exports = {
  7. meta: {
  8. type: "suggestion",
  9. docs: {
  10. description: "disallow synchronous methods",
  11. category: "Stylistic Issues",
  12. recommended: false,
  13. url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-sync.md",
  14. },
  15. fixable: null,
  16. schema: [
  17. {
  18. type: "object",
  19. properties: {
  20. allowAtRootLevel: {
  21. type: "boolean",
  22. default: false,
  23. },
  24. },
  25. additionalProperties: false,
  26. },
  27. ],
  28. messages: {
  29. noSync: "Unexpected sync method: '{{propertyName}}'.",
  30. },
  31. },
  32. create(context) {
  33. const selector =
  34. context.options[0] && context.options[0].allowAtRootLevel
  35. ? ":function MemberExpression[property.name=/.*Sync$/]"
  36. : "MemberExpression[property.name=/.*Sync$/]"
  37. return {
  38. [selector](node) {
  39. context.report({
  40. node,
  41. messageId: "noSync",
  42. data: {
  43. propertyName: node.property.name,
  44. },
  45. })
  46. },
  47. }
  48. },
  49. }