no-sync.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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:
  14. "https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/no-sync.md",
  15. },
  16. fixable: null,
  17. schema: [
  18. {
  19. type: "object",
  20. properties: {
  21. allowAtRootLevel: {
  22. type: "boolean",
  23. default: false,
  24. },
  25. },
  26. additionalProperties: false,
  27. },
  28. ],
  29. messages: {
  30. noSync: "Unexpected sync method: '{{propertyName}}'.",
  31. },
  32. },
  33. create(context) {
  34. const selector =
  35. context.options[0] && context.options[0].allowAtRootLevel
  36. ? ":function MemberExpression[property.name=/.*Sync$/]"
  37. : "MemberExpression[property.name=/.*Sync$/]"
  38. return {
  39. [selector](node) {
  40. context.report({
  41. node,
  42. messageId: "noSync",
  43. data: {
  44. propertyName: node.property.name,
  45. },
  46. })
  47. },
  48. }
  49. },
  50. }