@textlint/kernel
Version:
textlint kernel is core logic by pure JavaScript.
38 lines • 1.54 kB
JavaScript
// LICENSE : MIT
;
import LinterTask from "../task/linter-task";
import TaskRunner from "../task/task-runner";
import { invariant } from "../util/invariant";
export default class LinterProcessor {
/**
* @param {Processor} processor
* @param {MessageProcessManager} messageProcessManager
*/
constructor(processor, messageProcessManager) {
this.processor = processor;
this.messageProcessManager = messageProcessManager;
}
/**
* Run linter process
*/
async process({ config, configBaseDir, ruleDescriptors, filterRuleDescriptors, sourceCode }) {
const { preProcess, postProcess } = this.processor.processor(sourceCode.ext);
invariant(typeof preProcess === "function" && typeof postProcess === "function", "processor should implement {preProcess, postProcess}");
const task = new LinterTask({
config,
ruleDescriptors,
filterRuleDescriptors,
sourceCode,
configBaseDir
});
const messages = await TaskRunner.process(task);
const result = await postProcess(messages, sourceCode.filePath);
result.messages = this.messageProcessManager.process(result.messages);
if (result.filePath == null) {
result.filePath = `<Unknown{sourceCode.ext}>`;
}
invariant(result.filePath && result.messages.length >= 0, "postProcess should return { messages, filePath } ");
return result;
}
}
//# sourceMappingURL=linter-processor.js.map