### Install Harper via Scoop Source: https://writewithharper.com/docs/integrations/language-server Use this command to install the Harper package on Windows using Scoop. ```bash scoop install harper ``` -------------------------------- ### BinaryModule.setup() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.setup.html Initializes the BinaryModule. This method returns a Promise that resolves when the setup is complete. ```APIDOC ## BinaryModule.setup() ### Description Initializes the BinaryModule. This method returns a Promise that resolves when the setup is complete. ### Method ``` setup(): Promise; ``` ### Endpoint N/A (This is a method call, not an HTTP endpoint) ### Parameters None ### Request Body None ### Response #### Success Response (Promise) - Resolves when the BinaryModule is successfully set up. #### Response Example ```javascript // Example of calling the method and handling the promise BinaryModule.setup() .then(() => { console.log('BinaryModule setup complete!'); }) .catch(error => { console.error('Error setting up BinaryModule:', error); }); ``` ``` -------------------------------- ### Install Integration Test Dependencies Source: https://writewithharper.com/docs/contributors/environment Install required system libraries for running integration tests on Ubuntu. ```bash sudo apt-get install libnss3 sudo apt-get install libasound2 ``` -------------------------------- ### Install Harper Extension via CLI Source: https://writewithharper.com/docs/integrations/visual-studio-code Use this command to install the Harper extension directly from the terminal. ```bash code --install-extension elijah-potter.harper ``` -------------------------------- ### BinaryModule.setup() Method Signature Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.setup.html Defines the asynchronous setup method for the BinaryModule class. ```typescript setup(): Promise; ``` -------------------------------- ### Install Harper via Nixpkgs (Nix Command/Flakes) Source: https://writewithharper.com/docs/integrations/language-server Install Harper using Nix Command and Flakes experimental features. This command ensures Harper is available in your current shell environment. ```bash nix shell 'nixpkgs#harper' ``` -------------------------------- ### Install Harper Stable Release via Pacman Source: https://writewithharper.com/docs/integrations/language-server Install the latest stable release of Harper from the `extra` repository on Arch Linux using Pacman. ```bash sudo pacman -S harper ``` -------------------------------- ### Install Harper via Homebrew Source: https://writewithharper.com/docs/integrations/language-server Use this command to install the Harper package on macOS and Linux using Homebrew. ```bash brew install harper ``` -------------------------------- ### Install VS Code Extension Source: https://writewithharper.com/docs/contributors/visual-studio-code Install a packaged VS Code extension using the `code --install-extension` command, providing the path to the generated .vsix file. ```bash code --install-extension path/to/created/.vsix ``` -------------------------------- ### Initialize Nix Development Shell Source: https://writewithharper.com/docs/contributors/environment Start a shell environment pre-configured with all necessary build tools. ```bash nix develop ``` -------------------------------- ### Install harper-ls via Cargo Source: https://writewithharper.com/docs/integrations/language-server Install the `harper-ls` language server using Cargo, Rust's package manager. Ensure `~/.cargo/bin` is in your system's PATH. ```bash cargo install harper-ls --locked ``` -------------------------------- ### Install Harper binary via Cargo Source: https://writewithharper.com/docs/contributors/review Use this command to install a specific branch of a Harper binary artifact directly from the repository. ```bash cargo install --git https://github.com/automattic/harper --branch --locked ``` ```bash cargo install --git https://github.com/automattic/harper --branch somewhat-something harper-cli --locked ``` -------------------------------- ### Setup harper-ls with nvim-lspconfig Source: https://writewithharper.com/docs/integrations/neovim Basic initialization for the Harper language server using the nvim-lspconfig plugin. ```lua require('lspconfig').harper_ls.setup {} ``` -------------------------------- ### harper-ls Linter Configuration Example Source: https://writewithharper.com/docs/integrations/language-server Configure individual linters by setting boolean values within the 'linters' object. This example shows how to enable or disable various checks like 'SpellCheck', 'SpelledNumbers', and 'LongSentences'. ```json { "harper-ls": { "linters": { "SpellCheck": true, "SpelledNumbers": false, "AnA": true, "SentenceCapitalization": true, "UnclosedQuotes": true, "WrongQuotes": false, "LongSentences": true, "RepeatedWords": true, "Spaces": true, "Matcher": true, "CorrectNumberSuffix": true } } } ``` -------------------------------- ### Install Harper Bleeding-Edge via AUR Helper Source: https://writewithharper.com/docs/integrations/language-server Install the `harper-git` package for the bleeding-edge version on Arch Linux using an AUR helper like `paru` or `yay`. ```bash paru -S harper-git ``` -------------------------------- ### Example stats.txt Log Entries Source: https://writewithharper.com/docs/contributors/local-stats These are example lines from the stats.txt file, each representing a logged event as a JSON object. They detail linting actions, such as spelling errors, along with timestamps and unique identifiers. ```json {"kind":{"Lint":{"kind":"Spelling","context":[{"content":"mispelled","kind":{"kind":"Word","value":null}}]}},"when":1743696274,"uuid":"39d29bd0-5eb1-4bad-89ee-5a48531a4cbe"} ``` ```json {"kind":{"Lint":{"kind":"Spelling","context":[{"content":"isnt","kind":{"kind":"Word","value":null}}]}},"when":1743696281,"uuid":"22e1ca15-e583-49c5-9da3-bc7e625d9682"} ``` ```json {"kind":{"Lint":{"kind":"Spelling","context":[{"content":"Teasting","kind":{"kind":"Word","value":null}}]}},"when":1743696288,"uuid":"bd955190-a4d9-4f3e-b7df-d4bf6f12a415"} ``` -------------------------------- ### Configure native Neovim LSP for Harper Source: https://writewithharper.com/docs/integrations/neovim Setup Harper using Neovim's built-in LSP client without external plugins. ```lua -- General LSP setup vim.lsp.config['*'] = { capabilities = { textDocument = { semanticTokens = { multilineTokenSupport = true } } }, root_markers = { '.git' }, } vim.diagnostic.config({ virtual_lines = true }) -- Harper specific setup vim.lsp.config['harper'] = { cmd = { 'harper-ls', '--stdio' }, filetypes = { 'markdown', 'text', 'tex', 'typst' } } vim.lsp.enable('harper') ``` -------------------------------- ### Install Harper via Nixpkgs (Ephemeral Shell) Source: https://writewithharper.com/docs/integrations/language-server Try Harper within an ephemeral shell using Nixpkgs. Ensure `harper` is available in your Nix channels. ```bash nix-shell -p harper ``` -------------------------------- ### Development Workflow Command Source: https://writewithharper.com/docs/contributors/obsidian Use this command to set up the environment, navigate to the plugin directory, and start the development server. This command continuously rebuilds main.js on file changes. ```bash just setup && cd packages/obsidian-plugin && pnpm dev ``` -------------------------------- ### Install harper.js via package manager Source: https://writewithharper.com/docs/harperjs/introduction Use this command to add the harper.js package to your project dependencies. ```shell npm install --save harper.js ``` -------------------------------- ### GET BinaryModule.getDefaultLintConfigAsJSON Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.getdefaultlintconfigasjson.html Retrieves the default lint configuration for the project as a JSON-formatted string. ```APIDOC ## GET BinaryModule.getDefaultLintConfigAsJSON ### Description Retrieves the default lint configuration as a JSON string. ### Method GET ### Endpoint BinaryModule.getDefaultLintConfigAsJSON() ### Response #### Success Response (200) - **result** (string) - A JSON string representing the default lint configuration. #### Response Example { "result": "{\"rules\": {\"no-console\": \"error\"}}" } ``` -------------------------------- ### GET /WorkerLinter/getLintDescriptions Source: https://writewithharper.com/docs/harperjs/ref/harper.js.workerlinter.getlintdescriptions.html Retrieves a collection of linting rule descriptions as a key-value map. ```APIDOC ## GET /WorkerLinter/getLintDescriptions ### Description Retrieves a dictionary of linting rule identifiers and their corresponding human-readable descriptions. ### Method GET ### Endpoint /WorkerLinter/getLintDescriptions ### Response #### Success Response (200) - **data** (Record) - A map where keys are lint rule IDs and values are their descriptions. #### Response Example { "no-unused-vars": "Disallow unused variables", "eqeqeq": "Require the use of === and !==" } ``` -------------------------------- ### Create Test Markdown Source: https://writewithharper.com/docs/contributors/author-a-rule Define an example of the error the rule should detect in a markdown file. ```markdown This is an test of the `an_a` rule. Your test should look different. ``` -------------------------------- ### GET Linter.getLintConfig Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getlintconfig.html Retrieves the current configuration object for the linter. ```APIDOC ## GET Linter.getLintConfig() ### Description Retrieves the current configuration settings for the linter. ### Method GET ### Endpoint Linter.getLintConfig() ### Response #### Success Response (200) - **LintConfig** (object) - The current configuration object for the linter. ``` -------------------------------- ### Expected Files in Dedicated Plugin Directory Source: https://writewithharper.com/docs/contributors/obsidian After successful development setup, the dedicated plugin directory should contain these three essential files: the main JavaScript code, the plugin manifest, and the configuration data. ```plaintext main.js manifest.json data.json ``` -------------------------------- ### GET Linter.getLintDescriptionsAsJSON Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getlintdescriptionsasjson.html Retrieves the linting rule descriptions as a JSON map, formatted in Markdown. ```APIDOC ## GET Linter.getLintDescriptionsAsJSON() ### Description Retrieves the linting rule descriptions as a JSON map, formatted in Markdown. ### Method GET ### Endpoint Linter.getLintDescriptionsAsJSON() ### Response #### Success Response (200) - **result** (Promise) - A promise that resolves to a string containing the JSON map of linting rules. ``` -------------------------------- ### GET /linter/getLintDescriptionsHTMLAsJSON Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getlintdescriptionshtmlasjson.html Retrieves the linting rule descriptions as a JSON map, formatted in HTML. This method wraps the BinaryModule function of the same name. ```APIDOC ## GET /linter/getLintDescriptionsHTMLAsJSON ### Description Get the linting rule descriptions as a JSON map, formatted in HTML. Wraps the function on the BinaryModule by the same name. ### Method GET ### Endpoint /linter/getLintDescriptionsHTMLAsJSON ### Response #### Success Response (200) - **result** (string) - A JSON string containing the linting rule descriptions formatted in HTML. #### Response Example { "result": "{\"rule-id\": \"

Description in HTML

\"}" } ``` -------------------------------- ### Get Linter Configuration as JSON Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getlintconfigasjson.html Returns a promise that resolves to the linter configuration in JSON format. ```typescript getLintConfigAsJSON(): Promise; ``` -------------------------------- ### Package VS Code Extension Source: https://writewithharper.com/docs/contributors/visual-studio-code Package the VS Code extension using the `just package-vscode` command. This command prepares the extension for installation. ```bash just package-vscode ``` -------------------------------- ### Get Error Description with Lint.message() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.lint.message.html Call this method to retrieve a string that describes the current error. No setup or imports are required beyond having an error object. ```javascript message(): string; ``` -------------------------------- ### Linter.setup() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.setup.html Initializes the linter by downloading and compiling the required WebAssembly binary. ```APIDOC ## Linter.setup() ### Description Complete any setup that is necessary before linting. This may include downloading and compiling the WebAssembly binary. This setup will complete when needed regardless of whether you call this function. This function exists to allow you to do this work when it is of least impact to the user experiences. ### Method Method Call ### Signature setup(): Promise; ### Response - **Returns** (Promise) - A promise that resolves when the setup is complete. ``` -------------------------------- ### Weir rule example: Abbreviation expansion Source: https://writewithharper.com/docs/weir Example rule definition for expanding abbreviations. ```plaintext expr main (w/o) let message "Use `without` instead of `w/o`" let description "Expands the abbreviation `w/o` to the full word `without` for clarity." let kind "Style" let becomes "without" ``` -------------------------------- ### LocalLinter.setup() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.setup.html Initializes the LocalLinter instance. ```APIDOC ## LocalLinter.setup() ### Description Initializes the LocalLinter environment. This method must be called before performing linting operations. ### Method N/A (Class Method) ### Returns - **Promise** - A promise that resolves when the setup is complete. ``` -------------------------------- ### Weir rule example: Redundancy correction Source: https://writewithharper.com/docs/weir Example rule definition for correcting redundant phrases. ```plaintext expr main (like as if) let message "Avoid redundancy. Use either `like` or `as if`." let description "Corrects redundant `like as if` to `like` or `as if`." let becomes ["like", "as if"] test "And looks like as if linux-personality hasn't got any changes for 8 years." "And looks as if linux-personality hasn't got any changes for 8 years." ``` -------------------------------- ### Get default linter configuration as JSON Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getdefaultlintconfigasjson.html Returns a promise that resolves to the default configuration string. This method does not impact the current linter state. ```typescript getDefaultLintConfigAsJSON(): Promise; ``` -------------------------------- ### List Available Build Tools Source: https://writewithharper.com/docs/contributors/environment Display all available commands defined in the project's justfile. ```bash just --list ``` -------------------------------- ### Build and run Harper via Docker Source: https://writewithharper.com/docs/contributors/review Build the project from a specific branch and run the documentation demo in a local Docker container. ```bash git clone https://github.com/automattic/harper cd harper git switch IMAGE_HASH=$(docker build . -q) docker run -p 3000:3000 -it $IMAGE_HASH ``` -------------------------------- ### WorkerLinter.setup() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.workerlinter.setup.html Initializes the WorkerLinter. This method should be called before using other WorkerLinter functionalities. ```APIDOC ## WorkerLinter.setup() ### Description Initializes the WorkerLinter. This method should be called before using other WorkerLinter functionalities. ### Method POST ### Endpoint /websites/writewithharper/WorkerLinter/setup ### Request Body This method does not accept a request body. ### Response #### Success Response (200) - **void** - Indicates successful setup. #### Response Example (No response body is returned on success) ``` -------------------------------- ### BinaryModule.create() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.create.html Loads a binary from a specified URL. This is the only recommended way to construct this type. ```APIDOC ## BinaryModule.create() ### Description Loads a binary from a specified URL. This is the only recommended way to construct this type. ### Method Static ### Endpoint N/A (Static method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example usage (assuming BinaryModule is imported and available) // const binaryData = await BinaryModule.create('https://example.com/path/to/binary'); ``` ### Response #### Success Response (200) - **BinaryModule** (object) - The constructed BinaryModule instance. #### Response Example ```json { "message": "BinaryModule created successfully" } ``` ``` -------------------------------- ### Initialize and run Harper.js in Node.js Source: https://writewithharper.com/docs/harperjs/node Demonstrates importing the library and using LocalLinter to process text for grammar suggestions. Requires a Node.js version that supports ECMAScript modules. ```javascript async function main() { const harper = await import('harper.js'); // We cannot use `WorkerLinter` on Node.js since it relies on web-specific APIs. // This constructs the linter to consume American English. const linter = new harper.LocalLinter({ binary: harper.binary, dialect: harper.Dialect.American, }); const lints = await linter.lint('This is a example of how to use `harper.js`.'); console.log('Here are the results of linting the above text:'); for (const lint of lints) { console.log(' - ', lint.span().start, ':', lint.span().end, lint.message()); if (lint.suggestion_count() !== 0) { console.log('Suggestions:'); for (const sug of lint.suggestions()) { console.log( '\t - ', sug.kind() === 1 ? 'Remove' : 'Replace with', sug.get_replacement_text(), ); } } } } main(); ``` -------------------------------- ### Create BinaryModule Instance Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.html Use the static `create` method to load a binary from a specified URL. This is the recommended way to construct a BinaryModule instance. ```typescript create(url) ``` -------------------------------- ### GET /WorkerLinter/getDefaultLintConfigAsJSON Source: https://writewithharper.com/docs/harperjs/ref/harper.js.workerlinter.getdefaultlintconfigasjson.html Retrieves the default linting configuration for the WorkerLinter as a JSON-formatted string. ```APIDOC ## GET /WorkerLinter/getDefaultLintConfigAsJSON ### Description Retrieves the default linting configuration for the WorkerLinter as a JSON-formatted string. ### Method GET ### Endpoint /WorkerLinter/getDefaultLintConfigAsJSON ### Response #### Success Response (200) - **config** (string) - A JSON string representing the default linting configuration. #### Response Example "{\"rules\": {\"no-unused-vars\": \"error\"}}" ``` -------------------------------- ### Span.new() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.span.new.html Creates a new Span object with specified start and end points. ```APIDOC ## Span.new() ### Description Creates a new Span object. ### Method static new ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters - **start** (number) - Required - The starting position of the span. - **end** (number) - Required - The ending position of the span. ### Request Example None ### Response #### Success Response (200) - **Span** (Span) - A new Span object. #### Response Example None ``` -------------------------------- ### Configure harper-ls settings Source: https://writewithharper.com/docs/integrations/neovim Advanced configuration for linters, code actions, and file settings using default values. ```lua require('lspconfig').harper_ls.setup { settings = { ["harper-ls"] = { userDictPath = "", workspaceDictPath = "", fileDictPath = "", linters = { SpellCheck = true, SpelledNumbers = false, AnA = true, SentenceCapitalization = true, UnclosedQuotes = true, WrongQuotes = false, LongSentences = true, RepeatedWords = true, Spaces = true, Matcher = true, CorrectNumberSuffix = true }, codeActions = { ForceStable = false }, markdown = { IgnoreLinkTitle = false }, diagnosticSeverity = "hint", isolateEnglish = false, dialect = "American", maxFileLength = 120000, ignoredLintsPath = "", excludePatterns = {} } } } ``` -------------------------------- ### Get replacement text signature Source: https://writewithharper.com/docs/harperjs/ref/harper.js.suggestion.get_replacement_text.html Defines the method signature for retrieving replacement text. ```typescript get_replacement_text(): string; ``` -------------------------------- ### Get default linter configuration Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getdefaultlintconfig.html Returns a promise that resolves to the default LintConfig object. ```typescript getDefaultLintConfig(): Promise; ``` -------------------------------- ### Configure harper-ls settings Source: https://writewithharper.com/docs/integrations/helix Define default configuration values for linters, code actions, and markdown settings. ```toml [language-server.harper-ls.config.harper-ls] userDictPath = "" workspaceDictPath = "" fileDictPath = "" diagnosticSeverity = "hint" isolateEnglish = false dialect = "American" maxFileLength = 120000 ignoredLintsPath = "" excludePatterns = [] [language-server.harper-ls.config.harper-ls.linters] SpellCheck = true SpelledNumbers = false AnA = true SentenceCapitalization = true UnclosedQuotes = true WrongQuotes = false LongSentences = true RepeatedWords = true Spaces = true Matcher = true CorrectNumberSuffix = true [language-server.harper-ls.config.harper-ls.codeActions] ForceStable = false [language-server.harper-ls.config.harper-ls.markdown] IgnoreLinkTitle = false ``` -------------------------------- ### WorkerLinter.summarizeStats() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.workerlinter.summarizestats.html Retrieves statistical data within a specified range. Both start and end parameters are optional. ```APIDOC ## WorkerLinter.summarizeStats() ### Description Retrieves statistical data within a specified range. Both start and end parameters are optional. ### Method (Not explicitly specified, but implied to be a method call) ### Endpoint (Not applicable for this method) ### Parameters #### Query Parameters - **start** (bigint) - Optional - The starting point for the statistical data retrieval. - **end** (bigint) - Optional - The ending point for the statistical data retrieval. ### Request Example (Not applicable for this method) ### Response #### Success Response (200) - **Promise** - A promise that resolves with the statistical data. #### Response Example (Not provided in the source text) ``` -------------------------------- ### LocalLinter.summarizeStats() Signature Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.summarizestats.html This is the signature for the summarizeStats method. It can be called with optional start and end bigint parameters. ```typescript summarizeStats(start?: bigint, end?: bigint): Promise; ``` -------------------------------- ### Compile Harper-LS Source: https://writewithharper.com/docs/contributors/author-a-rule Recompile the language server binary after making changes to the Rust code. ```bash cargo build --release # Run in the monorepo to compile `harper-ls`. ``` -------------------------------- ### BinaryModule.getDefaultLintConfig() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.getdefaultlintconfig.html Retrieves the default lint configuration for the project. ```APIDOC ## BinaryModule.getDefaultLintConfig() ### Description Retrieves the default lint configuration. ### Method GET ### Endpoint /websites/writewithharper/harper.js/BinaryModule/getDefaultLintConfig ### Returns Promise ### Response Example { "example": "LintConfig object" } ``` -------------------------------- ### packWeirpackFiles() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.packweirpackfiles.html Converts a Weirpack file system into a real Weirpack binary by compressing and serializing them into a byte array. ```APIDOC ## packWeirpackFiles() ### Description Convert a Weirpack file system into a real Weirpack binary by compressing and serializing them into a byte array. ### Parameters #### Path Parameters - **files** (Map) - Required - A map representing the Weirpack file system. ### Returns - **Uint8Array** - The serialized Weirpack binary. ``` -------------------------------- ### Create a new Span instance Source: https://writewithharper.com/docs/harperjs/ref/harper.js.span.new.html Initializes a new Span object using start and end coordinates. ```typescript static new(start: number, end: number): Span; ``` -------------------------------- ### Define Span structure in Rust Source: https://writewithharper.com/docs/harperjs/spans The internal representation of a span as a struct containing start and end indices. ```rust struct Span { start: usize, end: usize } ``` -------------------------------- ### Linter.summarizeStats() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.summarizestats.html Summarizes the linter's usage statistics. Optionally filters data by start and end times. ```APIDOC ## Linter.summarizeStats() ### Description Summarize the linter's usage statistics. You may optionally pass in a start and/or end time. If so, the summary with only include data from _after_ the start time but _before_ the end time. ### Method N/A (This is a method call, not a REST endpoint) ### Endpoint N/A ### Parameters #### Query Parameters - **start** (bigint) - Optional - The start time for filtering statistics. - **end** (bigint) - Optional - The end time for filtering statistics. ### Request Example ```javascript // Example of calling the method (actual implementation details may vary) const summary = await linter.summarizeStats(1678886400000n, 1678972800000n); ``` ### Response #### Success Response (200) - **Summary** (object) - An object containing the linter's usage statistics. #### Response Example ```json { "totalRequests": 150, "uniqueUsers": 75, "averageResponseTime": 50.5 } ``` ``` -------------------------------- ### Configure Eglot for text-mode Source: https://writewithharper.com/docs/integrations/emacs Register harper-ls as the language server for text-mode in your init.el. ```elisp (with-eval-after-load 'eglot (add-to-list 'eglot-server-programs '(text-mode . ("harper-ls" "--stdio")))) ``` -------------------------------- ### Load Weirpacks via CLI Source: https://writewithharper.com/docs/weir Command to lint files using a specific Weirpack. ```bash harper-cli lint --weirpack path/to/rules.weirpack README.md ``` -------------------------------- ### Get Dialect using LocalLinter.getDialect() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.getdialect.html Call this method to retrieve the Dialect object. It returns a Promise that resolves to the Dialect. ```javascript getDialect(): Promise; ``` -------------------------------- ### Get Linter Dialect Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.setdialect.html Use this method to retrieve the English dialect the linter was constructed for. It returns a Promise that resolves to void. ```typescript setDialect(dialect: Dialect): Promise; ``` -------------------------------- ### Set Default Workspace Configuration Source: https://writewithharper.com/docs/integrations/emacs Define default linter settings and workspace behavior for harper-ls. ```elisp (setq-default eglot-workspace-configuration '(:harper-ls (:userDictPath "" :workspaceDictPath "" :fileDictPath "" :linters (:SpellCheck t :SpelledNumbers :json-false :AnA t :SentenceCapitalization t :UnclosedQuotes t :WrongQuotes :json-false :LongSentences t :RepeatedWords t :Spaces t :Matcher t :CorrectNumberSuffix t) :codeActions (:ForceStable :json-false) :markdown (:IgnoreLinkTitle :json-false) :diagnosticSeverity "hint" :isolateEnglish :json-false :dialect "American" :maxFileLength 120000 :ignoredLintsPath "" :excludePatterns []))) ``` -------------------------------- ### Alternative Pattern for Brand Rebranding Source: https://writewithharper.com/docs/weir A more readable alternative for defining patterns, explicitly listing each variation. This is semantically equivalent to the previous example. ```Weir [(G Suite), (G Suit), (Google Apps for Work)] ``` -------------------------------- ### LocalLinter.getLintDescriptionsHTMLAsJSON() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.getlintdescriptionshtmlasjson.html Retrieves linting descriptions in HTML format as a JSON string. ```APIDOC ## LocalLinter.getLintDescriptionsHTMLAsJSON() ### Description This method retrieves linting descriptions and returns them as an HTML string embedded within a JSON object. ### Method ``` getLintDescriptionsHTMLAsJSON(): Promise; ``` ### Returns - Promise: A promise that resolves to a JSON string containing the HTML lint descriptions. ``` -------------------------------- ### LinterInit.binary Property Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linterinit.binary.html Defines the module or path to the WebAssembly binary used by the linter. ```APIDOC ## LinterInit.binary ### Description The binary property specifies the module or file path to the WebAssembly binary required for the linter initialization. ### Signature `binary: BinaryModule;` ``` -------------------------------- ### Get Replacement Text for Suggestion Source: https://writewithharper.com/docs/harperjs/ref/harper.js.suggestion.html Retrieves the text that will replace the problematic section. Returns an empty string if the suggestion kind is 'Remove'. ```typescript get_replacement_text() ``` -------------------------------- ### LocalLinter.applySuggestion() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.applysuggestion.html Applies a given suggestion to the provided text using the LocalLinter. ```APIDOC ## LocalLinter.applySuggestion() ### Description Applies a specific linting suggestion to a given text. ### Method Asynchronous function (Promise) ### Endpoint N/A (This is a method within a JavaScript library, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **text** (string) - Required - The input text to which the suggestion will be applied. - **lint** (Lint) - Required - The lint object associated with the text. - **suggestion** (Suggestion) - Required - The specific suggestion to apply. ### Request Example ```javascript // Assuming you have initialized LocalLinter, text, lint, and suggestion objects const updatedText = await localLinter.applySuggestion(text, lint, suggestion); ``` ### Response #### Success Response (Promise) - **string** - The text after the suggestion has been applied. #### Response Example ```json "Updated text content after applying the suggestion." ``` ``` -------------------------------- ### Get Lint Descriptions as JSON Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getlintdescriptionsasjson.html Call this method to retrieve all linting rule descriptions as a JSON map. The output is formatted in Markdown. ```javascript getLintDescriptionsAsJSON(): Promise; ``` -------------------------------- ### Linter.getLintDescriptions() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getlintdescriptions.html Retrieves all linting rule descriptions as a Markdown-formatted object. ```APIDOC ## Linter.getLintDescriptions() ### Description Get the linting rule descriptions as an object, formatted in Markdown. ### Method GET ### Endpoint /linter/lintDescriptions ### Returns Promise> - An object where keys are rule names and values are their Markdown descriptions. ``` -------------------------------- ### Get Linter Dialect Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getdialect.html Call this method to retrieve the configured English dialect for the linter. It returns a Promise that resolves to a Dialect object. ```javascript getDialect(): Promise; ``` -------------------------------- ### LocalLinter.getLintDescriptionsAsJSON() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.getlintdescriptionsasjson.html This method returns a Promise that resolves to a JSON string containing linting descriptions. ```APIDOC ## LocalLinter.getLintDescriptionsAsJSON() ### Description Retrieves linting descriptions in JSON format. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters This method does not accept any parameters. ### Request Example N/A ### Response #### Success Response - **Promise** - A Promise that resolves to a JSON string representing linting descriptions. #### Response Example ```json "{\"lintDescriptions\": [{\"rule\": \"exampleRule\", \"message\": \"This is an example lint message.\"}]}" ``` ``` -------------------------------- ### Linter.getLintDescriptionsHTML() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.getlintdescriptionshtml.html Retrieves linting rule descriptions formatted in HTML. This method wraps the BinaryModule function of the same name. ```APIDOC ## Linter.getLintDescriptionsHTML() ### Description Get the linting rule descriptions as an object, formatted in HTML. Wraps the function on the BinaryModule by the same name. ### Method GET ### Endpoint /linter/descriptions/html ### Returns Promise> - An object where keys are rule names and values are HTML-formatted descriptions. ``` -------------------------------- ### Basic harper-ls Configuration Structure Source: https://writewithharper.com/docs/integrations/language-server The main configuration for harper-ls is expected within a JSON object under the 'harper-ls' key. This serves as the root for all other settings. ```json { "harper-ls": { // Your config goes here... } } ``` -------------------------------- ### Simplified Phrase Rule in Weir Source: https://writewithharper.com/docs/weir A simplified way to define a phrase rule where the top-level expression is implicitly a sequence. This is equivalent to the previous 'gong to' example. ```Weir expr main gong to ``` -------------------------------- ### LocalLinter.loadWeirpackFromBlob() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.loadweirpackfromblob.html Loads a Weirpack from a provided Blob and returns test failures if validation fails. ```APIDOC ## LocalLinter.loadWeirpackFromBlob() ### Description Load a Weirpack from a Blob. Returns undefined if tests pass and rules are imported, otherwise returns the Weirpack test failures. ### Parameters #### Path Parameters - **blob** (Blob) - Required - The Blob object containing the Weirpack data. ### Response - **Returns** (Promise) - A promise that resolves to the Weirpack test failures or undefined if successful. ``` -------------------------------- ### Weir Comment Syntax Source: https://writewithharper.com/docs/weir Comments in Weir are denoted by a single pound sign (#) and are ignored by the parser. This example shows a comment preceding a pattern definition. ```Weir # This is a comment and has no effect on the rest of the file. [(G Suite), (G Suit), (Google Apps for Work)] ``` -------------------------------- ### LocalLinter.getLintConfig() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.getlintconfig.html Retrieves the current linting configuration as a promise. ```APIDOC ## LocalLinter.getLintConfig() ### Description Retrieves the linting configuration for the local environment. ### Method GET ### Returns - **Promise** - A promise that resolves to the LintConfig object. ``` -------------------------------- ### LocalLinter.getLintDescriptionsHTML() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.getlintdescriptionshtml.html Retrieves HTML-formatted descriptions for lints. ```APIDOC ## LocalLinter.getLintDescriptionsHTML() ### Description Retrieves HTML-formatted descriptions for lints. ### Method N/A (This is a method call, not a REST endpoint) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response (Promise>) - **lintDescriptions** (Record) - An object where keys are lint names and values are their HTML descriptions. #### Response Example ```json { "indentation": "

Use consistent indentation.

", "line-length": "

Keep lines under 80 characters.

" } ``` ``` -------------------------------- ### Get Lint Suggestions Source: https://writewithharper.com/docs/harperjs/ref/harper.js.lint.suggestions.html Call the suggestions() method on a lint object to retrieve an array of suggestions for resolving issues. The method returns an array of Suggestion objects. ```javascript suggestions(): Suggestion[]; ``` -------------------------------- ### Run VS Code Extension Tests via Command Line Source: https://writewithharper.com/docs/contributors/visual-studio-code Execute the VS Code extension tests using the `just test-vscode` command. This is the recommended method for running tests. ```bash just test-vscode ``` -------------------------------- ### Add Noun to Dictionary Source: https://writewithharper.com/docs/contributors/dictionary Use this command-line tool to add new nouns to the Harper dictionary. Ensure you have followed the setup documentation for contributors before running this command. ```bash just addnoun ``` -------------------------------- ### Lint Class Methods Source: https://writewithharper.com/docs/harperjs/ref/harper.js.lint.html This section details the various methods available for the Lint class, including static methods for initialization and instance methods for retrieving linting details. ```APIDOC ## Lint Class **Signature:** ``` export declare class Lint ``` ### Methods #### `free()` - **Description**: Frees associated resources. #### `static from_json(json)` - **Description**: Creates a Lint instance from a JSON object. - **Parameters**: - `json` (object) - The JSON object to parse. #### `get_problem_text()` - **Description**: Get the content of the source material pointed to by [`Self::span`]. - **Returns**: (string) The problematic text content. #### `lint_kind_pretty()` - **Description**: Get a string representing the general category of the lint. - **Returns**: (string) A pretty-printed lint kind. #### `lint_kind()` - **Description**: Get a string representing the general category of the lint. - **Returns**: (string) The lint kind. #### `message_html()` - **Description**: Get a description of the error as HTML. - **Returns**: (string) The HTML formatted error message. #### `message()` - **Description**: Get a description of the error. - **Returns**: (string) The error message. #### `span()` - **Description**: Get the location of the problematic text. - **Returns**: (object) An object representing the location (e.g., start and end positions). #### `suggestion_count()` - **Description**: Equivalent to calling `.length` on the result of `suggestions()`. - **Returns**: (number) The number of suggestions available. #### `suggestions()` - **Description**: Get an array of any suggestions that may resolve the issue. - **Returns**: (array) An array of suggestion strings. #### `to_json()` - **Description**: Converts the Lint instance to a JSON object. - **Returns**: (object) The JSON representation of the Lint instance. #### `[Symbol.dispose]()` - **Description**: Disposes of the Lint instance and frees resources. This method is part of the disposable pattern. ``` -------------------------------- ### Convert Lint Object to JSON String Source: https://writewithharper.com/docs/harperjs/ref/harper.js.lint.to_json.html Use this method to get a string representation of the lint object. This is useful for debugging or when you need to pass linting results to other systems. ```typescript to_json(): string; ``` -------------------------------- ### Summarize Linter Statistics Source: https://writewithharper.com/docs/harperjs/linting Generates a summary of the linter's usage statistics. Optionally, you can provide start and end timestamps to filter the data within a specific range. ```typescript summarizeStats(start?: bigint, end?: bigint): Promise; ``` -------------------------------- ### POST /LocalLinter/loadWeirpackFromBytes Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.loadweirpackfrombytes.html Loads a Weirpack from a provided byte array and returns test failures if validation fails. ```APIDOC ## POST /LocalLinter/loadWeirpackFromBytes ### Description Load a Weirpack from a byte array. Returns undefined if tests pass and rules are imported, otherwise returns the Weirpack test failures. ### Method POST ### Endpoint /LocalLinter/loadWeirpackFromBytes ### Parameters #### Request Body - **bytes** (Uint8Array | number[]) - Required - The byte array containing the Weirpack data. ### Response #### Success Response (200) - **result** (WeirpackTestFailures | undefined) - Returns undefined if successful, or WeirpackTestFailures if validation fails. ``` -------------------------------- ### binary variable Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binary.html Accessing the Harper WebAssembly binary module. ```APIDOC ## binary ### Description A version of the Harper WebAssembly binary stored inline as a data URL. This variable is designed to be tree-shaken if it remains unused in the final bundle. ### Signature `binary: BinaryModule` ``` -------------------------------- ### BinaryModule Class API Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.html Documentation for the BinaryModule class, including its properties and methods for managing the WebAssembly core. ```APIDOC ## BinaryModule Class ### Description A wrapper around the underlying WebAssembly module that contains Harper's core code. Used to construct a Linter, as well as access some miscellaneous other functions. ### Properties - **url** (string) - The URL of the binary. ### Methods - **create(url)** (static) - Load a binary from a specified URL. This is the only recommended way to construct this type. - **getDefaultLintConfig()** - Retrieves the default lint configuration. - **getDefaultLintConfigAsJSON()** - Retrieves the default lint configuration as a JSON object. - **setup()** - Initializes the module. - **toTitleCase(text)** - Converts the provided text to title case. ``` -------------------------------- ### LocalLinter.getLintDescriptions() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.getlintdescriptions.html Retrieves a mapping of linting rule identifiers to their human-readable descriptions. ```APIDOC ## GET /LocalLinter/getLintDescriptions ### Description Retrieves a collection of linting rule descriptions as a key-value pair object. ### Method GET ### Endpoint LocalLinter.getLintDescriptions() ### Response #### Success Response (200) - **Record** (object) - A dictionary where keys are lint rule identifiers and values are their corresponding descriptions. #### Response Example { "no-unused-vars": "Disallow unused variables", "eqeqeq": "Require the use of === and !==" } ``` -------------------------------- ### BinaryModule.toTitleCase() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.binarymodule.totitlecase.html Converts a string to title case using the BinaryModule. ```APIDOC ## BinaryModule.toTitleCase() ### Description Converts the provided input string into title case format. This method returns a Promise that resolves to the formatted string. ### Parameters #### Request Body - **text** (string) - Required - The string to be converted to title case. ### Response #### Success Response (200) - **result** (string) - The title-cased version of the input string. ``` -------------------------------- ### Linter.loadWeirpackFromBytes() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.loadweirpackfrombytes.html Loads a Weirpack from an array of bytes, merging its rules into the current linter. Returns the same failure report structure as `loadWeirpackFromBlob`. ```APIDOC ## Linter.loadWeirpackFromBytes() ### Description Load a Weirpack from an array of bytes, merging its rules into the current linter. Returns the same failure report structure as `loadWeirpackFromBlob`. ### Method Not specified (likely a static or instance method) ### Endpoint Not applicable (this is a method call, not an HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example usage (assuming 'linter' is an instance of Linter) const bytes = new Uint8Array([1, 2, 3, 4, 5]); linter.loadWeirpackFromBytes(bytes) .then(failures => { console.log(failures); }); ``` ### Response #### Success Response (Promise resolves with) - **result** (WeirpackTestFailures | undefined) - The failure report structure. #### Response Example ```json { "example": "WeirpackTestFailures object or undefined" } ``` ``` -------------------------------- ### Linter.setLintConfigWithJSON() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.setlintconfigwithjson.html Configures the linter settings by passing a JSON-formatted string. ```APIDOC ## Linter.setLintConfigWithJSON() ### Description Sets the linter's current configuration from a provided JSON string. ### Method POST ### Parameters #### Request Body - **config** (string) - Required - A JSON string representing the linter configuration. ### Response #### Success Response (200) - **void** - Returns a Promise that resolves when the configuration is successfully set. ``` -------------------------------- ### LocalLinter Class Methods Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.html Overview of the primary methods available in the LocalLinter class for linting and configuration. ```APIDOC ## LocalLinter.lint(text, options) ### Description Performs linting on the provided text based on the current configuration. ### Parameters - **text** (string) - Required - The text content to be linted. - **options** (object) - Optional - Configuration options for the linting process. ## LocalLinter.loadWeirpackFromBlob(blob) ### Description Loads a Weirpack from a Blob. Returns undefined if tests pass and rules are imported, otherwise returns the Weirpack test failures. ### Parameters - **blob** (Blob) - Required - The blob containing the Weirpack data. ## LocalLinter.loadWeirpackFromBytes(bytes) ### Description Load a Weirpack from a byte array. Returns undefined if tests pass and rules are imported, otherwise returns the Weirpack test failures. ### Parameters - **bytes** (Uint8Array) - Required - The byte array containing the Weirpack data. ## LocalLinter.setLintConfig(config) ### Description Updates the linting configuration for the current instance. ### Parameters - **config** (object) - Required - The configuration object to apply. ``` -------------------------------- ### Linter.loadWeirpackFromBlob() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.linter.loadweirpackfromblob.html Loads a Weirpack from a Blob, merging its rules into the current linter. It returns `undefined` if the Weirpack tests pass and rules are imported successfully. Otherwise, it returns a map of rule names to failing tests. ```APIDOC ## Linter.loadWeirpackFromBlob() ### Description Load a Weirpack from a Blob, merging its rules into the current linter. Returns `undefined` when the Weirpack tests pass and the rules are imported, otherwise returns a map of rule names → failing tests so the caller can surface the broken expectations. ### Method Asynchronous method, likely POST or PUT depending on context, but not explicitly defined. ### Endpoint Not explicitly defined, assumed to be part of a Linter API. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "blob": "[Blob object representing the Weirpack]" } ``` ### Response #### Success Response (200) - **WeirpackTestFailures | undefined** (Promise) - Returns `undefined` if tests pass and rules are imported, otherwise returns a map of rule names to failing tests. #### Response Example ```json // If tests pass: undefined // If tests fail: { "ruleName1": ["testFailure1", "testFailure2"], "ruleName2": ["testFailure3"] } ``` ``` -------------------------------- ### WorkerLinter.getLintDescriptionsHTML() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.workerlinter.getlintdescriptionshtml.html Retrieves linting descriptions as an HTML string. This method is asynchronous and returns a Promise. ```APIDOC ## WorkerLinter.getLintDescriptionsHTML() ### Description Retrieves linting descriptions in HTML format. This method is part of the WorkerLinter class and is designed to be called asynchronously. ### Method N/A (This is a method call, not a direct HTTP request) ### Endpoint N/A (This is a method call within a JavaScript environment) ### Parameters This method does not accept any parameters. ### Request Example ```javascript // Assuming 'workerLinter' is an instance of WorkerLinter workerLinter.getLintDescriptionsHTML().then(descriptions => { console.log(descriptions); }); ``` ### Response #### Success Response - **descriptions** (Promise>) - A Promise that resolves to an object where keys are lint rule identifiers and values are their corresponding HTML descriptions. ``` -------------------------------- ### Configure harper-ls in LSP.sublime-settings Source: https://writewithharper.com/docs/integrations/sublime-text Add this configuration to the clients section of your LSP settings to enable Harper in Sublime Text. Ensure harper-ls is available in your system PATH. ```json { "clients": { "harper-ls": { "enabled": true, "command": [ "harper-ls", "--stdio" ], "selector": "source.markdown | text.html.markdown | text.plain", "settings": { "harper-ls": { "userDictPath": "", "workspaceDictPath": "", "fileDictPath": "", "linters": { "SpellCheck": true, "SpelledNumbers": false, "AnA": true, "SentenceCapitalization": true, "UnclosedQuotes": true, "WrongQuotes": false, "LongSentences": true, "RepeatedWords": true, "Spaces": true, "Matcher": true, "CorrectNumberSuffix": true }, "codeActions": { "ForceStable": false }, "markdown": { "IgnoreLinkTitle": false }, "diagnosticSeverity": "hint", "isolateEnglish": false, "dialect": "American", "maxFileLength": 120000, "ignoredLintsPath": "", "excludePatterns": [] } } } } } ``` -------------------------------- ### LocalLinter.setLintConfigWithJSON() Source: https://writewithharper.com/docs/harperjs/ref/harper.js.locallinter.setlintconfigwithjson.html Configures the linter settings using a provided JSON string. ```APIDOC ## LocalLinter.setLintConfigWithJSON() ### Description Sets the linting configuration for the LocalLinter instance using a JSON-formatted string. ### Parameters #### Parameters - **config** (string) - Required - A JSON string containing the linting configuration. ### Returns - **Promise** - A promise that resolves when the configuration has been set. ```