textlint is a pluggable natural language linting tool for prose, similar to ESLint but designed for checking written text rather than code. This document provides a high-level overview of textlint's architecture, core concepts, and position in the JavaScript ecosystem.
For detailed information on specific subsystems:
textlint is a command-line tool and Node.js module that checks natural language text for style, grammar, and consistency issues. Unlike spell checkers, textlint operates on an Abstract Syntax Tree (AST) representation of documents, enabling sophisticated structural analysis and automatic fixes.
Key characteristics:
@textlint/kernel) runs in both Node.js and browser environments--fix flagSources: README.md1-53 packages/textlint/package.json2-14
textlint processes text through a four-stage pipeline:
Sources: Diagram 2 from provided architecture overview, packages/textlint/package.json50-64
Sources: packages/textlint/src/index.ts structure, packages/@textlint/kernel/src/index.ts
textlint integrates with the JavaScript/TypeScript development ecosystem through multiple touchpoints:
| Integration Point | Package/Tool | Purpose |
|---|---|---|
| Package Manager | npm, pnpm | Rule/plugin distribution |
| Build Tools | Babel, TypeScript | Rule development transpilation |
| Testing | Mocha, vitest | Rule testing framework |
| Monorepo | Lerna | Version management and publishing |
| Editors | VS Code, Vim, Atom | Real-time linting integration |
| CI/CD | GitHub Actions | Automated quality checks |
| AI Assistants | MCP (Model Context Protocol) | Integration with Copilot, Cursor |
Sources: package.json44-60 README.md442-500 packages/textlint/package.json51
The textlint monorepo contains 30+ packages organized by function:
Sources: README.md510-561 Diagram 1 from architecture overview
Unlike many linters, textlint ships with no bundled rules. Users explicitly install rules via npm (e.g., npm install textlint-rule-no-todo). This keeps the core lightweight and allows users to build custom rule sets.
Sources: README.md30-33 README.md72-104
textlint converts text to an Abstract Syntax Tree (TxtNode structure) rather than processing raw strings. This enables:
Sources: docs/txtnode.md1-66 packages/@textlint/ast-node-types/src/index.ts
The @textlint/kernel package is written as universal JavaScript, allowing it to run in:
The CLI wrapper (textlint package) handles Node-specific concerns like file I/O and configuration loading.
Sources: packages/@textlint/kernel/package.json1-4 README.md378-405
File format support is delegated to plugins that provide Processor classes. Each processor defines:
availableExtensions(): Supported file extensions (e.g., [".md", ".markdown"])processor(ext).preProcess(): Parse text to ASTprocessor(ext).postProcess(): Transform results back to file contextBuilt-in plugins support Markdown and plain text; community plugins add HTML, AsciiDoc, ReStructuredText, etc.
Sources: docs/plugin.md9-63 packages/@textlint/textlint-plugin-markdown/src/index.ts
textlint maintains separate code paths for:
lintText()/lintFiles() → TextlintResult[] with error messagesfixText()/fixFiles() → TextlintFixResult[] with corrected textThis separation allows rules to provide optional fix functions without complicating the linting logic.
Sources: docs/use-as-modules.md29-46 packages/@textlint/kernel/src/index.ts
The textlint package provides the main CLI entry point at packages/textlint/bin/textlint.js Users typically invoke it via:
Key CLI flags:
--rule <rule-name>: Enable a rule without .textlintrc--fix: Apply automatic fixes--format <formatter>: Choose output format (stylish, json, etc.)--config <path>: Specify configuration file--mcp: Start Model Context Protocol server for AI integrationSources: README.md105-162 packages/textlint/bin/textlint.js
For Node.js integration, the textlint package exports modern high-level APIs:
Sources: docs/use-as-modules.md1-65 packages/textlint/src/index.ts
The @textlint/kernel package provides direct access to the linting engine for browser environments or custom integrations:
Sources: README.md378-405 packages/@textlint/kernel/src/textlint-kernel-interface.ts
textlint provides comprehensive tooling for rule and plugin developers:
Sources: packages/textlint-scripts/package.json1-5 packages/textlint-tester/package.json1-5 docs/rule.md373-416
textlint uses a flexible configuration file (.textlintrc, .textlintrc.json, .textlintrc.js, etc.) that specifies:
| Section | Purpose | Example |
|---|---|---|
rules | Enable/configure linting rules | { "no-todo": true } |
filters | Enable error filtering rules | { "comments": true } |
plugins | Add file format support | { "html": { "extensions": [".htm"] } } |
Configuration loading is handled by @textlint/config-loader using rc-config-loader for flexible file format support (JSON, YAML, JS).
Sources: docs/configuring.md1-298 packages/@textlint/config-loader/src/index.ts
textlint provides four primary extension mechanisms:
| Extension Type | Package Prefix | Purpose | Example |
|---|---|---|---|
| Rules | textlint-rule- | Check text for issues | textlint-rule-no-todo |
| Rule Presets | textlint-rule-preset- | Bundle multiple rules | textlint-rule-preset-ja-spacing |
| Plugins | textlint-plugin- | Add file format support | textlint-plugin-html |
| Filter Rules | textlint-filter-rule- | Suppress specific errors | textlint-filter-rule-comments |
All extensions follow npm naming conventions and can be scoped (e.g., @scope/textlint-rule-name).
Sources: README.md409-421 docs/configuring.md24-298
Sources: packages/textlint/package.json3-95 README.md563-584
The repository uses Lerna + pnpm workspaces for managing 30+ interdependent packages:
package.json: Defines workspace scripts and shared devDependencieslerna.json: Version management and publishing configurationpnpm-workspace.yaml: Workspace package locationsKey scripts:
pnpm run build: Build all packagespnpm run test: Run all testspnpm run ci:release: Publish all changed packagesSources: package.json1-61 lerna.json pnpm-lock.yaml1-10
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.