harper-core 3.0.0

The language checker for developers.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
mod compound_noun_after_det_adj;
mod compound_noun_after_possessive;
mod compound_noun_before_aux_verb;

use super::{Lint, LintKind, Suggestion, merge_linters::merge_linters};
use crate::{CharStringExt, DictWordMetadata, Token};

// Helper function to check if a token is a content word (not a function word)
pub(crate) fn is_content_word(tok: &Token, src: &[char]) -> bool {
    let Some(Some(meta)) = tok.kind.as_word() else {
        return false;
    };

    tok.span.len() > 1
        && (meta.is_noun() || meta.is_adjective() || meta.is_verb() || meta.is_adverb())
        && !(meta.is_determiner() || meta.is_conjunction())
        && (!meta.preposition
            || tok
                .get_ch(src)
                .eq_any_ignore_ascii_case_str(&["bar", "through"]))
}

pub(crate) fn predicate(
    closed: Option<&DictWordMetadata>,
    open: Option<&DictWordMetadata>,
) -> bool {
    open.is_none() && closed.is_some_and(|m| m.is_noun() && !m.is_proper_noun())
}

use compound_noun_after_det_adj::CompoundNounAfterDetAdj;
use compound_noun_after_possessive::CompoundNounAfterPossessive;
use compound_noun_before_aux_verb::CompoundNounBeforeAuxVerb;

merge_linters!(CompoundNouns => CompoundNounAfterDetAdj, CompoundNounBeforeAuxVerb, CompoundNounAfterPossessive => "Detects compound nouns split by a space and suggests merging them when both parts form a valid noun." );

#[cfg(test)]
mod tests {
    use crate::linting::pooled_linter::for_tests::create_test_pool;

    create_test_pool!(CompoundNouns, CompoundNouns, CompoundNouns::default());
    use super::CompoundNouns;
    use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};

    #[test]
    fn web_cam() {
        let test_sentence = "The web cam captured a stunning image.";
        let expected = "The webcam captured a stunning image.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn note_book() {
        let test_sentence = "She always carries a note book to jot down ideas.";
        let expected = "She always carries a notebook to jot down ideas.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn mother_board() {
        let test_sentence = "After the upgrade, the mother board was replaced.";
        let expected = "After the upgrade, the motherboard was replaced.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn smart_phone() {
        let test_sentence = "He bought a new smart phone last week.";
        let expected = "He bought a new smartphone last week.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn firm_ware() {
        let test_sentence = "The device's firm ware was updated overnight.";
        let expected = "The device's firmware was updated overnight.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn back_plane() {
        let test_sentence = "A reliable back plane is essential for high-speed data transfer.";
        let expected = "A reliable backplane is essential for high-speed data transfer.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn spread_sheet() {
        let test_sentence = "The accountant reviewed the spread sheet carefully.";
        let expected = "The accountant reviewed the spreadsheet carefully.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn side_bar() {
        let test_sentence = "The website's side bar offers quick navigation links.";
        let expected = "The website's sidebar offers quick navigation links.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn back_pack() {
        let test_sentence = "I packed my books in my back pack before leaving.";
        let expected = "I packed my books in my backpack before leaving.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn cup_board() {
        let test_sentence = "She stored the dishes in the old cup board.";
        let expected = "She stored the dishes in the old cupboard.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn key_board() {
        let test_sentence = "My key board stopped working during the meeting.";
        let expected = "My keyboard stopped working during the meeting.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn touch_screen() {
        let test_sentence = "The device features a responsive touch screen.";
        let expected = "The device features a responsive touchscreen.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn head_set() {
        let test_sentence = "He bought a new head set for his workouts.";
        let expected = "He bought a new headset for his workouts.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn frame_work() {
        let test_sentence = "The frame work of the app was built with care.";
        let expected = "The framework of the app was built with care.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn touch_pad() {
        let test_sentence = "The touch pad on my laptop is very sensitive.";
        let expected = "The touchpad on my laptop is very sensitive.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn micro_processor() {
        let test_sentence = "This micro processor is among the fastest available.";
        let expected = "This microprocessor is among the fastest available.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn head_phone() {
        let test_sentence = "I lost my head phone at the gym.";
        let expected = "I lost my headphone at the gym.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn micro_services() {
        let test_sentence = "Our architecture now relies on micro services.";
        let expected = "Our architecture now relies on microservices.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn dash_board() {
        let test_sentence = "The dash board shows real-time analytics.";
        let expected = "The dashboard shows real-time analytics.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn site_map() {
        let test_sentence = "A site map is provided at the footer of the website.";
        let expected = "A sitemap is provided at the footer of the website.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn fire_wall() {
        let test_sentence = "A robust fire wall is essential for network security.";
        let expected = "A robust firewall is essential for network security.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn bit_stream() {
        let test_sentence = "The bit stream was interrupted during transmission.";
        let expected = "The bitstream was interrupted during transmission.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn block_chain() {
        let test_sentence = "The block chain is revolutionizing the financial sector.";
        let expected = "The blockchain is revolutionizing the financial sector.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn thumb_nail() {
        let test_sentence = "I saved the image as a thumb nail.";
        let expected = "I saved the image as a thumbnail.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn bath_room() {
        let test_sentence = "They remodeled the bath room entirely.";
        let expected = "They remodeled the bathroom entirely.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    #[ignore = "\"everyone\" is not a valid compound noun, it's a pronoun"]
    fn every_one() {
        let test_sentence = "Every one should have access to quality education.";
        let expected = "Everyone should have access to quality education.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn play_ground() {
        let test_sentence = "The kids spent the afternoon at the play ground.";
        let expected = "The kids spent the afternoon at the playground.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn run_way() {
        let test_sentence = "The airplane taxied along the run way.";
        let expected = "The airplane taxied along the runway.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn cyber_space() {
        let test_sentence = "Hackers roam the cyber space freely.";
        let expected = "Hackers roam the cyberspace freely.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn cyber_attack() {
        let test_sentence = "The network was hit by a cyber attack.";
        let expected = "The network was hit by a cyberattack.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn web_socket() {
        let test_sentence = "Real-time updates are sent via a web socket.";
        let expected = "Real-time updates are sent via a websocket.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn finger_print() {
        let test_sentence = "The detective collected a finger print as evidence.";
        let expected = "The detective collected a fingerprint as evidence.";
        assert_suggestion_result(test_sentence, test_linter(), expected);
    }

    #[test]
    fn got_is_not_possessive() {
        assert_lint_count("I got here by car...", test_linter(), 0);
    }

    #[test]
    fn allow_issue_662() {
        assert_lint_count("They are as old as *modern* computers ", test_linter(), 0);
    }

    #[test]
    fn allow_issue_661() {
        assert_lint_count("I may be wrong.", test_linter(), 0);
    }

    #[test]
    fn allow_issue_704() {
        assert_lint_count("Here are some ways to do that:", test_linter(), 0);
    }

    #[test]
    fn allows_issue_721() {
        assert_lint_count(
            "So if you adjust any one of these adjusters that can have a negative or a positive effect.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn allows_678() {
        assert_lint_count("they can't catch all the bugs.", test_linter(), 0);
    }

    #[test]
    fn ina_not_suggested() {
        assert_lint_count(
            "past mistakes or a character in a looping reality facing personal challenges.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn allow_suppress_or() {
        assert_lint_count(
            "He must decide whether to suppress or coexist with his doppelgänger.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn allow_an_arm_and_a_leg() {
        assert_lint_count(
            "I have to pay an arm and a leg get a worker to come and be my assistant baker.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn allow_well_and_723() {
        assert_lint_count(
            "I understood very well and decided to go.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn allow_can_not() {
        assert_lint_count("Size can not be determined.", test_linter(), 0);
    }

    #[test]
    fn dont_flag_lot_to() {
        assert_lint_count(
            "but you'd have to raise taxes a lot to do it.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn dont_flag_to_me() {
        assert_lint_count(
            "There's no massive damage to the rockers or anything that to me would indicate that like the whole front of the car was off",
            test_linter(),
            0,
        );
    }

    #[test]
    fn allow_issue_1553() {
        assert_no_lints(
            "I'm not sure if there's anyone else that may be interested in more fine-grained control, but as it stands, having the domain level toggle is sufficient for me.",
            test_linter(),
        );
    }

    #[test]
    fn allow_issue_1496() {
        assert_no_lints("I am not able to respond to messages.", test_linter());
    }

    #[test]
    fn allow_issue_1298() {
        assert_no_lints(
            "A series of tests that cover all possible cases.",
            test_linter(),
        );
    }

    #[test]
    fn dont_flag_project_or() {
        assert_no_lints(
            "You can star or watch this project or follow author to get release notifications in time.",
            test_linter(),
        );
    }

    #[test]
    fn allow_issue_3950() {
        assert_no_lints("She is a high school teacher.", test_linter());
    }

    #[test]
    fn allow_public_key_server() {
        assert_no_lints(
            "Alternatively, you can import them from a public key server.",
            test_linter(),
        );
    }

    #[test]
    fn still_flags_after_unrelated_adjective() {
        assert_suggestion_result(
            "The device features a responsive touch screen.",
            test_linter(),
            "The device features a responsive touchscreen.",
        );
    }

    #[test]
    fn fix_big_break_through() {
        assert_suggestion_result(
            "I think a big break through is needed for AGI so I haven’t been worried about it.",
            test_linter(),
            "I think a big breakthrough is needed for AGI so I haven’t been worried about it.",
        );
    }
}