Automattic / Automattic/harper

Documentation should include some advanced Weir examples

Open
#4,334 0 comments 0 reactions 1 assignee Claimed by @elijah-potter View on GitHub
documentation weir
Dominant language
Rust
Stars
15.4k
Forks
627
Avg merge
1d 12h
Merged PRs (30d)
106

Description

I've been stuck on the original basic subset of Weir from when it first appeared. I'm finding it tricky even as a programmer with decades of experience to pick up the more advanced features. So I'm assuming it will be even trickier for non-programmers?

```weir
expr relPronouns [which, that, who, whom, whose]
expr main <((an in) ![-, with, (NOUN @relPronouns), (PROPN @relPronouns)]), an>
```

Is every Weir feature documented? I can't actually tell.

----
As a real-world example, I'm trying to solve #4333 using Weir. I thought I could but excluded context using this syntax but it's not working:
```weir
expr main <(Apple Silicone) ![case, cover, iPhone]>

let message "If you're referring to the chip and not the phone cover, use `Silicon` not `Silicone`."
let description "Corrects `Apple Silicone` to `Apple Silicon`."
let kind "Spelling"
let becomes "Apple Silicon"

test "I am testing it on Google Docs, Google Chrome, and Apple Silicone." "I am testing it on Google Docs, Google Chrome, and Apple Silicon."
allows "Apple Silicone case is honestly the worst case I've ever had on any phone."
allows "It's The Case That Never Changes! - Apple Silicone iPhone 16 Case Review"

allows "The new MacBook is powered by an Apple Silicon chip."
```
```
failures:

---- linting::weir_rules::tests::run_tests_in_apple_silicon stdout ----

thread 'linting::weir_rules::tests::run_tests_in_apple_silicon' (63655828) panicked at /Users/hippietrail/harper/target/debug/build/harper-core-f1b7be42e26fe605/out/weir_rules_generated_list.rs:1:1:
called `Result::unwrap()` on an `Err` value: ExpectedComma
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
linting::weir_rules::tests::run_tests_in_apple_silicon

test result: FAILED. 10 passed; 1 failed; 0 ignored; 0 measured; 6747 filtered out; finished in 0.35s

error: test failed, to rerun pass `-p harper-core --lib`
```
I tried changing to `expr main <((Apple Silicone) ![case, cover, iPhone])>` and that seems to have fixed the syntax error in my Weir and the `allow` tests now pass, but the `test` and a minimal one still fail:
```
test linting::weir_rules::tests::run_tests_in_apple_silicon ... FAILED

failures:

---- linting::weir_rules::tests::run_tests_in_apple_silicon stdout ----

thread 'linting::weir_rules::tests::run_tests_in_apple_silicon' (63701543) panicked at /Users/hippietrail/harper/target/debug/build/harper-core-f1b7be42e26fe605/out/weir_rules_generated_list.rs:1:1:
assertion `left == right` failed
left: []
right: [TestResult { expected: "Apple Silicon", got: "Apple Silicone" }]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
That `left` vs `right` looks really weird to me. I would've thought one should have the `expected` and the other should have the `got`??

----
I thought I got it and that having the `!` part forced it to need *something* after "Apple Silicone" and that the something could not be any of those words. An AI thought so and there are Weir rules like `expr main <((your self) !-), (your self)>` so I was expecting `expr main <((Apple Silicone) ![case, cover, iPhone]), (Apple Silicone)>` to work but alas no:
```
running 1 test
test linting::weir_rules::tests::run_tests_in_apple_silicon ... FAILED

failures:

---- linting::weir_rules::tests::run_tests_in_apple_silicon stdout ----

thread 'linting::weir_rules::tests::run_tests_in_apple_silicon' (63732195) panicked at /Users/hippietrail/harper/target/debug/build/harper-core-f1b7be42e26fe605/out/weir_rules_generated_list.rs:1:1:
assertion `left == right` failed
left: []
right: [TestResult { expected: "Apple Silicon", got: "Apple Silicone" }]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

I'm going to file what I've got as a draft PR to accompany this issue and move on...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.