id | title |
---|---|
use-as-modules |
Use as Node Modules |
textlint
module expose these header at index.js
// Level of abstraction(descending order)
// cli > TextLintEngine > TextLintCore(textlint)
// See: https://github.com/textlint/textlint/blob/master/docs/use-as-modules.md
// Command line interface
export { cli } from "./cli";
// It is a singleton object of TextLintCore
// Recommend: use TextLintCore
export { textlint } from "./textlint";
// TextLintEngine is a wrapper around `textlint` for linting **multiple** files
// include formatter, detecting utils
// <Recommend>: It is easy to use
// You can see engine/textlint-engine-core.js for more detail
export { TextLintEngine } from "./textlint-engine";
// TextFixEngine is a wrapper around `textlint` for linting **multiple** files
// include formatter, detecting utils
// <Recommend>: It is easy to use
// You can see engine/textlint-engine-core.js for more detail
export { TextFixEngine } from "./textfix-engine";
// Core API for linting a **single** text or file.
export { TextLintCore } from "./textlint-core";
Recommend to use TextLintEngine
.
See https://github.com/textlint/textlint/blob/master/packages/textlint/src/README.md
CLI parse command arguments, and run Engine with the options.
textlint has two engines TextLintEngine
and TextFixEngine
.
Both engine
- Load configuration from
.textlintrc
. - Handle multiple files or text string.
- Return an array of
TextLintResult
orTextLintFixResult
- actually, return a Promise like
Promise<TextLintResult[]>
- actually, return a Promise like
textlint's core
- Accept configuration as object.
- Handle a single file or text string.
- Return
TextLintResult
orTextLintFixResult
- actually, return a Promise like
Promise<TextLintResult>
- actually, return a Promise like
Lint files using TextLintEngine
:
See examples/use-as-module/index.js
// LICENSE : MIT
"use strict";
const TextLintEngine = require("textlint").TextLintEngine;
const path = require("path");
function lintFile(filePath) {
const options = {
// load rules from [../rules]
rules: ["no-todo"],
formatterName: "pretty-error"
};
const engine = new TextLintEngine(options);
const filePathList = [path.resolve(process.cwd(), filePath)];
return engine.executeOnFiles(filePathList).then(function (results) {
if (engine.isErrorResults(results)) {
const output = engine.formatResults(results);
console.log(output);
} else {
console.log("All Passed!");
}
});
}
lintFile(`${__dirname}/README.md`).catch(function (error) {
console.error(error);
process.exit(1);
});
You can use textlint-tester for testing your custom rule.
Consult link: