How to use textlint - 10 common examples

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 / packages / textlint-tester / src / textlint-tester.ts View on Github external
testValidPattern(name: string, param: TextlintRuleModule | TestConfig, valid: TesterValid) {
        const text = typeof valid === "object" ? valid.text : valid;
        const inputPath = typeof valid === "object" ? valid.inputPath : undefined;
        const ext = typeof valid === "object" && valid.ext !== undefined ? valid.ext : ".md";
        const textlint = new TextLintCore();
        if (isTestConfig(param)) {
            const testRuleSet = createTestRuleSet(param.rules);
            textlint.setupRules(testRuleSet.rules, testRuleSet.rulesOptions);
            if (param.plugins !== undefined) {
                const testPluginSet = createTestPluginSet(param.plugins);
                textlint.setupPlugins(testPluginSet.plugins, testPluginSet.pluginOptions);
            }
        } else {
            const options =
                typeof valid === "object"
                    ? valid.options
                    : // just enable
                      true;
            textlint.setupRules(
                {
                    [name]: param
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 textlint / textlint / examples / perf / run.js View on Github external
// LICENSE : MIT
"use strict";
// run as app
var cli = require("textlint").cli;
cli
    .execute(process.argv.concat(__dirname + "/md/"))
    .then(function(exit) {
        console.log(exit);
    })
    .catch(function(error) {
        console.error(error);
    });
github textlint / textlint / examples / perf / run.js View on Github external
// LICENSE : MIT
"use strict";
// run as app
var cli = require("textlint").cli;
cli
    .execute(process.argv.concat(__dirname + "/md/"))
    .then(function(exit) {
        console.log(exit);
    })
    .catch(function(error) {
        console.error(error);
    });
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 / textlint-tester / src / textlint-tester.ts View on Github external
testInvalidPattern(name: string, param: TextlintRuleModule | TestConfig, invalid: TesterInvalid) {
        const errors = invalid.errors;
        const inputPath = invalid.inputPath;
        const text = invalid.text;
        const ext = invalid.ext !== undefined ? invalid.ext : ".md";
        const textlint = new TextLintCore();
        if (isTestConfig(param)) {
            const testRuleSet = createTestRuleSet(param.rules);
            textlint.setupRules(testRuleSet.rules, testRuleSet.rulesOptions);
            if (Array.isArray(param.plugins)) {
                const testPluginSet = createTestPluginSet(param.plugins);
                textlint.setupPlugins(testPluginSet.plugins, testPluginSet.pluginOptions);
            }
        } else {
            const options = invalid.options;
            textlint.setupRules(
                {
                    [name]: param
                },
                {
                    [name]: options
                }
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 10 days ago

Package Health Score

83 / 100
Full package analysis