• Stars
    star
    887
  • Rank 51,456 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean).

AutoCorrect Icon

AutoCorrect

Go GitHub release (latest by date) Docker Image Version (latest server) Crates.io NPM PyPI version Gem Version Maven Central

🎯 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 的项目,并逐步完善规则细节,当前准确率较高(极少数异常情况),你可以放心用来辅助你完成自动纠正动作。

autocorrect lint output

Features

  • Add spacing between CJK (Chinese, Japanese, Korean) and English words.
  • Correct punctuations into full-width near the CJK.
  • Correct punctuations into half-width in English content.
  • (Experimental) Spellcheck and correct words with your dictionary.
  • Lint checking and output diff or JSON result, so you can integrate everywhere (GitLab CI, GitHub Action, VS Code, Vim, Emacs...)
  • Allows using .gitignore or .autocorrectignore to ignore files that you want to ignore.
  • Support more than 28 file types (Markdown, JSON, YAML, JavaScript, HTML ...), use AST parser to only check for strings, and comments.
  • Cross-platform for Linux, macOS, Windows, and WebAssembly, and as Native SDK for programming (Node.js, JavaScript Browser, Ruby, Python, Java).

典型应用场景

  • 撰写书籍、文档,新闻媒体等内容发布,应用于 Markdown、AsciiDoc、HTML 等文档场景,确保文案的标准化、专业化(案例:MDN 项目少数派)。
  • 集成 GitLab CI、GitHub Action、Travis CI 等 CI 环境,需要对项目进行自动化检查。
  • 集成到 Docusaurus、Hexo、Hugo、Jekyll、Gatsby 等静态网站生成器,在生成的时候自动格式化。
  • 利用语言支持的 SDK 集成到应用程序,在存储或输出网站内容的时候格式化,提升网站品质(如:Ruby ChinaV2EXLongbridge)。
  • 作为 VS Code、Intellij Platform IDE(已支持)、Vim、Emacs (待实现) 插件,需要对文案进行检查(Linter & Formatter),依靠 LintResult 给出的(Annotator、Diagnostic)提示。
  • 基于 WebAssembly 实现,作为 Chrome、Safari 等浏览器插件,应用于任何网站(待实现)
  • 也可以集成到 WYSIWYG Editor 里面,例如(ProseMirror、CKEditor、Slate、Draft.js、Tiptap、Monaco Editor、CodeMirror 等)。

Installation

$ brew install autocorrect

Or you can just install it via this:

$ curl -sSL https://git.io/JcGER | sh

After that, you will get autocorrect command.

$ autocorrect -V
AutoCorrect 2.4.0

Upgrade

Since: 1.9.0

AutoCorrect allows you to upgrade itself by autocorrect update command.

$ autocorrect update

NOTE: This command need you input your password, because it will install bin into /usr/local/bin directory.

Usage

Use in CLI

$ autocorrect text.txt
你好 Hello 世界

$ echo "hello世界" | autocorrect --stdin
hello 世界

$ autocorrect --fix text.txt
$ autocorrect --fix zh-CN.yml
$ autocorrect --fix

Lint

$ autocorrect --lint --format json text.txt

$ autocorrect --lint text.txt
Error: 1, Warning: 0

text.txt:1:3
-你好Hello世界
+你好 Hello 世界

You also can lint multiple files:

$ autocorrect --lint

Configuration

Default config: .autocorrect.default

$ autocorrect init
AutoCorrect init config: .autocorrectrc

NOTE: If you download fail, try to use autocorrect init --local command again.

Now the .autocorrectrc file has been created.

.autocorrectrc is allows use YAML, JSON format.

Config file example:

# yaml-language-server: $schema=https://huacnlee.github.io/autocorrect/schema.json
# Config rules
rules:
  # Auto add spacing between CJK (Chinese, Japanese, Korean) and English words.
  # 0 - off, 1 - error, 2 - warning
  space-word: 1
  # Add space between some punctuations.
  space-punctuation: 1
  # Add space between brackets (), [] when near the CJK.
  space-bracket: 1
  # Convert to fullwidth.
  fullwidth: 1
  # To remove space near the fullwidth.
  no-space-fullwidth: 1
  # Fullwidth alphanumeric characters to halfwidth.
  halfwidth-word: 1
  # Fullwidth punctuations to halfwidth in english.
  halfwidth-punctuation: 1
  # Spellcheck
  spellcheck: 2
textRules:
  # Config special rules for some texts
  # For example, if we wants to let "Hello你好" just warning, and "Hi你好" to ignore
  # "Hello你好": 2
  # "Hi你好": 0
fileTypes:
  # Config the files associations, you config is higher priority than default.
  # "rb": ruby
  # "Rakefile": ruby
  # "*.js": javascript
  # ".mdx": markdown
spellcheck:
  # 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

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你好: 0

After that, AutoCorrect will follow your textRules to process.

Ignore files

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.

Disable by inline comment

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 回到了启用的状态';
}

Disable some rules

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 回到了启用的状态。';
}

VS Code Extension

Install Extension

https://marketplace.visualstudio.com/items?itemName=huacnlee.autocorrect

内置 Visual Studio Code 插件,安装后会将 AutoCorrect 和 Visual Studio Code 完整集成,可以达到「保存自动格式化」或「纠正提示」。

如下图:

AutoCorrect for VS Code Extension

Intellij Platform Plugin

AutoCorrect for Intellij Platform Plugin

https://github.com/huacnlee/autocorrect-idea-plugin

GitHub Action

https://github.com/huacnlee/autocorrect-action

Add to your .github/workflows/ci.yml

steps:
  - name: Check source code
    uses: actions/checkout@v3

  - 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 programming

AutoCorrect makes for support use in many programming languages.

Benchmark

MacBook Pro (13-inch, M1, 2020)

Use make bench to run benchmark tests.

See autocorrect/src/benches/example.rs for details.

format_050              time:   [10.003 µs 10.013 µs 10.024 µs]
format_100              time:   [18.511 µs 18.550 µs 18.597 µs]
format_400              time:   [60.089 µs 60.216 µs 60.461 µs]
format_html             time:   [220.68 µs 220.91 µs 221.18 µs]
halfwidth_english       time:   [3.2353 µs 3.2452 µs 3.2545 µs]
format_json             time:   [55.620 µs 55.658 µs 55.695 µs]
format_javascript       time:   [108.63 µs 108.70 µs 108.79 µs]
format_json_2k          time:   [9.3879 ms 9.4871 ms 9.6541 ms]
format_jupyter          time:   [86.660 µs 86.743 µs 86.830 µs]
format_markdown         time:   [1.0007 ms 1.0123 ms 1.0285 ms]
spellcheck_50           time:   [1.9177 µs 1.9422 µs 1.9766 µs]
spellcheck_100          time:   [3.5868 µs 3.5909 µs 3.5950 µs]
spellcheck_400          time:   [14.873 µs 14.974 µs 15.110 µs]
lint_markdown           time:   [1.1195 ms 1.1205 ms 1.1215 ms]
lint_json               time:   [67.764 µs 68.341 µs 69.137 µs]
lint_html               time:   [280.87 µs 281.44 µs 282.20 µs]
lint_javascript         time:   [123.99 µs 125.50 µs 128.38 µs]
lint_yaml               time:   [433.41 µs 441.09 µs 452.74 µs]
lint_to_json            time:   [1.8391 ms 1.8428 ms 1.8476 ms]
lint_to_diff            time:   [1.8632 ms 1.8801 ms 1.9030 ms]

Real world benchmark

With MDN Translated Content project, it has about 30K files.

~/work/translated-content $ autocorrect --fix
AutoCorrect spend time: 8402.538ms

Other Extensions

The other implementations from the community.

User cases

License

This project under MIT license.

More Repositories

1

rails-settings-cached

Global settings for your Rails application.
Ruby
1,005
star
2

flora-kit

💐 基于 shadowsocks-go 做的完善实现,自动网络分流,完全兼容 Surge 的配置文件。
Go
898
star
3

redis-search

Deprecated! High performance real-time prefix search, indexes store in Redis for Rails application
Ruby
712
star
4

rucaptcha

Captcha Gem for Rails, which generates captcha image by Rust.
Ruby
686
star
5

quora

Quora.com like project with Ruby on Rails (不再维护)
JavaScript
684
star
6

init.d

⚙️ Batch scripts for Rails production environment install on Ubuntu Server.
678
star
7

bluedoc

An open-source document management tool for enterprise self host.
Ruby
626
star
8

social-share-button

Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
CoffeeScript
581
star
9

PokemonGoMove

Pokemon GO iOS GPS Emulator - NO Jailbreak needed, lets you play the game on your Mac :)
Python
412
star
10

imax.im

🎬 Source code of IMAX.im
Ruby
366
star
11

mediom

Forum web application, an example for from Rails to Go (Revel)
Go
355
star
12

jquery.qeditor

This is a simple WYSIWYG editor with jQuery.
CoffeeScript
259
star
13

carrierwave-aliyun

阿里云 OSS Ruby 上传组件,基于 Carrierwave
Ruby
195
star
14

auto-correct

Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, numerical digits and symbols).
Ruby
142
star
15

activestorage-aliyun

Wraps the Aliyun OSS as an Active Storage service.
Ruby
131
star
16

sails

Create a Thrift Server use like Rails
Ruby
71
star
17

turbolinks-prefetch

Turbolinks extends for prefetch links to speeds up your website.
JavaScript
70
star
18

personlab

我博客的源代码,这个代码较老,不推荐拿来学习
Ruby
69
star
19

vimmate

Custom vim like Textmate for Ruby on Rails development
Vim Script
69
star
20

mongoid_auto_increment_id

Override id field to MySQL like auto increment for Mongoid.
Ruby
65
star
21

hello-go

入门 Go 编写应用
Go
57
star
22

pasite

Share your sources code on the web, see the http://pasite.org
Ruby
55
star
23

zed-theme-macos-classic

A macOS native style theme for Zed, let it same like native app in macOS.
JavaScript
49
star
24

sql-builder

A simple SQL builder for generate SQL for non-ActiveRecord supports databases
Ruby
36
star
25

rails-activestorage-example

Rails use Active Storage the right way
Ruby
30
star
26

redmine-theme-innerboard

Innerboard theme for Redmine
26
star
27

cocoaout

Auto build and release tool for Cocoa projects.
Ruby
25
star
28

enumize

Extend ActiveRecord::Enum for add more helpful methods.
Ruby
24
star
29

jquery.lazyimg

Image lazy load plugin for jQuery, fork from jquery.unveil to improve performance with huge DOMs.
CoffeeScript
23
star
30

gitlab-mail-receiver

The way of allow your GitLab support Email receive and parse the email content, and find Issue/MergeRequest to create reply.
Ruby
23
star
31

redis-search-example

An example for use redis-search gem
JavaScript
23
star
32

ip-location

通过淘宝 IP 库查询 IP 所在地域位置 http://ip.taobao.com
Ruby
18
star
33

mongoid_taggable_on

Taggable on custom fields for Mongoid
Ruby
16
star
34

vscode-macos-classic.theme

macOS Classic theme for Visual Studio Code
Makefile
15
star
35

backup-aliyun

Aliyun OSS storage with Backup
Ruby
12
star
36

jdialog

a jQuery popup window plugin
JavaScript
12
star
37

html-pipeline.cr

HTML processing filters and utilities for Crystal.
Crystal
11
star
38

vue-rails-example

Use Vue.js in Rails 6 example
Ruby
9
star
39

actiontext-lite

Lite version of ActionText
Ruby
7
star
40

autocorrect-action

GitHub action for use AutoCorrect as lint
Shell
6
star
41

zed-extension-action

GitHub Action for automatically bump Zed Extensions version after a release.
JavaScript
6
star
42

docker-rails

Deploy Rails via Docker example
Ruby
5
star
43

booklib

php + Codeigniter Library management tool
PHP
4
star
44

vscode-blackboard-plus.theme

Visual Studio Code - Blackboard Plus Theme
4
star
45

zed-csv

CSV support for Zed
Rust
4
star
46

remarkdown

This is extends of Markdown lib from Crystal Stdlib for Support Markdown GFM.
Crystal
4
star
47

huacnlee.github.io

Ruby
3
star
48

vscode-autocorrect

AutoCorrect for VS Code
TypeScript
3
star
49

sidekiq-activerecord-shard

Sidekiq middleware to supports ActiveRecord 7 shard
Ruby
3
star
50

autocorrect-idea-plugin

AutoCorrect Plugin for IntelliJ IDEA
Kotlin
2
star
51

auto-booking-park

Shell
2
star
52

jselectdate

jQuery date choice control with dropdown list
JavaScript
2
star
53

capistrano-upload-configs

Capistrano plugin for Upload local config files to remote, and create soft link.
Ruby
2
star
54

zed-autocorrect

AutoCorrect for Zed
Rust
2
star
55

micro-web-simple

Go
1
star
56

jimagelink

模拟yupoo的缩略图上的小图标效果的jQuery插件
JavaScript
1
star
57

jcaches

client side cache with Javascript
JavaScript
1
star
58

yjs-server

JavaScript
1
star
59

Light-Classic.tmTheme

Improve of TextMate Light Theme from Mac Classic
1
star