用於文本和降價的可插入術工具。
Textlint類似於Eslint,但它用於自然語言。
訪問https://textlint.github.io/。
npm install textlint-rule-xxx 。要快速參觀Textlint,請查看我們的入門指南:Squirrel:
您可以使用NPM安裝textlint命令:
$ npm install textlint --save-dev
要求:
如果您不確定正在運行哪種版本的節點,則可以在控制台中運行node -v以找出答案。
textlint ,則必須在全球安裝每個參考規則。textlint ,則必須在本地安裝每個規則。我們建議在本地安裝textlint 。
如果您從未使用過node.js和npm,請參閱以下內容:

Textlint沒有默認規則!
您可以使用.textlintrc.json配置文件運行textlint。
# Install textlint and rules into local directory
npm install --save-dev textlint textlint-rule-no-todo npx textlint --init命令創建.textlintrc.json文件中的文件。
npx textlint --init .textlintrc.json將被創建:
{
"rules" : {
"no-todo" : true
}
}通過textlint的棉絨文件:
npx textlint ./README.md textlint load .textlintrc.json來自當前目錄和lint README.md 。
運行npx textlint -h以獲取有關如何使用CLI的信息。
$ textlint [options] file.md [file|dir|glob*]
Options:
-h, --help Show help.
-c, --config path::String Use configuration from this file or sharable config.
--ignore-path path::String Specify path to a file containing patterns that describes files to ignore. - default: .textlintignore
--init Create the config file if not existed. - default: false
--fix Automatically fix problems
--dry-run Enable dry-run mode for --fix. Only show result, don't change the file.
--debug Outputs debugging information
--print-config Print the config object to stdout
-v, --version Outputs the version number.
Using stdin:
--stdin Lint text provided on <STDIN>. - default: false
--stdin-filename String Specify filename to process STDIN as
Output:
-o, --output-file path::String Enable report to be written to a file.
-f, --format String Use a specific output format.
Available formatter : checkstyle, compact, jslint-xml, json, junit, pretty-error, stylish, table, tap, unix
Available formatter for --fix: compats, diff, fixed-result, json, stylish - default: stylish
--no-color Disable color in piped output.
--quiet Report errors only. - default: false
Specifying rules and plugins:
--no-textlintrc Disable .textlintrc
--plugin [String] Set plugin package name
--rule [String] Set rule package name
--preset [String] Set preset package name and load rules from preset package.
--rulesdir [path::String] Use additional rules from this directory
Caching:
--cache Only check changed files - default: false
--cache-location path::String Path to the cache file or directory - default: .textlintcache
Experimental:
--experimental Enable experimental flag.Some feature use on experimental.
--rules-base-directory path::String Set module base directory. textlint load modules(rules/presets/plugins) from the base directory.
在運行TextLint時,您可以使用Glob模式將文件定位為棉絨。確保您將通過引號中傳遞的所有Glob參數包裝。
$ npx textlint " docs/** "有關更多詳細信息,請參見CLI文檔。
例子:
.textlintrc是通過Azu/RC-Config-Loader加載為JSON,YAML或JS的配置文件。
使用以下參數運行文字線
$ npx textlint --rule no-todo --rule very-nice-rule README.md
等同於在目錄中使用.textlintrc.json包含以下JSON的目錄中的textlint README.md
{
"rules" : {
"no-todo" : true ,
"very-nice-rule" : true
}
}您還可以在.textlintrc.json文件中為特定規則配置選項。
{
"rules" : {
"no-todo" : false , // disable
"very-nice-rule" : {
"key" : " value "
}
}
}例如,在這裡,我們將選項(“鍵”:“ value”)傳遞給very-nice-rule 。
可以在.textlintrc.json文件中指定選項:如下:
{
// Allow to comment in JSON
"rules" : {
"<rule-name>" : true | false | object
}
}有關更多詳細信息,請參見
Textlint插件是一組規則和規則config或自定義解析器。
要啟用插件,請將“插件名”放入.textlintrc.json中。
// `.textlintrc.json`
{
"plugins" : [
"plugin-name"
] ,
// overwrite-plugins rules config
// <plugin>/<rule>
"rules" : {
"plugin-name/rule-name" : false
}
}請參閱文檔/插件
Textlint默認情況下支持Markdown和純文本。
安裝處理器插件並添加新的文件格式支持。
例如,如果您想提起HTML,請使用TextLint-Plugin-HTML作為插件。
npm install textlint-plugin-html --save-dev
將"html"添加到.textlintrc.json
{
"plugins": [
"html"
]
}
在.html文件上運行textlint:
textlint index.html
可選支持的文件類型:
有關詳細信息,請參見處理器插件列表。
Textlint沒有內置的規則,但是有100多個可插入規則:
有關更多詳細信息,請參見textlint規則的集合·textlint/textlint Wiki。
如果您創建一個新規則,並將其添加到Wiki :)
一些規則可以使用--fix命令行標誌來固定。
$ npx textlint --fix README.md
# As a possible, textlint fix the content. 
另外,支持乾式運行模式。
$ npx textlint --fix --dry-run --format diff README.md
# show the difference between fixed content and original content.
您可以將其複制並粘貼到讀書中。
[ ![ textlint fixable rule ] ( https://img.shields.io/badge/textlint-fixable-green.svg?style=social )] ( https://textlint.github.io/ )使用以下格式:
例如,使用pretty-error Formatter:
$ npx textlint -f pretty-error file.md
@textlint/linter-formatter中的更多詳細信息。
您可以將Textlint用作節點模塊。
$ npm install textlint --save-dev
最小用法:
import { createLinter , loadTextlintrc , loadLinterFormatter } from "textlint" ;
const descriptor = await loadTextlintrc ( ) ;
const linter = createLinter ( { descriptor } ) ;
const results = await linter . lintFiles ( [ "*.md" ] ) ;
// textlint has two types formatter sets for linter and fixer
const formatter = await loadLinterFormatter ( { formatterName : "stylish" } ) ;
const output = formatter . format ( results ) ;
console . log ( output ) ;更多詳細信息信息,請閱讀以下文檔:
@textlint/bernel是textlint的低級API。它對於瀏覽器或非node.js環境很有用。
import { TextlintKernel } from "@textlint/kernel" ;
const kernel = new TextlintKernel ( ) ;
const options = {
filePath : "/path/to/file.md" ,
ext : ".md" ,
plugins : [
{
pluginId : "markdown" ,
plugin : require ( "@textlint/textlint-plugin-markdown" )
}
] ,
rules : [
{
ruleId : "no-todo" ,
rule : require ( "textlint-rule-no-todo" ) . default
}
]
} ;
kernel . lintText ( "TODO: text" , options ) . then ( result => {
assert . ok ( typeof result . filePath === "string" ) ;
assert . ok ( result . messages . length === 1 ) ;
} ) ; Textlint具有四個可擴展的點:

請參閱文檔/
no-todo規則。<!-- textlint-disable --> ?您可以使用過濾規則,例如Textlint-Filter-lule-comments。
有關更多詳細信息,請參閱忽略文本·文本。
有關更多詳細信息,請參見集成文檔。
該存儲庫是我們使用Lerna管理的MonorePo。這意味著我們實際上是從同一代碼庫向NPM發布了多個軟件包,包括:
這些模塊是textlint的一部分。
| 包裹 | 版本 | 描述 |
|---|---|---|
textlint | textlint命令行工具本身 | |
@textlint/kernel | Textlint主邏輯模塊。這是通用的JavaScript。 | |
@textlint/linter-formatter | textlint輸出格式 | |
@textlint/fixer-formatter | FIXER的Textlint輸出格式 | |
@textlint/textlint-plugin-markdown | 降價支持textlint | |
@textlint/textlint-plugin-text | 純文本支持Textlint | |
@textlint/ast-tester | Textlint AST的合規性測試 | |
@textlint/markdown-to-ast | Markdown解析器 | |
@textlint/ast-traverse | txtnode traverse庫 | |
@textlint/text-to-ast | 純文本解析器 | |
@textlint/config-loader | 加載.textlintrc配置文件 |
這些模塊對於文本規則/插件作者很有用。
| 包裹 | 版本 | 描述 |
|---|---|---|
@textlint/ast-node-types | textlint ast(抽象語法樹)類型定義 | |
textlint-tester | Textlint規則測試工具 | |
textlint-scripts | textlint規則NPM Run-Scripts | |
create-textlint-rule | 創建沒有構建配置的文本規則 |
這些模塊與TextLint有用。
| 包裹 | 版本 | 描述 |
|---|---|---|
gulp-textlint | textlint的Gulp插件 |
這些模塊是monorepo中的內部用法。
| 包裹 | 版本 | 描述 |
|---|---|---|
@textlint/feature-flag | 功能標誌管理器 |
textlint項目遵循語義版本控制。但是,對於大多數SEMVER項目,Textlint並沒有什麼不同。
.d.ts )對於錯誤和功能請求,請創建一個問題。
始終歡迎拉動請求。
有關更多詳細信息,請參見貢獻指南。
麻省理工學院©Azu
從ESLINT複製一些代碼。
ESLint
Copyright (c) 2013 Nicholas C. Zakas. All rights reserved.
https://github.com/eslint/eslint/blob/master/LICENSE
從Textlint/Media下載。
感謝Eslint。
Textlint網站由Netlify提供支持。