no-aggregating-enable.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 DisabledArea = require("../internal/disabled-area")
  7. const utils = require("../internal/utils")
  8. module.exports = {
  9. meta: {
  10. docs: {
  11. description:
  12. "disallow a `eslint-enable` comment for multiple `eslint-disable` comments",
  13. category: "Best Practices",
  14. recommended: true,
  15. url:
  16. "https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html",
  17. },
  18. fixable: null,
  19. schema: [],
  20. type: "suggestion",
  21. },
  22. create(context) {
  23. const sourceCode = context.getSourceCode()
  24. const disabledArea = DisabledArea.get(sourceCode)
  25. return {
  26. Program() {
  27. for (const entry of disabledArea.numberOfRelatedDisableDirectives) {
  28. const comment = entry[0]
  29. const count = entry[1]
  30. if (count >= 2) {
  31. context.report({
  32. loc: utils.toForceLocation(comment.loc),
  33. message:
  34. "This `eslint-enable` comment affects {{count}} `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
  35. data: { count },
  36. })
  37. }
  38. }
  39. },
  40. }
  41. },
  42. }