no-sync.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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('../types').Rule.RuleModule} */
  11. module.exports = {
  12. meta: {
  13. deprecated: {
  14. message: "Node.js rules were moved out of ESLint core.",
  15. url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
  16. deprecatedSince: "7.0.0",
  17. availableUntil: "11.0.0",
  18. replacedBy: [
  19. {
  20. message:
  21. "eslint-plugin-n now maintains deprecated Node.js-related rules.",
  22. plugin: {
  23. name: "eslint-plugin-n",
  24. url: "https://github.com/eslint-community/eslint-plugin-n",
  25. },
  26. rule: {
  27. name: "no-sync",
  28. url: "https://github.com/eslint-community/eslint-plugin-n/tree/master/docs/rules/no-sync.md",
  29. },
  30. },
  31. ],
  32. },
  33. type: "suggestion",
  34. docs: {
  35. description: "Disallow synchronous methods",
  36. recommended: false,
  37. url: "https://eslint.org/docs/latest/rules/no-sync",
  38. },
  39. schema: [
  40. {
  41. type: "object",
  42. properties: {
  43. allowAtRootLevel: {
  44. type: "boolean",
  45. default: false,
  46. },
  47. },
  48. additionalProperties: false,
  49. },
  50. ],
  51. messages: {
  52. noSync: "Unexpected sync method: '{{propertyName}}'.",
  53. },
  54. },
  55. create(context) {
  56. const selector =
  57. context.options[0] && context.options[0].allowAtRootLevel
  58. ? ":function MemberExpression[property.name=/.*Sync$/]"
  59. : "MemberExpression[property.name=/.*Sync$/]";
  60. return {
  61. [selector](node) {
  62. context.report({
  63. node,
  64. messageId: "noSync",
  65. data: {
  66. propertyName: node.property.name,
  67. },
  68. });
  69. },
  70. };
  71. },
  72. };