UNPKG

@textlint/kernel

Version:
88 lines 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextlintFilterRuleContextImpl = void 0; const TextlintRuleErrorImpl_1 = require("./TextlintRuleErrorImpl"); const TextlintRulePaddingLocator_1 = require("./TextlintRulePaddingLocator"); const invariant_1 = require("../util/invariant"); class TextlintFilterRuleContextImpl { constructor(args) { this.shouldIgnore = (range, optional = {}) => { (0, invariant_1.invariant)(Array.isArray(range) && typeof range[0] === "number" && typeof range[1] === "number", "shouldIgnore([number, number]); accept range."); this._ignoreReport({ ruleId: this._ruleId, range, optional }); }; /** * get file path current processing. */ this.getFilePath = () => { return this._sourceCode.getFilePath(); }; /** * Gets the source code for the given node. * @param {TxtNode=} node The AST node to get the text for. * @param {int=} beforeCount The number of characters before the node to retrieve. * @param {int=} afterCount The number of characters after the node to retrieve. * @returns {string} The text representing the AST node. */ this.getSource = (node, beforeCount, afterCount) => { return this._sourceCode.getSource(node, beforeCount, afterCount); }; /** * get config base directory path * config base directory path often is the place of .textlintrc * * e.g.) /path/to/dir/.textlintrc * `getConfigBaseDir()` return `"/path/to/dir/"`. * * When using textlint as module, it is specified by `configBaseDir` * If not found the value, return undefined. * * You can use it for resolving relative path from config dir. * @returns {string|undefined} */ this.getConfigBaseDir = () => { return this._configBaseDir; }; this._ruleId = args.ruleId; this._sourceCode = args.sourceCode; this._ignoreReport = args.ignoreReport; this.locator = (0, TextlintRulePaddingLocator_1.createPaddingLocator)(); this._configBaseDir = args.configBaseDir; this._severityLevel = args.severityLevel; Object.freeze(this); } /** * Rule id * @returns {string} */ get id() { return this._ruleId; } get severity() { return this._severityLevel; } /** * Node's type values * @type {TextLintNodeType} */ get Syntax() { return this._sourceCode.getSyntax(); } /** * CustomError object * @type {RuleError} */ get RuleError() { return TextlintRuleErrorImpl_1.TextlintRuleErrorImpl; } /** * Not use * @returns {() => void} */ get report() { return () => { throw new Error("Filter rule can not report"); }; } } exports.TextlintFilterRuleContextImpl = TextlintFilterRuleContextImpl; //# sourceMappingURL=TextlintFilterRuleContextImpl.js.map