# rule

`rule.py` checks a text file against one writing rule and reports every break the way a compiler reports a syntax error: `file:line:col: error:`, the source line, a caret under the word, `N errors generated.`, and exit status 1. The rule changes every day, drawn by the date from a fixed table, or is picked by name from 30. It is one file, Python 3.11 or newer, standard library only: from this folder, `uv run rule.py` prints today's rule and `uv run rule.py draft.txt` checks a file against it (`python3 rule.py` works the same). It takes any UTF-8 text you wrote, as a file or on standard input (`-`), and reads the local calendar date; a text that keeps the rule prints nothing at all.

## The command

    rule [--rule NAME] [--date YYYY-MM-DD] [--no-log] FILE      check FILE ("-" reads stdin)
    rule                                                        print today's rule
    rule [--date YYYY-MM-DD]                                    print the rule for a date
    rule --list                                                 the 30 named rules
    rule --explain NAME [--date YYYY-MM-DD]                     the exact definition of one rule
    rule --record                                               print the log and the tally
    rule --help

Here `rule` stands for `uv run rule.py`. To type `rule` instead, link the file onto your PATH; it is executable and its first line runs it with uv:

    ln -s "$PWD/rule.py" ~/.local/bin/rule

From this folder:

    uv run rule.py                            today's rule
    uv run rule.py draft.txt                  check draft.txt against it
    uv run rule.py --rule no-the draft.txt    check against a rule picked by name
    uv run python -m unittest -v              the tests
    uv run python qa/accept.py                the acceptance run (needs tmux and git)

For example, the sentence `We walked to the market.` saved as `draft.txt`, on a no-k day:

    draft.txt:1:7: error: "walked" contains "k" [no-k]
    We walked to the market.
          ^
    draft.txt:1:21: error: "market" contains "k" [no-k]
    We walked to the market.
                        ^
    2 errors generated.

Errors go to standard error. The rule line, `--list`, `--explain` and `--record` go to standard output. Exit status: 0 the text kept the rule, 1 it broke the rule, 2 the tool could not run (unreadable file, empty file, invalid UTF-8, unknown rule, bad date). There is no fix option, no ignore option, no suppression comment and no config file. The checked file is opened read-only and never written.

Colour appears only when standard error is a terminal and `NO_COLOR` is unset: the word `error:` and the underline in brick, `#EC5E52`. Nothing else is coloured.

## The calendar

The rule for a day is `ROTATION[days since 1970-01-01 % 24]`, on the local calendar date. The rotation holds 24 rules: 8 graded plain (a paragraph passes without noticing) and 16 graded effort (a paragraph passes if the writer pays attention). For the first 15 days of each 24-day cycle the two grades alternate, plain on indices 0, 2, 4, 6, 8, 10, 12 and 14. The last 9 days of every cycle, indices 15 to 23, are all effort.

The 6 hard rules are the Oulipo constraints that make prose close to unwritable. The date never draws them; they are picked by name only. `no-<letter>` is accepted for any letter a to z. `--date` gives the rule for any date and is never logged. With `--explain`, `--date` stands in for today.

Every daily rule is in the rotation because a written paragraph of at least 40 words of ordinary English keeps it; `test_rule.py` holds those paragraphs and checks each one.

## The 30 rules

This is the output of `uv run rule.py --list`. `uv run rule.py --explain NAME` prints the exact definition of each.

    Rotation table, revision 1. In force from 1970-01-01. 24 daily rules, 6 by name.

    R01  no-dash             plain   daily    -
         No em dash, en dash, horizontal bar, doubled hyphen or spaced hyphen used as a dash.
    R02  no-the              effort  daily    -
         The word "the" does not appear.
    R03  no-exclaim          plain   daily    -
         No exclamation mark.
    R04  no-k                effort  daily    -
         No word contains the letter "k".
    R05  short-sentences     plain   daily    -
         No sentence has more than 14 words.
    R06  no-first-person     effort  daily    -
         None of: i, me, my, mine, myself, i'm, i've, i'll, i'd.
    R07  no-numerals         plain   daily    -
         No digits; spell numbers out.
    R08  no-be               effort  daily    E-Prime, D. David Bourland Jr.
         No form of "to be".
    R09  no-contractions     plain   daily    -
         No word ending in n't, 'll, 're, 've, 'm or 'd, and no "let's".
    R10  no-w                effort  daily    -
         No word contains the letter "w".
    R11  no-same-opener      plain   daily    -
         No two consecutive sentences open with the same word.
    R12  short-words         effort  daily    -
         No word has more than 7 letters.
    R13  no-repeat-adjacent  plain   daily    -
         No word immediately repeats the word before it.
    R14  no-alliteration     effort  daily    -
         Two adjacent words in a sentence do not start with the same letter.
    R15  no-ly               plain   daily    -
         No word of three or more letters ends in "ly".
    R16  no-y                effort  daily    -
         No word contains the letter "y".
    R17  even-sentences      effort  daily    -
         Every sentence has an even number of words.
    R18  no-and              effort  daily    -
         Neither the word "and" nor "&".
    R19  no-v                effort  daily    -
         No word contains the letter "v".
    R20  no-repeat-sentence  effort  daily    -
         No word appears twice in one sentence.
    R21  no-b                effort  daily    -
         No word contains the letter "b".
    R22  no-same-length      effort  daily    -
         Two adjacent words in a sentence do not have the same number of letters.
    R23  no-g                effort  daily    -
         No word contains the letter "g".
    R24  no-repeated-word    effort  daily    -
         No word appears twice anywhere in the text.
    R25  no-e                hard    by name  Perec, La Disparition, 1969
         No word contains the letter "e".
    R26  no-a                hard    by name  Oulipo lipogram
         No word contains the letter "a".
    R27  no-t                hard    by name  Oulipo lipogram
         No word contains the letter "t".
    R28  snowball            hard    by name  Oulipo snowball
         In every sentence the word in position n has exactly n letters.
    R29  univocalic          hard    by name  Perec, Les Revenentes, 1972 (e only); Oulipo univocalism
         The whole text uses one vowel only.
    R30  prisoner            hard    by name  Oulipo prisoner's constraint
         Only letters without ascenders or descenders: a c e m n o r s u v w x z.

    no-<letter> is accepted for any letter a to z.

## How text is read

- The file is read as strict UTF-8; invalid bytes exit 2. A leading byte order mark is dropped. Each line is normalised to NFC, split on line feeds, with a trailing carriage return dropped.
- A word is a run of Unicode letters and combining marks, with an apostrophe (straight or curly) allowed between two letters. A hyphen, an underscore or a slash ends a word, so `well-known` is two words. A word keeps its own spelling when printed.
- A number is a run of decimal digits, in any script, with a single `.` or `,` allowed between two digits. Numbers are not words, so `b2b` is a word, a number and a word.
- The letters of a word, for the length rules, are its letters only: `don't` has 4, `naïve` has 5.
- Folding, for the letter rules and first letters: casefold, decompose, drop combining marks, then map ß to ss, æ to ae, œ to oe, ø to o, đ to d, ł to l and ı to i. So `é` counts as `e`, `ç` as `c`, `ğ` as `g`. Only the Latin letters a to z take part in letter rules.
- A sentence ends at a run of `.` `!` `?` `…` `。` `！` `？`, with closing quotes or brackets allowed after it, when whitespace or the end of the text follows. A blank line also ends a sentence; a line break alone does not. A period after `mr mrs ms dr prof st vs cf e.g i.e` or after a single letter (an initial) does not end one. Numbers and punctuation are not counted as words.
- Columns count Unicode code points of the normalised line, starting at 1. The caret line copies the source line's tabs as tabs, so the caret lines up in a terminal.
- All word comparisons ignore capitalisation. Every message quotes the broken word exactly as it was written.

## Limits

- Chinese, Japanese and Thai are written without spaces and are not segmented: a run of such text counts as one word. Right-to-left alignment and wide characters under the caret are not handled.
- `'s` is never flagged by no-be or no-contractions, because it may be a possessive.
- Sentence splitting knows a short, fixed list of abbreviations and nothing else.
- Markdown, code and commit comment lines are read as plain text.

## The log

Only a check of today's rule, with no `--rule` and no `--date`, is logged. One line is appended to `$RULE_LOG` if set, else `$XDG_STATE_HOME/rule-of-the-day/log`, else `~/.local/state/rule-of-the-day/log`: the date, the rule, the exit code, the word count and the break count, separated by single spaces. The file name and the text are never recorded. `--no-log` skips it, and a run that exits 2 is never logged. The log is append-only, so a broken run stays in the record after a later pass. `rule --record` prints it with a tally; a day counts as survived if any run that day exited 0.

## In git

Check the last commit message:

    git log -1 --format=%B | rule --rule no-dash -

As a `commit-msg` hook, saved as `.git/hooks/commit-msg` and made executable:

    #!/bin/sh
    exec rule --rule no-dash "$1"

Git's own comment lines, the ones starting with `#`, are in the file the hook receives, and they are read as text like every other line.

The audit of a repository's whole past, one commit at a time so each report keeps its commit:

    git rev-list HEAD | while read -r h; do git log -1 --format=%B "$h" | rule --rule no-dash --no-log - 2>&1 | sed "s/^<stdin>:/$h:/"; done

This checks every message ever committed against a rule that did not exist when they were written.

## Help

The last lines of `rule --help`:

    Rules are drawn from a fixed table. A given date always gives the same rule. There is no way to ignore a rule.

## Colophon

One file of Python, standard library only, no network. The report format is borrowed unchanged from GCC and Clang. The hard rules come from Perec and the Oulipo, no-be is E-Prime after D. David Bourland Jr., and the test paragraphs retell one walk to a river under each daily rule, after Queneau's Exercices de style. Rotation table revision 1, in force from 1970-01-01. This README was written on 2026-10-13, a no-k day, and checked against all thirty rules. It keeps none of them.

normal is dead
