How to use the textlint.TextLintEngine function in textlint

To help you get started, we’ve selected a few textlint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github textlint / textlint / examples / use-as-module / index.js View on Github external
function lintFile(filePath) {
    /**
     * See lib/_typing/textlint.d.ts
     */
    var options = {
        // load rules from [../rules]
        rules: ["no-todo"],
        formatterName: "pretty-error"
    };
    var engine = new TextLintEngine(options);
    var filePathList = [path.resolve(process.cwd(), filePath)];
    return engine.executeOnFiles(filePathList).then(function(results) {
        if (engine.isErrorResults(results)) {
            var output = engine.formatResults(results);
            console.log(output);
        } else {
            console.log("All Passed!");
        }
    });
}
github 1000ch / linter-textlint / lib / index.js View on Github external
// local config
      let configFile = directory.resolve('./.textlintrc');
      let pluginPath = directory.resolve('./node_modules/');

      if (!existsConfig(configFile, pluginPath)) {
        if (!existsConfig(textlintrcPath, textlintRulesDir)) {
          return Promise.resolve([]);
        }

        // use global config
        configFile = textlintrcPath;
        pluginPath = textlintRulesDir;
      }

      const textlint = new TextLintEngine({
        configFile,
        rulesBaseDirectory: pluginPath
      });
      const filePath = editor.getPath();

      return textlint.executeOnFiles([filePath]).then((results) => {
        const { push } = Array.prototype;
        const messages = [];
        results
          .filter(result => result.messages.length)
          .forEach(result => push.apply(messages, result.messages));

        return messages.map((message) => {
          const linterMessage = {
            severity: textlint.isErrorMessage(message) ? 'error' : 'warning',
            location: {
github ics-creative / project-japanese-proofreading / src / server.ts View on Github external
async function validateTextDocument(textDocument: TextDocument): Promise {
  // In this simple example we get the settings for every validate run.
  const settings = await getDocumentSettings(textDocument.uri);

  const document = textDocument.getText();
  const ext: string = path.extname(
    vscode_uri.default.parse(textDocument.uri).fsPath,
  );

  const engine: TextLintEngine = new TextLintEngine({
    configFile: path.resolve(__dirname, "../.textlintrc"),
  });

  const results: TextlintResult[] = await engine.executeOnText(document, ext);
  const diagnostics: Diagnostic[] = [];

  if (engine.isErrorResults(results)) {
    const messages: TextlintMessage[] = results[0].messages;

    const l: number = messages.length;
    for (let i: number = 0; i < l; i++) {
      const message: TextlintMessage = messages[i];
      const text: string = message.message;
      const pos: Position = Position.create(
        Math.max(0, message.line - 1),
        Math.max(0, message.column - 1),
github textlint / textlint / packages / gulp-textlint / index.js View on Github external
module.exports = function(options) {
    options = options || {};
    const textlint = new TextLintEngine(options);
    const filePaths = [];

    return through.obj(
        function(file, enc, cb) {
            filePaths.push(file.path);
            this.push(file);
            cb();
        },
        function(cb) {
            const that = this;
            textlint
                .executeOnFiles(filePaths)
                .then(function(results) {
                    if (textlint.isErrorResults(results)) {
                        log(textlint.formatResults(results));
                        that.emit("error", new PluginError("textlint", "Lint failed."));
github andrepolischuk / docslint / lib / lintFiles.js View on Github external
module.exports = function lintFiles (input, options) {
  const config = createConfig(options)
  const patterns = input.length === 0 ? ['**/*.md'] : input

  const engine = options.fix
    ? new textlint.TextFixEngine(config)
    : new textlint.TextLintEngine(config)

  return globby(patterns, {gitignore: true})
    .then(paths => engine.executeOnFiles(paths))
    .then(results => {
      if (!options.fix) {
        return results
      }

      const fixer = new TextLintFixer()

      return fixer.write(results).then(() => results)
    })
}
github textlint / textlint-app / src / node / infra / textlint / TextlintAPIServer.js View on Github external
get lintEngine() {
        if (this._textLintEngine) {
            return this._textLintEngine;
        }
        const textLineEngine = new textlint.TextLintEngine({
            configFile: this.configFile,
            rulesBaseDirectory: this.rulesBaseDirectory
        });
        this._textLintEngine = textLineEngine;
        return textLineEngine;
    }

textlint

The pluggable linting tool for text and markdown.

MIT
Latest version published 29 days ago

Package Health Score

83 / 100
Full package analysis