UNPKG

textlint-filter-rule-comments

Version:
123 lines (106 loc) 4.52 kB
// LICENSE : MIT "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var StatusManager = function () { function StatusManager(endIndex) { _classCallCheck(this, StatusManager); /** * @typedef {Object} IgnoringCommentObject * @property {number|null} startIndex * @property {number|null} endIndex * @property {string|null} ruleId */ /** * @type {IgnoringCommentObject[]} */ this.reportingConfig = []; /** * @type {TxtNode} */ this.endIndex = endIndex; } _createClass(StatusManager, [{ key: "getIgnoringMessages", value: function getIgnoringMessages() { var _this = this; return this.reportingConfig.map(function (reporting) { if (reporting.endIndex === null) { // [start, ?= document-end] // filled with document's end reporting.endIndex = _this.endIndex; } return reporting; }); } /** * Add data to reporting configuration to disable reporting for list of rules * starting from start location * @param {Object} startNode Node to start * @param {string[]} rulesToDisable List of rules * @returns {void} */ }, { key: "disableReporting", value: function disableReporting(startNode, rulesToDisable) { var reportingConfig = this.reportingConfig; if (rulesToDisable.length) { rulesToDisable.forEach(function (ruleId) { reportingConfig.push({ startIndex: startNode.range[0], endIndex: null, ruleId: ruleId }); }); } else { reportingConfig.push({ startIndex: startNode.range[0], endIndex: null, ruleId: null }); } } /** * Add data to reporting configuration to enable reporting for list of rules * starting from start location * @param {Object} startNode Node to start * @param {string[]} rulesToEnable List of rules * @returns {void} */ }, { key: "enableReporting", value: function enableReporting(startNode, rulesToEnable) { var i; var endIndex = startNode.range[0]; var reportingConfig = this.reportingConfig; if (rulesToEnable.length) { rulesToEnable.forEach(function (ruleId) { for (i = reportingConfig.length - 1; i >= 0; i--) { if (!reportingConfig[i].endIndex && reportingConfig[i].ruleId === ruleId) { reportingConfig[i].endIndex = endIndex; break; } } }); } else { // find all previous disabled locations if they was started as list of rules var prevStart; for (i = reportingConfig.length - 1; i >= 0; i--) { if (prevStart && prevStart !== reportingConfig[i].start) { break; } if (!reportingConfig[i].endIndex) { reportingConfig[i].endIndex = endIndex; prevStart = reportingConfig[i].start; } } } } }]); return StatusManager; }(); exports.default = StatusManager; //# sourceMappingURL=StatusManager.js.map