chore: rename affixes.json to annotations.json (#1504)
Some checks are pending
Build Chrome Plugin / package (push) Waiting to run
Build Binaries / Release harper-cli - macOS-aarch64 (push) Waiting to run
Build Binaries / Release harper-cli - Linux-aarch64-GNU (push) Waiting to run
Build Binaries / Release harper-cli - Linux-aarch64-musl (push) Waiting to run
Build Binaries / Release harper-cli - macOS-x86_64 (push) Waiting to run
Build Binaries / Release harper-cli - Linux-x86_64-GNU (push) Waiting to run
Build Binaries / Release harper-cli - Linux-x86_64-musl (push) Waiting to run
Build Binaries / Release harper-cli - Windows-x86_64 (push) Waiting to run
Build Binaries / Release harper-ls - macOS-aarch64 (push) Waiting to run
Build Binaries / Release harper-ls - Linux-aarch64-GNU (push) Waiting to run
Build Binaries / Release harper-ls - Linux-aarch64-musl (push) Waiting to run
Build Binaries / Release harper-ls - macOS-x86_64 (push) Waiting to run
Build Binaries / Release harper-ls - Linux-x86_64-GNU (push) Waiting to run
Build Binaries / Release harper-ls - Linux-x86_64-musl (push) Waiting to run
Build Binaries / Release harper-ls - Windows-x86_64 (push) Waiting to run
Build Web / build (push) Waiting to run
Package VS Code Plugin / Package - darwin-arm64 (push) Waiting to run
Package VS Code Plugin / Package - darwin-x64 (push) Waiting to run
Package VS Code Plugin / Package - linux-arm64 (push) Waiting to run
Package VS Code Plugin / Package - linux-x64 (push) Waiting to run
Package VS Code Plugin / Package - win32-x64 (push) Waiting to run
Package WordPress Plugin / package (push) Waiting to run
Precommit / precommit (push) Waiting to run

* chore: rename `affixes.json` to `annotations.json`

The name was getting further and further from the function of the file. And the file is very important so a more representative name makes it less abstract when learning how Harper works.

* fix: mention old name `affixes.json`

I also noticed two fields in the sample entry had outdated names.

---------

Co-authored-by: Elijah Potter <me@elijahpotter.dev>
This commit is contained in:
Andrew Dunbar 2025-07-07 23:41:17 +07:00 committed by GitHub
parent 51148d0337
commit 92b964d038
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 19 deletions

View file

@ -352,7 +352,7 @@ fn main() -> anyhow::Result<()> {
let rune_words = format!("1\n{line}");
let dict = MutableDictionary::from_rune_files(
&rune_words,
include_str!("../../harper-core/affixes.json"),
include_str!("../../harper-core/annotations.json"),
)?;
println!("New, from you:");
@ -445,7 +445,7 @@ fn main() -> anyhow::Result<()> {
use serde_json::Value;
let dict_path = dir.join("dictionary.dict");
let affixes_path = dir.join("affixes.json");
let affixes_path = dir.join("annotations.json");
// Validate old and new flags are exactly one Unicode code point (Rust char)
// And not characters used for the dictionary format
@ -467,27 +467,27 @@ fn main() -> anyhow::Result<()> {
// Load and parse affixes
let affixes_string = fs::read_to_string(&affixes_path)
.map_err(|e| anyhow!("Failed to read affixes.json: {e}"))?;
.map_err(|e| anyhow!("Failed to read annotations.json: {e}"))?;
let affixes_json: Value = serde_json::from_str(&affixes_string)
.map_err(|e| anyhow!("Failed to parse affixes.json: {e}"))?;
.map_err(|e| anyhow!("Failed to parse annotations.json: {e}"))?;
// Get the nested "affixes" object
let affixes_obj = &affixes_json
.get("affixes")
.and_then(Value::as_object)
.ok_or_else(|| anyhow!("affixes.json does not contain 'affixes' object"))?;
.ok_or_else(|| anyhow!("annotations.json does not contain 'affixes' object"))?;
let properties_obj = &affixes_json
.get("properties")
.and_then(Value::as_object)
.ok_or_else(|| anyhow!("affixes.json does not contain 'properties' object"))?;
.ok_or_else(|| anyhow!("annotations.json does not contain 'properties' object"))?;
// Validate old flag exists and get its description
let old_entry = affixes_obj
.get(&old)
.or_else(|| properties_obj.get(&old))
.ok_or_else(|| anyhow!("Flag '{old}' not found in affixes.json"))?;
.ok_or_else(|| anyhow!("Flag '{old}' not found in annotations.json"))?;
let description = old_entry
.get("#")
@ -548,7 +548,7 @@ fn main() -> anyhow::Result<()> {
// Verify that the updated affixes string is valid JSON
serde_json::from_str::<Value>(&updated_affixes_string)
.map_err(|e| anyhow!("Failed to parse updated affixes.json: {e}"))?;
.map_err(|e| anyhow!("Failed to parse updated annotations.json: {e}"))?;
// Write changes
fs::write(&dict_path, updated_dict)

View file

@ -33,7 +33,7 @@ fn uncached_inner_new() -> Arc<MutableDictionary> {
Arc::new(
MutableDictionary::from_rune_files(
include_str!("../../dictionary.dict"),
include_str!("../../affixes.json"),
include_str!("../../annotations.json"),
)
.expect("Curated dictionary should be valid."),
)
@ -377,7 +377,7 @@ mod tests {
#[test]
fn are_merged_attrs_same_as_spread_attrs() {
let curated_attr_list = include_str!("../../affixes.json");
let curated_attr_list = include_str!("../../annotations.json");
let merged = MutableDictionary::from_rune_files("1\nblork/DGS", curated_attr_list).unwrap();
let spread =

View file

@ -438,10 +438,10 @@ registerlinter module name:
sed -i "/insert_expr_rule!(ChockFull, true);/a \ \ \ \ insert_struct_rule!({{name}}, true);" "$D/lint_group.rs"
just format
# Print affixes and their descriptions from affixes.json
# Print affixes and their descriptions from annotations.json
printaffixes:
#! /usr/bin/env node
const affixesData = require('{{justfile_directory()}}/harper-core/affixes.json');
const affixesData = require('{{justfile_directory()}}/harper-core/annotations.json');
const allAffixes = {
...affixesData.affixes || {},
...affixesData.properties || {}
@ -508,8 +508,8 @@ newest-dict-changes *numCommits:
if (showDiff) console.log(`DIFFSTART\n${diffString}\nDIFFEND`);
// uncomment first line to use in justfile, comment out second line to use standalone
const affixes = require('{{justfile_directory()}}/harper-core/affixes.json').affixes;
// const affixes = require('./harper-core/affixes.json').affixes;
const affixes = require('{{justfile_directory()}}/harper-core/annotations.json').affixes;
// const affixes = require('./harper-core/annotations.json').affixes;
diffString.split("\n").forEach(line => {
const match = line.match(/^(?:\[-(.*?)-\])?(?:\{\+(.*?)\+\})?$/);

View file

@ -9,15 +9,17 @@ If this happens to you, please open a PR to get them in.
PR [#343](https://github.com/Automattic/harper/pull/343) is a practical example of the ideas described here.
There are two files you need to worry about.
[`harper-core/dictionary.dict`](https://github.com/Automattic/harper/blob/master/harper-core/dictionary.dict) and [`harper-core/affixes.json`](https://github.com/Automattic/harper/blob/master/harper-core/affixes.json).
[`harper-core/dictionary.dict`](https://github.com/Automattic/harper/blob/master/harper-core/dictionary.dict) and [`harper-core/annotations.json`](https://github.com/Automattic/harper/blob/master/harper-core/annotations.json) (formerly `affixes.json`).
The first is a list of words, tagged with modifiers defined in the second.
For example, all words, such as "move", tagged with `L`, will be expanded to two dictionary entries, "move" and "movement".
In `affixes.json`, this expansion rule looks like this:
In `annotations.json`, this expansion rule looks like this:
```js title=affixes.json
```js title=annotations.json
{
"L": {
// A description of the rule.
"#": "'-ment' suffix",
// Denotes that the area of interest is at the _end_ of the base word.
"kind": "suffix",
// Declare that it is OK to use the result of the expansion with other expansions.
@ -33,9 +35,9 @@ In `affixes.json`, this expansion rule looks like this:
}
],
// The word metadata that should be applied to the expanded word.
"adds_metadata": {},
"target": {},
// The word metadata that should be applied to the base word.
"gifts_metadata": {}
"base_metadata": {}
}
}
```