textlint

textlint

  • Docs
  • Rules
  • Blog
  • Help
  • GitHub

›Developer Guide

User Manual

  • Getting Started with textlint
  • Command Line Interface
  • Configuring textlint
  • Ignoring Text
  • Integrating with Editors, Tools, etc..

Developer Guide

  • Creating Rules
  • Creating Filter Rule
  • Creating Fixable Rule
  • Creating Preset
  • Advanced: Paragraph Rule
  • How to implement "after-all" in the rule?
  • Plugin
  • Formatter
  • Use as Node Modules
  • TxtAST Interface

Contributing

  • Contributing Guideline
Edit

How to implement "after-all" in the rule?

Is there any way to execute this after all checks are done?

textlint doesn't provide after-all hook. But you can write following:

// Async Task return a promise.
const callAsync = (text) => {
    // do something by async
    return Promise.resolve(text);
};

module.exports = (context) => {
    const { Syntax, getSource } = context;
    const promiseQueue = [];
    return {
        [Syntax.Str](node) {
            const text = getSource(node);
            // add the promise object to queue
            promiseQueue.push(callAsync(text));
        },
        // call this method at the end
        // Syntax.Document <-> Syntax.DocumentExit
        // https://github.com/textlint/textlint/blob/master/docs/rule.md
        [Syntax.DocumentExit]() {
            // Note: textlint wait for `Promise.all` is resolved.
            return Promise.all(promiseQueue)
                .then((...responses) => {
                    // do something
                })
                .then(() => {
                    // after-all !
                });
        }
    };
};

Related Issues

  • Rule: Tear down · Issue #266 · textlint/textlint
← Advanced: Paragraph RulePlugin →
  • Related Issues
textlint
Docs
User ManualDeveloper Guide
Community
Project Chat
More
BlogGitHubStar
Copyright © 2023 textlint organization