เครื่องมือผ้าสำลีที่สามารถทำได้สำหรับข้อความและ markdown
TextLint คล้ายกับ ESLINT แต่ใช้กับภาษาธรรมชาติ
เยี่ยมชม https://textlint.github.io/
npm install textlint-rule-xxxสำหรับการทัวร์อย่างรวดเร็วของ TextLint ให้ชำระเงินคู่มือการเริ่มต้นใช้งานของเรา: กระรอก:
คุณสามารถติดตั้งคำสั่ง textlint โดยใช้ NPM:
$ npm install textlint --save-dev
ความต้องการ :
หากคุณไม่แน่ใจว่าคุณกำลังใช้โหนดเวอร์ชันใดคุณสามารถเรียกใช้ node -v ในคอนโซลของคุณเพื่อค้นหา
textlint ทั่วโลกคุณต้องติดตั้งกฎอ้างอิงแต่ละข้อทั่วโลกเช่นกันtextlint ในเครื่องคุณต้องติดตั้งแต่ละกฎในเครื่องด้วย เราขอแนะนำให้ติดตั้ง textlint ในเครื่อง
หากคุณไม่เคยใช้ node.js และ npm โปรดดูสิ่งต่อไปนี้:

TextLint ไม่มีกฎเริ่มต้น !!
คุณสามารถเรียกใช้ไฟล์ textlint ด้วย .textlintrc.json ไฟล์กำหนดค่า
# 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 Load textlint .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 ใด ๆ ที่คุณส่งผ่านคำพูด
$ npx textlint " docs/** "สำหรับรายละเอียดเพิ่มเติมดูเอกสารประกอบ CLI
ตัวอย่าง:
.textlintrc เป็นไฟล์กำหนดค่าที่โหลดเป็น JSON, YAML หรือ JS ผ่าน AZU/RC-Config-Loader
รันข้อความด้วยอาร์กิวเมนต์ต่อไปนี้
$ npx textlint --rule no-todo --rule very-nice-rule README.md
เทียบเท่ากับการรัน textlint README.md ในไดเรกทอรีที่มี .textlintrc.json ที่มี json ต่อไปนี้
{
"rules" : {
"no-todo" : true ,
"very-nice-rule" : true
}
} คุณยังสามารถกำหนดค่าตัวเลือกสำหรับกฎเฉพาะในไฟล์ .textlintrc.json ของคุณ
{
"rules" : {
"no-todo" : false , // disable
"very-nice-rule" : {
"key" : " value "
}
}
} ตัวอย่างเช่นที่นี่เราผ่านตัวเลือก ("คีย์": "ค่า") ไปยัง very-nice-rule
ตัวเลือกสามารถระบุได้ในไฟล์ .textlintrc.json ของคุณดังนี้:
{
// Allow to comment in JSON
"rules" : {
"<rule-name>" : true | false | object
}
}สำหรับรายละเอียดเพิ่มเติมดู
ปลั๊กอิน TextLint เป็นชุดของกฎและ rulesconfig หรือปรับแต่งตัวแยกวิเคราะห์
ในการเปิดใช้งานปลั๊กอินให้ใส่ "ปลั๊กอินชื่อ" ลงใน .textlintrc.json
// `.textlintrc.json`
{
"plugins" : [
"plugin-name"
] ,
// overwrite-plugins rules config
// <plugin>/<rule>
"rules" : {
"plugin-name/rule-name" : false
}
}ดู docs/plugin.md
TextLint รองรับ markdown และข้อความธรรมดาโดยค่าเริ่มต้น
ติดตั้ง ปลั๊กอินโปรเซสเซอร์ และเพิ่มการสนับสนุนรูปแบบไฟล์ใหม่
ตัวอย่างเช่นหากคุณต้องการผ้าสำลี HTML ให้ใช้ TextLint-Plugin-HTML เป็นปลั๊กอิน
npm install textlint-plugin-html --save-dev
เพิ่ม "html" เป็น .textlintrc.json
{
"plugins": [
"html"
]
}
เรียกใช้ textlint บนไฟล์ .html :
textlint index.html
ประเภทไฟล์ที่รองรับเสริม:
ดูรายการปลั๊กอินโปรเซสเซอร์สำหรับรายละเอียด
TextLint ไม่ได้มีกฎในตัว แต่มีกฎที่สามารถเสียบได้มากกว่า 100 รายการ:
ดูคอลเลกชันของ TextLint Rule · TextLint/TextLint Wiki สำหรับรายละเอียดเพิ่มเติม
หากคุณสร้างกฎใหม่และเพิ่มลงในวิกิ :)
กฎบางอย่างสามารถแก้ไขได้โดยใช้ธงบรรทัดคำสั่ง --fix
$ npx textlint --fix README.md
# As a possible, textlint fix the content. 
นอกจากนี้รองรับโหมด Dry Run
$ npx textlint --fix --dry-run --format diff README.md
# show the difference between fixed content and original content.
คุณสามารถคัดลอกและวางลงใน readme ของคุณ
[ ![ textlint fixable rule ] ( https://img.shields.io/badge/textlint-fixable-green.svg?style=social )] ( https://textlint.github.io/ )ใช้ Formatters ต่อไปนี้:
เช่นใช้รูปแบบ pretty-error :
$ 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/เคอร์เนลเป็น API ระดับต่ำสำหรับ TextLint มันมีประโยชน์สำหรับสภาพแวดล้อมของเบราว์เซอร์หรือไม่ใช่ 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-rule-comments
โปรดดูการละเว้นข้อความ· TextLint สำหรับรายละเอียดเพิ่มเติม
สำหรับรายละเอียดเพิ่มเติมดูเอกสารการรวม
ที่เก็บนี้เป็น monorepo ที่เราจัดการโดยใช้ Lerna นั่นหมายความว่าเราเผยแพร่แพ็คเกจหลายฉบับให้กับ NPM จาก codebase เดียวกันรวมถึง:
โมดูลเหล่านี้เป็นส่วนหนึ่งของ TextLint
| บรรจุุภัณฑ์ | รุ่น | คำอธิบาย |
|---|---|---|
textlint | เครื่องมือบรรทัดคำสั่ง textlint เอง | |
@textlint/kernel | โมดูลลอจิกหลักของ TextLint มันเป็นจาวาสคริปต์สากล | |
@textlint/linter-formatter | Formatter เอาต์พุต TextLint | |
@textlint/fixer-formatter | TextLint Output Formatter สำหรับ Fixer | |
@textlint/textlint-plugin-markdown | การสนับสนุน Markdown สำหรับ textlint | |
@textlint/textlint-plugin-text | รองรับข้อความธรรมดาสำหรับ TextLint | |
@textlint/ast-tester | การทดสอบการปฏิบัติตามกฎระเบียบสำหรับ AST ของ TextLint | |
@textlint/markdown-to-ast | ตัวแยกวิเคราะห์ Markdown | |
@textlint/ast-traverse | TxtNode Traverse Library | |
@textlint/text-to-ast | ตัวแยกวิเคราะห์ข้อความธรรมดา | |
@textlint/config-loader | โหลดไฟล์กำหนดค่า. TEXTLINTRC |
โมดูลเหล่านี้มีประโยชน์สำหรับผู้เขียน TextLint Rule/Plugin
| บรรจุุภัณฑ์ | รุ่น | คำอธิบาย |
|---|---|---|
@textlint/ast-node-types | TextLint AST (บทคัดย่อไวยากรณ์ทรี) คำจำกัดความประเภท | |
textlint-tester | เครื่องมือทดสอบกฎ TextLint | |
textlint-scripts | TextLint กฎ npm run-scripts | |
create-textlint-rule | สร้างกฎ TextLint โดยไม่มีการกำหนดค่าการสร้าง |
โมดูลเหล่านี้เป็นการรวมที่มีประโยชน์กับ TextLint
| บรรจุุภัณฑ์ | รุ่น | คำอธิบาย |
|---|---|---|
gulp-textlint | Gulp Plugin สำหรับ TextLint |
โมดูลเหล่านี้คือการใช้งานภายในในโมโนเรป
| บรรจุุภัณฑ์ | รุ่น | คำอธิบาย |
|---|---|---|
@textlint/feature-flag | ตัวจัดการธงฟีเจอร์ |
TextLint Project ติดตามการกำหนดเวอร์ชันความหมาย อย่างไรก็ตาม TextLint ไม่แตกต่างกันกับโครงการ SEMVER ส่วนใหญ่
.d.ts )สำหรับข้อบกพร่องและคำขอคุณสมบัติโปรดสร้างปัญหา
คำขอดึงยินดีต้อนรับเสมอ
สำหรับรายละเอียดเพิ่มเติมดูคู่มือการสนับสนุน
mit © 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