no-restricted-disable.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 ignore = require("ignore")
  7. const DisabledArea = require("../internal/disabled-area")
  8. const utils = require("../internal/utils")
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. description:
  13. "disallow `eslint-disable` comments about specific rules",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url:
  17. "https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html",
  18. },
  19. fixable: null,
  20. schema: {
  21. type: "array",
  22. items: { type: "string" },
  23. uniqueItems: true,
  24. },
  25. type: "suggestion",
  26. },
  27. create(context) {
  28. const sourceCode = context.getSourceCode()
  29. const disabledArea = DisabledArea.get(sourceCode)
  30. if (context.options.length === 0) {
  31. return {}
  32. }
  33. const ig = ignore()
  34. for (const pattern of context.options) {
  35. ig.add(pattern)
  36. }
  37. return {
  38. Program() {
  39. for (const area of disabledArea.areas) {
  40. if (area.ruleId == null || ig.ignores(area.ruleId)) {
  41. context.report({
  42. loc: utils.toRuleIdLocation(
  43. area.comment,
  44. area.ruleId
  45. ),
  46. message: "Disabling '{{ruleId}}' is not allowed.",
  47. data: {
  48. ruleId: area.ruleId || String(context.options),
  49. },
  50. })
  51. }
  52. }
  53. },
  54. }
  55. },
  56. }