harper-core 2.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
use super::merge_linters::merge_linters;

mod general;
mod proper_noun;

use general::General;
use proper_noun::ProperNoun;

merge_linters!(
    ItsContraction => General, ProperNoun =>
    "Detects places where the possessive `its` should be the contraction `it's`, including before verbs/clauses and before proper nouns after opinion verbs."
);

#[cfg(test)]
mod tests {
    use super::ItsContraction;
    use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};

    #[test]
    fn fix_had() {
        assert_suggestion_result(
            "Its had an enormous effect.",
            ItsContraction::default(),
            "It's had an enormous effect.",
        );
    }

    #[test]
    fn fix_been() {
        assert_suggestion_result(
            "Its been months since we spoke.",
            ItsContraction::default(),
            "It's been months since we spoke.",
        );
    }

    #[test]
    fn fix_got() {
        assert_suggestion_result(
            "I think its got nothing to do with us.",
            ItsContraction::default(),
            "I think it's got nothing to do with us.",
        );
    }

    #[test]
    fn fixes_its_common() {
        assert_suggestion_result(
            "Its common for users to get frustrated.",
            ItsContraction::default(),
            "It's common for users to get frustrated.",
        );
    }

    #[test]
    fn ignore_correct_contraction() {
        assert_lint_count(
            "It's been a long year for everyone.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn ignore_possessive() {
        assert_lint_count(
            "The company revised its policies last week.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn ignore_coroutine() {
        assert_lint_count(
            "Launch each task within its own child coroutine.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn issue_381() {
        assert_suggestion_result(
            "Its a nice day.",
            ItsContraction::default(),
            "It's a nice day.",
        );
    }

    #[test]
    fn ignore_nominal_progressive() {
        assert_lint_count(
            "The class preserves its existing properties.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    #[ignore = "past participles are not always adjectives ('cared' for instance)"]
    fn ignore_nominal_perfect() {
        assert_lint_count(
            "The robot followed its predetermined route.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn ignore_nominal_long() {
        assert_lint_count(
            "I think of its exploding marvelous spectacular output.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn corrects_because() {
        assert_suggestion_result(
            "Its because they don't want to.",
            ItsContraction::default(),
            "It's because they don't want to.",
        );
    }

    #[test]
    fn corrects_its_hard() {
        assert_suggestion_result(
            "Its hard to believe that.",
            ItsContraction::default(),
            "It's hard to believe that.",
        );
    }

    #[test]
    fn corrects_its_easy() {
        assert_suggestion_result(
            "Its easy if you try.",
            ItsContraction::default(),
            "It's easy if you try.",
        );
    }

    #[test]
    fn corrects_its_a_picnic() {
        assert_suggestion_result(
            "Its a beautiful day for a picnic",
            ItsContraction::default(),
            "It's a beautiful day for a picnic",
        );
    }

    #[test]
    fn corrects_its_my() {
        assert_suggestion_result(
            "Its my favorite song.",
            ItsContraction::default(),
            "It's my favorite song.",
        );
    }

    #[test]
    fn allows_its_new() {
        assert_no_lints(
            "The company announced its new product line. ",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_own_charm() {
        assert_no_lints("The house has its own charm. ", ItsContraction::default());
    }

    #[test]
    fn allows_its_victory() {
        assert_no_lints(
            "The team celebrated its victory. ",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_history() {
        assert_no_lints(
            "The country is proud of its history. ",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_secrets() {
        assert_no_lints(
            "The book contains its own secrets. ",
            ItsContraction::default(),
        );
    }

    #[test]
    fn corrects_think_google() {
        assert_suggestion_result(
            "I think its Google, not Microsoft.",
            ItsContraction::default(),
            "I think it's Google, not Microsoft.",
        );
    }

    #[test]
    fn corrects_hope_katie() {
        assert_suggestion_result(
            "I hope its Katie.",
            ItsContraction::default(),
            "I hope it's Katie.",
        );
    }

    #[test]
    fn corrects_guess_date() {
        assert_suggestion_result(
            "I guess its March 6.",
            ItsContraction::default(),
            "I guess it's March 6.",
        );
    }

    #[test]
    fn corrects_assume_john() {
        assert_suggestion_result(
            "We assume its John.",
            ItsContraction::default(),
            "We assume it's John.",
        );
    }

    #[test]
    fn corrects_doubt_tesla() {
        assert_suggestion_result(
            "They doubt its Tesla this year.",
            ItsContraction::default(),
            "They doubt it's Tesla this year.",
        );
    }

    #[test]
    fn handles_two_word_name() {
        assert_suggestion_result(
            "She thinks its New York.",
            ItsContraction::default(),
            "She thinks it's New York.",
        );
    }

    #[test]
    fn ignores_existing_contraction() {
        assert_lint_count("I think it's Google.", ItsContraction::default(), 0);
    }

    #[test]
    fn ignores_possessive_noun_after_name() {
        assert_lint_count(
            "I think its Google product launch.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn ignores_without_opinion_verb() {
        assert_lint_count(
            "Its Google Pixel lineup is impressive.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn ignores_common_noun_target() {
        assert_lint_count(
            "We hope its accuracy improves.",
            ItsContraction::default(),
            0,
        );
    }

    #[test]
    fn issue_2547() {
        assert_no_lints(
            "using the foo feature and its associated parameter",
            ItsContraction::default(),
        );
    }

    #[test]
    fn ignore_past_participle_noun_phrase() {
        assert_no_lints(
            "using the foo feature and its abetted parameter",
            ItsContraction::default(),
        );
    }

    #[test]
    fn corrects_predicative_called() {
        assert_suggestion_result(
            "Its called recursion.",
            ItsContraction::default(),
            "It's called recursion.",
        );
    }

    #[test]
    fn corrects_predicative_named() {
        assert_suggestion_result(
            "Its named Manhattan.",
            ItsContraction::default(),
            "It's named Manhattan.",
        );
    }

    #[test]
    fn allows_possessive_generated_code() {
        assert_no_lints(
            "The compiler emits its generated code.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn corrects_its_anybody() {
        assert_suggestion_result(
            "Its anybody who volunteers should speak up.",
            ItsContraction::default(),
            "It's anybody who volunteers should speak up.",
        );
    }

    #[test]
    fn corrects_its_anyone() {
        assert_suggestion_result(
            "Its anyone you ping will be looped in automatically.",
            ItsContraction::default(),
            "It's anyone you ping will be looped in automatically.",
        );
    }

    #[test]
    fn corrects_its_everyone() {
        assert_suggestion_result(
            "Its everyone on the thread noticed the spike.",
            ItsContraction::default(),
            "It's everyone on the thread noticed the spike.",
        );
    }

    #[test]
    fn corrects_its_everything() {
        assert_suggestion_result(
            "Its everything we collect ends up in the archive.",
            ItsContraction::default(),
            "It's everything we collect ends up in the archive.",
        );
    }

    #[test]
    fn corrects_its_somebody() {
        assert_suggestion_result(
            "Its somebody on call right now.",
            ItsContraction::default(),
            "It's somebody on call right now.",
        );
    }

    #[test]
    fn corrects_its_somewhere() {
        assert_suggestion_result(
            "Its somewhere safe to stash the nightly dump.",
            ItsContraction::default(),
            "It's somewhere safe to stash the nightly dump.",
        );
    }

    #[test]
    fn corrects_its_nobody() {
        assert_suggestion_result(
            "Its nobody left who can approve this.",
            ItsContraction::default(),
            "It's nobody left who can approve this.",
        );
    }

    #[test]
    fn corrects_its_anywhere() {
        assert_suggestion_result(
            "Its anywhere the monitors blink red.",
            ItsContraction::default(),
            "It's anywhere the monitors blink red.",
        );
    }

    #[test]
    fn corrects_its_anything() {
        assert_suggestion_result(
            "Its anything worth keeping should be archived.",
            ItsContraction::default(),
            "It's anything worth keeping should be archived.",
        );
    }

    #[test]
    fn corrects_its_something() {
        assert_suggestion_result(
            "Its something that keeps restarting the job.",
            ItsContraction::default(),
            "It's something that keeps restarting the job.",
        );
    }

    #[test]
    fn allows_its_tail() {
        assert_no_lints(
            "Its tail twitches every time I call it.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_release_pipeline() {
        assert_no_lints(
            "Its release pipeline is stable in production.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_nodes() {
        assert_no_lints(
            "The cluster updates its nodes nightly.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_cover_page() {
        assert_no_lints(
            "Its cover page mentions all contributors.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_not_anybody() {
        assert_no_lints(
            "Its not anybody to blame despite the outage.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_never_anywhere() {
        assert_no_lints(
            "Its never anywhere near the ideal timing we hoped for.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_at_its_highest() {
        assert_no_lints(
            "Curiosity about Gatsby was at its highest that night.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_pull_is() {
        assert_no_lints(
            "The Earth is huge, so its pull is super strong.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_unforeseen_consequences() {
        assert_no_lints(
            "The experiment continued despite its unforeseen consequences.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_potential_to_benefit() {
        assert_no_lints(
            "The proposal emphasized its potential to benefit local businesses.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_cover_was() {
        assert_no_lints(
            "Its cover was intricately engraved with floral patterns.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn allows_its_starting_level() {
        assert_no_lints(
            "Reduce the tracker to its starting level.",
            ItsContraction::default(),
        );
    }
}