Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

memelint

memelint lints the memes of a project: the words that spread through comments, docstrings, and documentation. It tells you which words and sentences do not follow Simplified Technical English (ASD-STE100), with an allowlist for the vocabulary of your project.

Each finding gives the file, the position, the severity, the message and the rule:

$ memelint check
foo.py:2:29: error: 'ensure' is not approved; use 'make sure' [STE 1.1]
foo.py:3:7: error: 'don't' is a contraction; write the words in full [STE 4.2]
foo.py:3:13: error: 'delve' is not in the STE dictionary; if it is a technical name, add it to memelint.toml [STE 1.6]
foo.py:4:7: error: sentence has 28 words; the STE limit for descriptive text is 25 [STE 6.3]
foo.py:4:7: error: 'closing' is the -ing form of 'close'; STE allows only the infinitive, imperative, past tense and past participle [STE 3.5]

The exit code is 1 when there is an error.

memelint check --fix writes safe fixes automatically: each contraction becomes the words in full. --unsafe-fixes also replaces each unapproved word with the one alternative of the same part of speech; examine the diff.

Installation

ASD-STE100 is copyrighted, thus the binary does not contain its dictionary. The first run downloads the PDF from ASD and makes the vocabulary in ~/.cache/memelint/. The Nix package makes it when it builds.

On your machine

Use the install script, or use Nix.

The install script

The release binaries are for Linux and macOS, on x86_64 and aarch64:

curl -fsSL https://memelint.sh | sh
memelint check

Nix

With Nix, there is no installation. This builds the checker with the vocabulary and with each tree-sitter grammar that nixpkgs has, and runs it:

$(nix-build --no-out-link \
  https://github.com/antimemes/memelint/archive/main.tar.gz)\
/bin/memelint check

With flakes:

nix run github:antimemes/memelint -- check

In GitHub Actions

Put this in .github/workflows/memelint.yml. The findings become annotations on the pull request:

name: memelint

on:
  push:
    branches: [main]
  pull_request:

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: antimemes/memelint@latest

memelint is a project of the Antimemetics Institute.

Configuration

memelint reads memelint.toml at the project root. Each key is optional. The first line gives your editor the schema:

#:schema https://raw.githubusercontent.com/antimemes/memelint/main/crates/memelint/memelint.schema.json

profile = "basic"                  # "basic" (the default) or "strict"
words = ["gantry", "sprocket"]
word-lists = ["words.txt", "https://example.com/team-words.txt"]
subtree-word-lists = ["experiments/*/memelint-words.txt"]
default-word-lists = true
ignore = ["vendor/", "*.generated.go"]
check = false                      # examine files (default: true for code, false for prose)

[rules]
"6.3" = "warning"                  # "error", "warning" or "off"

[languages.markdown]               # for the files of one language
check = true                       # examine these files (default: true for code, false for prose)
words = ["spread"]
word-lists = ["doc-words.txt"]
default-word-lists = true

[languages.markdown.rules]
"1.6" = "off"

[scopes.docs]                      # for the paths that `paths` names
paths = ["docs/"]                  # as in .gitignore, from the directory of memelint.toml
profile = "strict"
words = ["gantry"]
check = true                       # examine the files in these paths

[scopes.docs.rules]
"6.3" = "off"
KeyEffect
profilethe severity of each rule, see Rules
rulesthe severity of one rule
wordsthe technical names and verbs of the project, see Words
word-listsfiles, URLs and bundled lists of words
subtree-word-listsglobs of word files, each for the directory of the file and all directories below it; ignore does not apply to them, see Words
default-word-listsuse the bundled lists (default: true)
ignorepaths that memelint does not examine, in the syntax of .gitignore
checkexamine files (default: true for code, false for prose); true also examines prose
languages.<name>the same keys for the files of one language, see Languages
languages.<name>.checkexamine the files of one language (default: true for code, false for prose)
scopes.<name>the profile, rules and words of the paths that paths names, see Rules
scopes.<name>.checkexamine the files in these paths; this applies before the language and the top level

Markdown files are prose. memelint examines them only when [languages.markdown], a scope or the top level has check = true.

Words

The ASD-STE100 dictionary has approximately 900 words. The technical names and technical verbs of your domain are not in it, and the standard lets you use them. Tell memelint which they are:

  • words: a list in memelint.toml.
  • word-lists: files with one entry on each line and # comments. An entry is a path from the directory of memelint.toml, a URL, or the name of a bundled list.

An entry is one word, or a phrase of 2 or 3 words, for example base URL. The words of a phrase are accepted only together: base without URL is examined as before. The last word of a phrase can have an inflection.

  • default-word-lists: the bundled lists are on unless this is false. The software list applies to all files, and the list of a language to its files.

The entries add to each other. memelint accepts a listed word with its plural and its -s and -ed forms. It does not accept the -ing form: STE does not let you use the -ing form of a verb (rule 3.5). A technical name that ends in -ing, for example landing, goes in the list as a word.

memelint fetch downloads the URLs into ~/.cache/memelint/words/, and memelint check reads them from there.

The bundled lists are software, c, cpp, go, java, javascript, markdown, nix, python, rust, toml, tsx and typescript. Their text is in the repository. They are not complete. If you add words, send a pull request.

To use only your lists:

default-word-lists = false
word-lists = ["words.txt"]

The test for a bundled list

A bundled list applies to all projects of a language, and the software list to all projects. Thus a word goes into a bundled list when it is correct in these points for a person who does not know the project:

  1. The word names one specified item, and it is the most accurate word for that item. artifact, helper and context are not correct. The sentence is better with the accurate word, for example “the log file” and not “the artifact”.
  2. The meaning comes from the language, its standard library, the system, the tools, or the general vocabulary of software. Not from one library, framework or domain. schema, model and session are not correct. Each library that a project uses gives the word a different meaning, and only the project knows its libraries.
  3. In the comments of that language, most uses of the word have that one meaning. The other meanings are easy to see from the spelling, or from the subsequent word. path is correct: “file path” and “URL path” are far apart, and the sentence shows which one applies. node is correct: the runtime is written Node.js. tag is not correct. In comments it is a git tag, a markup tag, a struct tag and a build tag, with no mark that shows which.
  4. ASD-STE100 has no approved word for that item, and the word is not an approved word. If it is, the list does not get the word.

Write the meaning after the word as a comment. Then the person who examines the pull request sees the meaning on the same line, and sees a different meaning immediately:

sentinel      # a value that marks an end or an absence
node          # a point of a tree, a graph or a document; the runtime is Node.js

We examined these points against 566,000 comments of Python, Rust, Go and JavaScript projects. The words that a person reads incorrectly are the words of point 1 and point 2. These are words that many different items can be, for example schema, session and resource. Each library fills them with a different item. Words with meanings that are far apart, for example key, path and union, a person reads correctly.

A word that is not correct in one point can be a technical name in one project. Put it in the words of that project, not in a bundled list.

The meaning is for the person who examines the list. memelint checks words, not meanings: a listed word is accepted in each sentence that has it.

Words of one directory

In a repository with many packages, each directory can have its words. Name the files with a glob:

subtree-word-lists = ["experiments/*/memelint-words.txt"]

An example file, experiments/rotor-sim/memelint-words.txt:

# words of the rotor simulation
flywheel
torque-ramp
swashplate

The words of a file apply to the directory of the file and to all directories below it. memelint reads the files from the directories below memelint.toml: ignore and .gitignore do not apply to them. A glob with * or ** can find no file; that is not an error, and a note names the glob. A path without * or ** must be a file, as with word-lists. A path that ends with / is an error: the key names files, not directories. You select the file name: memelint has no default name, and it reads only the files you name.

A scope, [scopes.<name>], also has words and word-lists, for the paths it names (see Rules).

Words of one run

A program that writes text can check it with words that it knows only at run time. --word-list <file> adds the words of a file to each file of the run. The file has one word on each line and # comments, and its path starts at the directory in which memelint runs. Give the option one time for each list:

$ memelint check --word-list papers/toy/words.txt papers/toy/report

Rules

ASD-STE100 Issue 9 has 53 rules. A program can check a part of them. memelint checks these:

RuleFinding
1.1a word that is not approved, with the approved alternatives, for example commence (use start)
1.2an approved word in a part of speech in which it is not approved. For example, test is a noun, thus “do a test” and not “test it”
1.6a word that is not in the dictionary and not in your word list, for example kubelet. Put the words of your project in memelint.toml, and they are approved
3.5the -ing form of an approved verb, for example starting
4.2a contraction, for example don't
6.3a sentence of more than 25 words

Each rule has a severity: error, warning or off. The exit code is 1 when there is an error. The profile sets the severity of each rule:

ProfileEffect
basic (the default)1.1 and 1.6 are off, 6.3 is a warning
stricteach finding is an error

The basic profile checks the form of the writing, and no word list is necessary. The strict profile also checks the vocabulary, with the word list of the project.

[rules] changes one rule, and [languages.<name>.rules] changes it for the files of one language. The language value applies first, then [rules], then the profile:

profile = "strict"

[rules]
"4.2" = "off"

[languages.markdown.rules]
"1.6" = "off"

A scope names paths and gives them a profile and rules. Thus a project that is basic at the root can make docs/ strict:

[scopes.docs]
paths = ["docs/"]       # as in .gitignore, from the directory of memelint.toml
profile = "strict"

[scopes.docs.rules]
"6.3" = "off"

In these paths, the scope rules apply first, then [languages.<name>.rules], then [rules], then the scope profile, then the top-level profile. When two scopes name one file, the last of them in memelint.toml sets the severity, and the words of the two apply.

A scope with check = true or check = false turns memelint on or off in its paths. The check of the last scope applies first, then the check of the language, then the top-level check.

A rule that gives no findings cannot be set. memelint stops with an error message when it reads memelint.toml.

Languages

memelint lints each language that has a tree-sitter grammar. The grammar name is the key of [languages.<name>], for example rust, python, cpp or markdown.

Rust, Python, JavaScript, TypeScript, Go, C, Java, Nix, TOML and Markdown are compiled in. For each other language memelint loads <name>.so from a grammar directory, in this sequence:

  1. --grammars <dir>
  2. each directory in MEMELINT_GRAMMARS
  3. ~/.local/share/memelint/grammars

These are the grammar files that Neovim and nixpkgs make. The Nix package sets MEMELINT_GRAMMARS to all the grammars in nixpkgs. When a file has no grammar, memelint does not examine it, and gives a note at the end.

A [languages.<name>] table has the keys check, words, word-lists, default-word-lists and rules, for the files of that language.

Markdown files are prose. memelint reads their paragraphs, headings and table cells, and not their code blocks. When memelint walks a directory, it does not examine Markdown files, unless [languages.markdown], a scope that names them or the top level has check = true. It examines a file that you name on the command line, for example memelint check README.md.