enforceSuppressionCode.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _utilities = require("../utilities");
  7. var schema = [{
  8. type: 'string'
  9. }];
  10. var message = function message() {
  11. var suppression = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  12. return "".concat(suppression, " is missing a suppression error code. Please update this suppression to use an error code: ").concat(suppression, "[\u2026]");
  13. };
  14. var create = function create(context) {
  15. var isMissingSuppressionCode = function isMissingSuppressionCode(value) {
  16. var failedType;
  17. _utilities.suppressionTypes.forEach(function (cur) {
  18. if (value && value.startsWith(cur) && !value.startsWith("".concat(cur, "[")) && !value.endsWith(']')) {
  19. failedType = cur;
  20. }
  21. });
  22. return failedType;
  23. };
  24. var handleComment = function handleComment(comment) {
  25. var value = comment.type === 'Block' ? comment.value.replace(/\*/g, '') : comment.value;
  26. var suppression = value.trim().split(' ').filter(function (arg) {
  27. return arg.length > 0;
  28. })[0];
  29. var failedType = isMissingSuppressionCode(suppression);
  30. if (failedType) {
  31. context.report(comment, message(failedType));
  32. }
  33. };
  34. return {
  35. Program: function Program() {
  36. context.getSourceCode().getAllComments().filter(function (comment) {
  37. return comment.type === 'Block' || comment.type === 'Line';
  38. }).forEach(handleComment);
  39. }
  40. };
  41. };
  42. var _default = {
  43. create: create,
  44. schema: schema
  45. };
  46. exports["default"] = _default;
  47. module.exports = exports.default;