no-unlimited-disable.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  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. "disallow `eslint-disable` comments without rule names",
  12. category: "Best Practices",
  13. recommended: true,
  14. url:
  15. "https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html",
  16. },
  17. fixable: null,
  18. schema: [],
  19. type: "suggestion",
  20. },
  21. create(context) {
  22. const sourceCode = context.getSourceCode()
  23. return {
  24. Program() {
  25. for (const comment of sourceCode.getAllComments()) {
  26. const directiveComment = utils.parseDirectiveComment(
  27. comment
  28. )
  29. if (directiveComment == null) {
  30. continue
  31. }
  32. const kind = directiveComment.kind
  33. if (
  34. kind !== "eslint-disable" &&
  35. kind !== "eslint-disable-line" &&
  36. kind !== "eslint-disable-next-line"
  37. ) {
  38. continue
  39. }
  40. if (!directiveComment.value) {
  41. context.report({
  42. loc: utils.toForceLocation(comment.loc),
  43. message:
  44. "Unexpected unlimited '{{kind}}' comment. Specify some rule names to disable.",
  45. data: { kind: directiveComment.kind },
  46. })
  47. }
  48. }
  49. },
  50. }
  51. },
  52. }