flags.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @fileoverview Shared flags for ESLint.
  3. */
  4. "use strict";
  5. //------------------------------------------------------------------------------
  6. // Typedefs
  7. //------------------------------------------------------------------------------
  8. /**
  9. * @typedef {Object} InactiveFlagData
  10. * @property {string} description Flag description
  11. * @property {string | null} [replacedBy] Can be either:
  12. * - An active flag (string) that enables the same feature.
  13. * - `null` if the feature is now enabled by default.
  14. * - Omitted if the feature has been abandoned.
  15. */
  16. //-----------------------------------------------------------------------------
  17. // Exports
  18. //-----------------------------------------------------------------------------
  19. /**
  20. * The set of flags that change ESLint behavior with a description.
  21. * @type {Map<string, string>}
  22. */
  23. const activeFlags = new Map([
  24. ["test_only", "Used only for testing."],
  25. ["test_only_2", "Used only for testing."],
  26. [
  27. "v10_config_lookup_from_file",
  28. "Look up `eslint.config.js` from the file being linted.",
  29. ],
  30. [
  31. "unstable_native_nodejs_ts_config",
  32. "Use native Node.js to load TypeScript configuration.",
  33. ],
  34. ]);
  35. /**
  36. * The set of flags that used to be active.
  37. * @type {Map<string, InactiveFlagData>}
  38. */
  39. const inactiveFlags = new Map([
  40. [
  41. "test_only_replaced",
  42. {
  43. description:
  44. "Used only for testing flags that have been replaced by other flags.",
  45. replacedBy: "test_only",
  46. },
  47. ],
  48. [
  49. "test_only_enabled_by_default",
  50. {
  51. description:
  52. "Used only for testing flags whose features have been enabled by default.",
  53. replacedBy: null,
  54. },
  55. ],
  56. [
  57. "test_only_abandoned",
  58. {
  59. description:
  60. "Used only for testing flags whose features have been abandoned.",
  61. },
  62. ],
  63. [
  64. "unstable_ts_config",
  65. {
  66. description: "Enable TypeScript configuration files.",
  67. replacedBy: null,
  68. },
  69. ],
  70. [
  71. "unstable_config_lookup_from_file",
  72. {
  73. description:
  74. "Look up `eslint.config.js` from the file being linted.",
  75. replacedBy: "v10_config_lookup_from_file",
  76. },
  77. ],
  78. ]);
  79. /**
  80. * Creates a message that describes the reason the flag is inactive.
  81. * @param {InactiveFlagData} inactiveFlagData Data for the inactive flag.
  82. * @returns {string} Message describing the reason the flag is inactive.
  83. */
  84. function getInactivityReasonMessage({ replacedBy }) {
  85. if (typeof replacedBy === "undefined") {
  86. return "This feature has been abandoned.";
  87. }
  88. if (typeof replacedBy === "string") {
  89. return `This flag has been renamed '${replacedBy}' to reflect its stabilization. Please use '${replacedBy}' instead.`;
  90. }
  91. // null
  92. return "This feature is now enabled by default.";
  93. }
  94. module.exports = {
  95. activeFlags,
  96. inactiveFlags,
  97. getInactivityReasonMessage,
  98. };