AutoCorrect
🎯 AutoCorrect 的愿景是提供一套标准化的文案较正方案。以便于在各类场景(例如:撰写书籍、文档、内容发布、项目源代码...)里面应用,让使用者轻松实现标准化、专业化的文案输出 / 校正。
AutoCorrect is a linter and formatter to help you to improve copywriting, correct spaces, words, punctuations between CJK (Chinese, Japanese, Korean).
Like Eslint, Rubocop, Gofmt ..., AutoCorrect allows us to check source code, and output as colorized diff with corrected suggest. You can integrate to CI (GitLab CI, GitHub Action, Travis CI....) for use to checking the contents in source code. Recognize the file name, and find out the strings and the comment part.
基于 Rust 编写的 CLI 工具,用于「自动纠正」或「检查并建议」文案,给 CJK(中文、日语、韩语)与英文混写的场景,补充正确的空格,纠正单词,同时尝试以安全的方式自动纠正标点符号等等。
类似 ESlint、Rubocop、Gofmt 等工具,AutoCorrect 可以用于 CI 环境,它提供 Lint 功能,能便捷的检测出项目中有问题的文案,起到统一规范的作用。
支持各种类型源代码文件,能自动识别文件名,并准确找到字符串、注释做自动纠正。
此方案最早于 2013 年 出现于 Ruby China 的项目,并逐步完善规则细节,当前准确率较高(极少数异常情况),你可以放心用来辅助你完成自动纠正动作。
Other implements for programming:
- Rust - autocorrect
- Ruby - auto-correct
- Go - go-auto-correct
Features
- Auto add spacing between CJK (Chinese, Japanese, Korean) and English words.
- Multiple file content support (HTML, YAML, Rust, Go, SQL, Ruby, Python, Objective-C, Swift, Java, Kotlin, Dart, JavaScript, CSharp ...).
- Fullwidth -> halfwidth (only for [a-zA-Z0-9], and
:in time). - Correct punctuations into Fullwidth near the CJK.
- Spellcheck and correct words by your own dictionary.
- Lint checking and output diff or JSON result, so you can integrate to everywhere (GitLab CI, GitHub Action, VS Code, Vim, Emacs...)
- Allows using
.gitignoreor.autocorrectignoreto ignore files that you want to ignore. - Desktop app for macOS, (Windows, Linux WIP).
Install
🍏 AutoCorrect 还为非技术人员提供了比较简单的桌面端版本,如有需要可访问 Download 页面来下载。
|
After that, you will get /usr/local/bin/autocorrect command.
)
<file>...
)
Upgrade
After: 1.9.0
AutoCorrect allows you to upgrade itself by autocorrect update command.
NOTE: This command need you input your password, because it will install bin into
/usr/local/bindirectory.
Usage
- Using CLI
- Configuration
- VS Code Extension
- Use for JavaScript
- Use for Node.js
- Use for Rust
- GitHub Action
- GitLab CI
Using CLI
Lint
--> text.txt:1:3
- 你好Hello世界
+ 你好 Hello 世界
You also can lint multiple files:
Configuration
NOTE: If you download fail, try to use
autocorrect init --localcommand again.
Now the .autocorrectrc file has created.
.autocorrectrc is allows use YAML, JSON format.
Config file example:
# Config for Speelcheck
spellcheck:
# 0 - Disabled, 1 - Format and Lint, 2 - LintOnly
mode: 1
# Correct Words (Case insensitive) for by Spellcheck
words:
- GitHub
- App Store
# This means "appstore" into "App Store"
- AppStore = App Store
- Git
- Node.js
- nodejs = Node.js
- VIM
- DNS
- HTTP
- SSL
Ignore option
Use .autocorrectignore to ignore files
Sometimes, you may want to ignore some special files that not wants to check.
By default, the file matched .gitignore rule will be ignored.
You can also use .autocorrectignore to ignore other files, format like .gitignore.
Disable with inline comment
If you just want to disable some special lines in file, you can write a comment autocorrect: false or autocorrect-disable,
when AutoCorrect matched comment include that, it will disable temporary.
And then, you can use autocorrect: true or autocorrect-enable to reopen it again.
For example, in JavaScript:
The output will:
VS Code Extension
https://marketplace.visualstudio.com/items?itemName=huacnlee.auto-correct
内置 Visual Studio Code 插件,安装后会将 AutoCorrect 和 Visual Studio Code 完整集成,可以达到「保存自动格式化」或「纠正提示」。
如下图:
GitHub Action
https://github.com/marketplace/actions/huacnlee-autocorrect
Add to your .github/workflows/ci.yml
steps:
- name: Check source code
uses: actions/checkout@main
- name: AutoCorrect
uses: huacnlee/autocorrect-action@main
GitLab CI
Add 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: true
Use for JavaScript
AutoCorrect also provide a JavaScript module via WebAssembly, you can use it in your JavaScript project.
And then:
const autocorrect = import;
const raw = `<p>你好Hello世界</p>`;
autocorrect.;
Use for Node.js
When you want use AutoCorrect in Node.js, you must install @huacnlee/autocorrect-node.
And then:
const autocorrect = require;
autocorrect.;
// "你好 Hello 世界"
Use for Rust
In your Cargo.toml
[]
= "1.0.0"
Use autocorrect::format to format plain text.
extern crate autocorrect;
Benchmark
MacBook Pro (13-inch, M1, 2020)
Use make bench to run benchmark tests.
See autocorrect/src/benches/example.rs for details.
)
)
)
)
)
)
)
)
)
)
)
| Type | Total chars | Duration |
|---|---|---|
| format | 50 | 0.014 ms |
| format | 100 | 0.019 ms |
| format | 400 | 0.045 ms |
| format | Markdown | 2.8 ms |
| spellcheck | 50 | 0.037 ms |
| spellcheck | 100 | 0.057 ms |
| spellcheck | 400 | 0.195 ms |
Real world benchmark
With MDN Translated Content project, it's has about 30K files.
License
This project under MIT license.