require-description.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author Yosuke Ota <https://github.com/ota-meshi>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. const utils = require("../internal/utils")
  7. module.exports = {
  8. meta: {
  9. docs: {
  10. description:
  11. "require include descriptions in ESLint directive-comments",
  12. category: "Stylistic Issues",
  13. recommended: false,
  14. url:
  15. "https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/require-description.html",
  16. },
  17. fixable: null,
  18. schema: [
  19. {
  20. type: "object",
  21. properties: {
  22. ignore: {
  23. type: "array",
  24. items: {
  25. enum: [
  26. "eslint",
  27. "eslint-disable",
  28. "eslint-disable-line",
  29. "eslint-disable-next-line",
  30. "eslint-enable",
  31. "eslint-env",
  32. "exported",
  33. "global",
  34. "globals",
  35. ],
  36. },
  37. additionalItems: false,
  38. uniqueItems: true,
  39. },
  40. },
  41. additionalProperties: false,
  42. },
  43. ],
  44. type: "suggestion",
  45. },
  46. create(context) {
  47. const sourceCode = context.getSourceCode()
  48. const ignores = new Set(
  49. (context.options[0] && context.options[0].ignore) || []
  50. )
  51. return {
  52. Program() {
  53. for (const comment of sourceCode.getAllComments()) {
  54. const directiveComment = utils.parseDirectiveComment(
  55. comment
  56. )
  57. if (directiveComment == null) {
  58. continue
  59. }
  60. if (ignores.has(directiveComment.kind)) {
  61. continue
  62. }
  63. if (!directiveComment.description) {
  64. context.report({
  65. loc: utils.toForceLocation(comment.loc),
  66. message:
  67. "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.",
  68. })
  69. }
  70. }
  71. },
  72. }
  73. },
  74. }