@textlint/kernel
Version:
textlint kernel is core logic by pure JavaScript.
81 lines • 2.87 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextlintKernelDescriptor = void 0;
const DescriptorsFactory_1 = require("./DescriptorsFactory");
class TextlintKernelDescriptor {
constructor(args) {
this.args = args;
this.rule = (0, DescriptorsFactory_1.createTextlintRuleDescriptors)(args.rules);
this.filterRule = (0, DescriptorsFactory_1.createTextlintFilterRuleDescriptors)(args.filterRules);
this.plugin = (0, DescriptorsFactory_1.createTextlintPluginDescriptors)(args.plugins);
this.configBaseDir = args.configBaseDir;
}
/**
* Return available extensions of plugins
*/
get availableExtensions() {
return this.plugin.availableExtensions;
}
/**
* Merge constructor args and partialArgs
* It shallow merge partialArgs.
* It means that overwrite own properties by partialArgs.
*/
shallowMerge(partialArgs) {
return new TextlintKernelDescriptor({
...this.args,
...partialArgs
});
}
/**
* Concat descriptors
* If A.concat(B), A is base, B is added
* Note: withoutDuplicated pick A from [A, B] If A and B have same ruleId.
* @param other
*/
concat(other) {
var _a;
return new TextlintKernelDescriptor({
configBaseDir: (_a = other.configBaseDir) !== null && _a !== void 0 ? _a : this.configBaseDir,
rules: this.rule.toKernelRulesFormat().concat(other.rule.toKernelRulesFormat()),
filterRules: this.filterRule
.toKernelFilterRulesFormat()
.concat(other.filterRule.toKernelFilterRulesFormat()),
plugins: this.plugin.toKernelPluginsFormat().concat(other.plugin.toKernelPluginsFormat())
});
}
/**
* find PluginDescriptor with extension.
* This is forward match.
*
* If following config of textlint, this method prefer to select MarkdownA for markdown.
*
* {
* "plugins": [MarkdownA, MarkdownB]
* }
*/
findPluginDescriptorWithExt(ext) {
return this.plugin.findPluginDescriptorWithExt(ext);
}
/**
* Convert descriptor to TextlintKernelOptions
*/
toKernelOptions() {
return {
configBaseDir: this.configBaseDir,
rules: this.rule.toKernelRulesFormat(),
filterRules: this.filterRule.toKernelFilterRulesFormat(),
plugins: this.plugin.toKernelPluginsFormat()
};
}
toJSON() {
return {
rule: this.rule.toJSON(),
filterRule: this.filterRule.toJSON(),
plugin: this.plugin.toJSON(),
configBaseDir: this.configBaseDir
};
}
}
exports.TextlintKernelDescriptor = TextlintKernelDescriptor;
//# sourceMappingURL=TextlintKernelDescriptor.js.map