Harper Grammar Checker

repository·master·Indexed 11 days ago

https://github.com/automattic/harper

A fast, private, and lightweight English grammar checker that runs on-device to provide millisecond-level linting. It offers a variety of integrations including harper-core for Rust (v2.7.0), harper.js for JavaScript/TypeScript, harper-wasm for WebAssembly, and plugins for VS Code, Obsidian, and WordPress. The ecosystem includes harper-cli for automated file checking and harper-comments for parsing programming language comments via tree-sitter.

Tokens
50.5K
Snippets
177
Records
263
Agent score
96%

What's inside Harper

  1. Overview of Harper for VS Code

    master

    Harper is a next-generation grammar checker designed for code. It serves as an alternative to tools like Grammarly by catching stylistic errors, complex grammatical issues, and layout-related problems.

    Key features include:

    • Broad Language Support: Works with almost all common programming languages and various markup formats.
    • On-device Execution: Runs locally on your machine, ensuring low memory usage and millisecond-level feedback.
    • API Documentation Protection: Helps ensure that comments in languages like Rust, Java, or JavaScript remain grammatically correct, preventing poor search engine ranking or quality issues in your public API documentation.
  2. Overview of Harper

    master
    Harper is a high-performance, privacy-focused English grammar checker. Unlike many competitors, it is designed to be lightweight and fast, capable of linting documents in milliseconds with a minimal memory footprint. It is completely private, meaning your data is not sent to external servers for processing. Harper is also small enough to be loaded via WebAssembly.
  3. Introduction to the Weir Language

    master

    Weir is an expression language used to define linguistic rules and conventions for Harper to enforce. It allows individuals and organizations to implement style guides (e.g., Oxford comma usage, capitalization rules, or brand name enforcement).

    A typical Weir rule consists of an expression defining the pattern to match, followed by metadata describing the error and the correction. You can experiment with rules in the Weir studio.

    expr main [(G [Suite, Suit]), (Google Apps for Work)]
    
    let message "Use the updated brand."
    let description "`G Suite` or `Google Apps for Work` is now called `Google Workspace`"
    let kind "Miscellaneous"
    let becomes "Google Workspace"
  4. Use `harper-comments` to locate and parse programming language comments

    master

    harper-comments is a crate designed to help Harper identify and extract comments from various programming languages. It functions primarily as a wrapper around tree-sitter to locate comments across a wide range of languages.

    Additionally, it provides purpose-built parsers for structured comments in specific languages (such as Go). These specialized parsers are accessible via the CommentParser and are enabled automatically through it.

  5. Understand the website repository structure

    master

    The website code is organized into several key directories within the repository:

    PathPurpose
    packages/web/src/routes/Site routes: marketing pages (.svelte), docs (.md), and API handlers (+server.ts)
    packages/web/src/routes/docs/Contributor and user documentation
    packages/web/src/lib/Shared Svelte components, marketing sections, and small utilities
    packages/web/vite.config.tsVite config, SveltePress theme, and documentation sidebar
    packages/lint-framework/Browser linting UI (underlines, popups) reused by the site and extensions
    packages/harper-editor/Embeddable Harper editor used on the homepage and /editor
    packages/components/Shared UI primitives consumed by the site and other packages
    packages/harper.js/JavaScript API over harper-wasm
  6. Key features of Harper for Obsidian

    master

    Harper is designed as a privacy-focused, high-performance grammar checker for Obsidian users. Key characteristics include:

    • Privacy: Runs entirely offline inside Obsidian. Your data is not sent to centralized servers.
    • Code Awareness: Explicitly ignores the contents of code fences and inline code blocks to prevent false positives in technical writing.
    • Performance: Faster than network-based alternatives (like Grammarly or LanguageTool) because it eliminates network latency by running on-device.
    • Real-Time Checking: Provides immediate feedback as you type.
  7. Use `harper-dictionary-wordlist` to load wordlists

    master

    The harper-dictionary-wordlist package provides utility methods designed to facilitate loading external wordlists into Harper dictionaries. This is useful for extending Harper's vocabulary with custom or domain-specific terms.

    For detailed API documentation and specific method signatures, refer to the generated cargo doc for this crate.

  8. Use harper-cli for automated file checking

    master
    harper-cli is an experimental frontend for Harper designed for automated environments. It is primarily intended for scenarios where you need to check a large number of files automatically, such as within a Continuous Integration (CI) pipeline.