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

Formatter

Result of linting

Pass following array of TextLintResult to reporter module.

// results of linting
const results = [
    // TextLintResult object
    {
        filePath: "./myfile.md",
        messages: [
            // TextLintMessage object
            {
                type: "lint",
                ruleId: "semi",
                line: 1,
                column: 23,
                message: "Expected a semicolon."
            }
        ]
    }
];

TextLintMessage and TextLintResult are defined as follows.

export class TextlintMessage {
    // See src/shared/type/MessageType.js
    // Message Type
    type: string;
    // Rule Id
    ruleId: string;
    message: string;
    // optional data
    data?: any;
    // FixCommand
    fix?: TextlintFixCommand;
    // location info
    // Text -> AST TxtNode(0-based columns) -> textlint -> TextlintMessage(**1-based columns**)
    line: number; // start with 1
    column: number; // start with 1
    // indexed-location
    index: number; // start with 0
    // Severity Level
    // See src/shared/type/SeverityLevel.js
    severity: number;
}

// Linting result
export interface TextlintResult {
    filePath: string;
    messages: TextlintMessage[];
}

// "range" will be replaced by "text"
export class TextlintFixCommand {
    text: string;
    range: [number, number];
}

It is compatible for ESLint formatter.

Simple usage from Command line

We can get the raw output to stdout using json formatter.

$ textlint --format json <file>
[
    // TextLintResult object
    {
        filePath: "./myfile.md",
        messages: [
            // TextLintMessage object
            {
                ruleId: "semi",
                line: 1,
                column: 23,
                message: "Expected a semicolon."
            }
        ]
    }
];

Result of fixing

textlint support fixable rule

Fixable result is a bit difference for things of linting.

// results of fixing
const results = [
    // TextLintFixResult
    {
        filePath: "./myfile.md",
        // fixed content string
        output: "fixed content",
        // applied fixable messages
        // messages is an array of `TextLintMessage`
        applyingMessages: [],
        // not fixable messages
        // messages is an array of `TextLintMessage`
        remainingMessages: [],
        // messages is the same one of `TextLintResult`
        // pre-applyingMessages + remainingMessages
        // messages is an array of `TextLintMessage`
        messages: []
    }
];

TextLintFixResult is defined as follows.

// Fixing result
export interface TextlintFixResult {
    filePath: string;
    // fixed content
    output: string;
    // all messages = pre-applyingMessages + remainingMessages
    // it is same with one of `TextlintResult`
    messages: TextlintMessage[];
    // applied fixable messages
    applyingMessages: TextlintMessage[];
    // original means original for applyingMessages and remainingMessages
    // pre-applyingMessages + remainingMessages
    remainingMessages: TextlintMessage[];
}

It is not compatible for ESLint.

Simple usage from Command line

We can get the raw output to stdout using json formatter.

$ textlint --fix --format json <file>
[
  {
    "filePath": "./myfile.md",
    "output": "content string",
    "messages": [],
    "applyingMessages": [],
    "remainingMessages": []
  }
]

How to get source code from result?

You can read the source code from filePath property.

Built-in formatter

textlint use @textlint/linter-formatter module as built-in formatter.

  • @textlint/linter-formatter

Custom Formatter

textlint -f <package-name>

e.g.) textlint-formatter-codecov

textlint -f textlint-formatter-codecov
# ==
textlint -f codecov
← PluginUse as Node Modules →
  • Result of linting
    • Simple usage from Command line
  • Result of fixing
    • Simple usage from Command line
  • How to get source code from result?
  • Built-in formatter
  • Custom Formatter
textlint
Docs
User ManualDeveloper Guide
Community
Project Chat
More
BlogGitHubStar
Copyright © 2023 textlint organization