Skip to content

arihant2math/cargo-csc

Repository files navigation

cargo-csc

A code spell-checker, written in rust. This project aims to be a cleaner and faster replacement for cspell.

Installation

cargo install cargo-csc

Installing Dictionaries

cargo-csc requires dictionaries to test words against. We now have a first-party dictionary repository: https://github.com/arihant2math/cargo-csc-dicts

To install the first-party dictionaries, run:

cargo-csc import-dictionaries

This command also updates the installed dictionaries if rerun.

Any additional text files you'd want to use as dictionaries (words.txt for example) can be imported with cargo-csc install <URL|PATH>.

CLI Usage Guide

The cargo-csc CLI is a code spell checker that allows you to identify and manage spelling errors in your codebase. This guide provides an overview of the available commands, arguments, and options to help you effectively use the tool.

General Usage

cargo-csc <COMMAND> [OPTIONS]

Run cargo-csc --help to see the general help menu.

Example:

cargo-csc % cargo-csc check src/
Found 12 files
× TypoDiagnostic
╭─[src/args.rs:41:8]
40 │     pub ci: Option<String>,
41 │     /// Which files/folders to exclde from the search
·        ───────────────────────┬───────────────────────
·                               ╰── Typo here
42 │     #[clap(long)]
43 │     pub exclude: Vec<String>,
╰────
help: Unknown word `exclde`.

CI Integration

You can use cargo-csc in your CI pipelines to ensure code quality by checking for typos. For example, in a GitHub Actions workflow, you add the --ci github flag to the check command to emit GitHub annotations.


Commands Overview

Check

Checks a directory or set of files for typos.

cargo-csc check [OPTIONS]

Options:

  • --dir <PATH> (required): The path to the folder to scan for typos.
  • --glob <PATTERN>: A glob pattern to filter files (default: **/*.*).
  • --verbose (-v): Enables verbose output.
  • --progress (-p): Displays progress while processing files.
  • --exclude <PATH>: Files or folders to exclude from the search (can be repeated).
  • --extra-dictionaries <PATH>: Paths to additional dictionaries to use (can be repeated).
  • --max-depth <DEPTH>: Maximum directory depth to search.
  • --follow-symlinks: Follow symbolic links during the search.
  • --max-filesize <SIZE>: Maximum file size (in bytes) to process.
  • --jobs <NUMBER> (-j): Number of threads to use (default: number of CPUs).
  • --settings <PATH>: Path to a custom settings file.
  • --output <FORMAT>: Output format for results (json or text).

Example:

cargo-csc check src **/*.rs

Cache

Manages the cache used by the tool.

cargo-csc cache <SUBCOMMAND>

Subcommands:

  • build: Compile the wordlists into a cache (not implemented yet, caching happens on the fly).
  • clear: Clear the cached wordlists.

Install

Installs a dictionary from a local file or a URL.

cargo-csc install <URI>

Argument:

<URI>: Path to a local file or a URL to a dictionary file.

Example:

  • Install from a local file:
    cargo-csc install ./path/to/dictionary.txt
  • Install from a URL:
    cargo-csc install https://example.com/dictionary.txt

ImportDictionaries

Imports dictionaries from the cspell tool. Currently this doesn't support tries.

cargo-csc import-dictionaries

Settings

Example

// code-spellcheck.json
{
  "dictionary_definitions": [
    {
      "name": "custom",
      "path": "./custom.txt"
    }
  ],
  "dictionaries": [
    "custom",
    "en_US",
    "extra",
    "rust",
    "software_terms",
    "software_tools",
    "words"
  ],
  "ignore_paths": [
    "**/target/**",
    "**/node_modules/**"
  ],
  "words": [
    "wordlist",
    "wordlists"
  ]
}

Uninstalling

Once uninstalled, you can remove the settings and cache folder with:

rm -rf ~/.code-spellcheck

About

Code spell checker

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages