A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean).
A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean).
AutoCorrect 的愿景是提供一套标准化的文案校正方案。以便于在各类场景(例如:撰写书籍、文档、内容发布、项目源代码...)里面应用,让使用者轻松实现标准化、专业化的文案输出 / 校正。
AutoCorrect is a linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean).
Like Eslint, Rubocop and Gofmt ..., AutoCorrect allows us to check source code, and output as colorized diff with corrected suggestions. You can integrate to CI (GitLab CI, GitHub Action, Travis CI....) for use to check the contents in source code. Recognize the file name, and find out the strings and the comment part.
AutoCorrect 是一个基于 Rust 编写的工具,用于「自动纠正」或「检查并建议」文案,给 CJK(中文、日语、韩语)与英文混写的场景,补充正确的空格,纠正单词,同时尝试以安全的方式自动纠正标点符号等等。
类似 ESlint、Rubocop、Gofmt 等工具,AutoCorrect 可以用于 CI 环境,它提供 Lint 功能,能便捷的检测出项目中有问题的文案,起到统一规范的作用。
支持各种类型源代码文件,能自动识别文件名,并准确找到字符串、注释做自动纠正。
此方案最早于 2013 年 出现于 Ruby China 的项目,并逐步完善规则细节,当前准确率较高(极少数异常情况),你可以放心用来辅助你完成自动纠正动作。
.gitignore or .autocorrectignore to ignore files that you want to ignore.You can install it via Homebrew:
$ brew install autocorrectYou can install it via Scoop:
$ scoop install autocorrectOr you can just install it via this on Unix-like system:
$ curl -sSL https://git.io/JcGER | shAfter that, you will get autocorrect command.
$ autocorrect -V
AutoCorrect 2.4.0Or install NPM:
$ yarn add autocorrect-node
$ yarn autocorrect -VSince: 1.9.0
AutoCorrect allows you to upgrade itself by autocorrect update command.
$ autocorrect updateNOTE: This command need you input your password, because it will install bin into
/usr/local/bindirectory.
$ autocorrect text.txt
你好 Hello 世界
$ echo "hello世界" | autocorrect --stdin
hello 世界
$ autocorrect --fix text.txt
$ autocorrect --fix zh-CN.yml
$ autocorrect --fix$ autocorrect --lint --format json text.txt
$ autocorrect --lint text.txtError: 1, Warning: 0
text.txt:1:3
-你好Hello世界
+你好 Hello 世界You also can lint multiple files:
$ autocorrect --lintHow to lint all changed files in Git:
$ git diff --name-only | xargs autocorrect --lintsince: 2.7.0
AutoCorrect has been published in NPM with CLI command support. If you want to use it in Frontend or Node.js project, you can just install autocorrect-node package for without install AutoCorrect bin.
cd your-project
yarn add autocorrect-nodeNow you can run yarn autocorrect command in your project. This command is same as autocorrect command.
$ yarn autocorrect -hMore docs: autocorrect-node/README.md
Default config: .autocorrect.default
$ autocorrect init
AutoCorrect init config: .autocorrectrcNOTE: If you download fail, try to use
autocorrect init --localcommand again.
Now the .autocorrectrc file has been created.
.autocorrectrc is allows use YAML, JSON format.
Config file example:
…Since: 2.2.0
When you want to config some special words or texts to ignore on format or lint.
The textRules config may help you.
For example, we want:
Hello世界 - To just give a warning.Hi你好 - To ignore.Use can config:
textRules:
Hello世界: 2
Hi你好: 0After that, AutoCorrect will follow your textRules to process.
Use .autocorrectignore to ignore files
Sometimes, you may want to ignore some special files that not want to check.
By default, the file matched .gitignore rule will be ignored.
You can also use .autocorrectignore to ignore other files, format like .gitignore.
If you just want to disable some special lines in a file, you can write a comment autocorrect-disable,
when AutoCorrect matched the comment include that, it will disable temporarily.
And then, you can use autocorrect-enable to reopen it again.
For example, in JavaScript:
function hello() {
// autocorrect-disable
console.log("现在这行开始autocorrect会暂时禁用");
console.log("这行也是disable的状态");
// autocorrect-enable
let a = "现在起autocorrect回到了启用的状态";
}The output will:
function hello() {
// autocorrect-disable
console.log("现在这行开始autocorrect会暂时禁用");
console.log("这行也是disable的状态");
// autocorrect-enable
let a = "现在起 autocorrect 回到了启用的状态";
}Since: 2.0
You can use autocorrect-disable <rule> in a comment to disable some rules.
Rule names please see: Configuration
function hello() {
// autocorrect-disable space-word
console.log("现在这行开始autocorrect会暂时禁用.");
// autocorrect-disable fullwidth
console.log("这行也是disable的状态.");
// autocorrect-enable
let a = "现在起autocorrect回到了启用的状态.";
}Will get:
function hello() {
// autocorrect-disable space-word
console.log("现在这行开始autocorrect会暂时禁用。");
// autocorrect-disable fullwidth, space-word
console.log("这行也是disable的状态.");
// autocorrect-enable
let a = "现在起 autocorrect 回到了启用的状态。";
}https://marketplace.visualstudio.com/items?itemName=huacnlee.autocorrect
Screenshot:
https://github.com/huacnlee/autocorrect-idea-plugin
https://github.com/huacnlee/autocorrect-action
Add to your .github/workflows/ci.yml
steps:
- name: Check source code
uses: actions/checkout@v4
- name: AutoCorrect
uses: huacnlee/autocorrect-action@mainAdd to your .gitlab-ci.yml, to use huacnlee/autocorrect Docker image to check.
autocorrect:
stage: build
image: huacnlee/autocorrect:latest
script:
- autocorrect --lint
# Enable allow_failure if you wants.
# allow_failure: trueSince: 2.8.0
AutoCorrect can work with reviewdog, so you can use it in CI/CD. ReviewDog will post a comment to your PR with the AutoCorrect change suggestions. Then the PR committer can easy to accept the suggestions.
Use --format rdjson option to output the lint results as the reviewdog supported format.
autocorrect --lint --format rdjson | reviewdog -f=rdjson -reporter=github-pr-reviewUse huacnlee/autocorrect-action can help you setup GitHub Action.
AutoCorrect makes for support use in many programming languages.
MacBook Pro (13-inch, Apple M3, 2023)
Use make bench to run benchmark tests.
See autocorrect/src/benches/example.rs for details.
…With MDN Translated Content project, it has about 30K files.
~/work/translated-content $ autocorrect --fix
AutoCorrect spend time: 8402.538msThe other implementations from the community.
This project under MIT license.
No open issues yet, or sync has not completed.