#documentation #grammar #spellcheck #languagetool

bin+lib cargo-languagetool

A third-party cargo extension for checking grammar in the documentation and comments

8 unstable releases (3 breaking)

new 0.4.1 Jun 15, 2024
0.4.0 May 27, 2024
0.3.3 May 26, 2024
0.2.0 May 26, 2024
0.1.0 May 26, 2024

#251 in Cargo plugins

Download history 318/week @ 2024-05-25 18/week @ 2024-06-01

336 downloads per month

MIT license

31KB
559 lines

cargo languagetool

Crates.io Version MIT

[!WARNING]
The command is still at alpha stage. Do not expect too much.

Improve the quality of your documentation. Use correct English words and grammar, let anyone understand your documentation, allow anyone to use your code, and reduce the time people need to spend to know how the crate works and what it does. Good examples are necessary, but correct spelling and understandable explanations are worth no less.

This is a fork of cargo-grammarly. Thanks to iddm for their prior work.

Grammarly discontinued their developer API. So, I decided to switch to LanguageTool. LanguageTool is free, open-source and has a free public API.

Installing

cargo install --git https://github.com/rnbguy/cargo-languagetool

Using

cargo languagetool
# or
cargo languagetool src/
$ cargo languagetool --help
A third-party cargo extension for checking grammar in the documentation and comments.

Usage: cargo languagetool [OPTIONS] [PATHS]...

Arguments:
  [PATHS]...  [default: .]

Options:
      --hostname <HOSTNAME>
          [env: LANGUAGETOOL_HOSTNAME=] [default: https://api.languagetoolplus.com]
  -p, --port <PORT>
          [env: LANGUAGETOOL_PORT=]
  -u, --username <USERNAME>
          [env: LANGUAGETOOL_USERNAME=]
  -a, --api-key <API_KEY>
          [env: LANGUAGETOOL_API_KEY=]
      --disable-categories <DISABLE_CATEGORIES>

      --enable-categories <ENABLE_CATEGORIES>

      --disable-rules <DISABLE_RULES>

      --enable-rules <ENABLE_RULES>

      --enable-only

      --language <LANGUAGE>
          [default: en-US]
      --picky

      --no-cache
          Disable cache query.
      --show-all
          Show all doc comments (even cached).
  -h, --help
          Print help
  -V, --version
          Print version

Configuring

The utility works out of the box. However, if you want to use your premium key, you may want to put it in the .env file or as an environment variable as:

LANGUAGETOOL_USERNAME=jane@doe.com
LANGUAGETOOL_API_KEY=1234abcd

If you would like to use your own server, you can put the server URL in the .env or as an environment variable as:

LANGUAGETOOL_HOSTNAME=http://localhost
LANGUAGETOOL_PORT=8010

[!TIP]
You can use ltrs docker (languagetool-rust CLI) to launch a local languagetool docker container.

How it works

The utility simply grabs all the doc comments (///, //!, #![doc = "text"] and #[doc = "text"]) from your crate's source code and sends it to the languagetool grammar checking API using the languagetool-rust crate. If there are any mistakes in your texts, they are printed using the way the rustc compiler prints its warnings and errors, using the annotate-snippets crate.

The doc comments are parsed using the syn and proc_macro2 crates. These are used specifically to know where in the code these comments are. Doing it with regular expressions would waste a lot of time.

Dependencies

~13–28MB
~426K SLoC