bito-lint-core 0.1.1

Core library for bito-lint
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
//! Curated word lists for writing analysis.
//!
//! Collections of glue words, transition words, vague words, business jargon,
//! clich\u{e9}s, sensory words, hidden verbs, conjunctions, and spelling pairs.

use std::collections::{HashMap, HashSet};
use std::sync::LazyLock;

/// Common glue/function words (the, a, and, or, etc.).
pub static GLUE_WORDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    [
        "the", "a", "an", "and", "or", "but", "in", "on", "at", "to", "for", "of", "with", "by",
        "from", "up", "about", "into", "through", "during", "that", "this", "these", "those", "it",
        "its", "is", "are", "was", "were", "be", "been", "being", "have", "has", "had", "do",
        "does", "did", "will", "would", "should", "could", "may", "might", "must", "can", "which",
        "who", "when", "where", "why", "how", "if", "than", "then", "as", "so",
    ]
    .into_iter()
    .collect()
});

/// Transition words that connect ideas between sentences.
pub static TRANSITION_WORDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    [
        "however",
        "therefore",
        "thus",
        "consequently",
        "nevertheless",
        "moreover",
        "furthermore",
        "additionally",
        "meanwhile",
        "instead",
        "otherwise",
        "similarly",
        "likewise",
        "conversely",
        "nonetheless",
        "hence",
        "accordingly",
        "subsequently",
        "indeed",
        "specifically",
        "particularly",
        "especially",
    ]
    .into_iter()
    .collect()
});

/// Multi-word transition phrases.
pub static TRANSITION_PHRASES: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    [
        "for example",
        "for instance",
        "in addition",
        "in contrast",
        "on the other hand",
        "as a result",
        "in conclusion",
        "in summary",
        "to summarize",
        "finally",
    ]
    .into_iter()
    .collect()
});

/// Vague or weak words that weaken prose.
pub static VAGUE_WORDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    [
        "thing",
        "things",
        "stuff",
        "nice",
        "good",
        "bad",
        "great",
        "terrible",
        "amazing",
        "awesome",
        "interesting",
        "very",
        "really",
        "quite",
        "rather",
        "somewhat",
        "pretty",
        "fairly",
    ]
    .into_iter()
    .collect()
});

/// Vague phrases.
pub static VAGUE_PHRASES: LazyLock<HashSet<&'static str>> =
    LazyLock::new(|| ["kind of", "sort of", "a bit"].into_iter().collect());

/// Business jargon words.
pub static BUSINESS_JARGON: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    [
        "synergy",
        "leverage",
        "paradigm",
        "disrupt",
        "innovative",
        "streamline",
        "optimization",
        "scalable",
        "bandwidth",
        "win-win",
        "game changer",
        "best practice",
        "core competency",
        "value-added",
        "going forward",
        "deep dive",
        "reach out",
    ]
    .into_iter()
    .collect()
});

/// Business jargon phrases.
pub static BUSINESS_JARGON_PHRASES: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    [
        "circle back",
        "touch base",
        "low-hanging fruit",
        "move the needle",
        "drink the kool-aid",
        "boil the ocean",
        "think outside the box",
        "at the end of the day",
        "take it offline",
        "drill down",
    ]
    .into_iter()
    .collect()
});

/// Common clich\u{e9}s.
pub static CLICHES: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    [
        "avoid it like the plague",
        "beat around the bush",
        "better late than never",
        "bite the bullet",
        "break the ice",
        "bring to the table",
        "call it a day",
        "cut to the chase",
        "easy as pie",
        "get the ball rolling",
        "hit the nail on the head",
        "in the nick of time",
        "it goes without saying",
        "jump on the bandwagon",
        "keep your eyes peeled",
        "let the cat out of the bag",
        "piece of cake",
        "raining cats and dogs",
        "the best of both worlds",
        "throw in the towel",
        "time flies",
        "under the weather",
        "when pigs fly",
        "whole nine yards",
        "a blessing in disguise",
        "a dime a dozen",
        "actions speak louder than words",
        "add insult to injury",
        "at the drop of a hat",
        "back to square one",
        "barking up the wrong tree",
        "bent out of shape",
        "bite off more than you can chew",
        "break a leg",
        "burning the midnight oil",
        "caught between a rock and a hard place",
        "costs an arm and a leg",
        "cry over spilled milk",
        "curiosity killed the cat",
        "devil's advocate",
        "don't count your chickens",
        "every cloud has a silver lining",
    ]
    .into_iter()
    .collect()
});

/// Sensory words organized by the five senses.
pub static SENSORY_WORDS: LazyLock<HashMap<&'static str, HashSet<&'static str>>> =
    LazyLock::new(|| {
        let mut map = HashMap::new();

        map.insert(
            "sight",
            [
                "see",
                "saw",
                "seen",
                "look",
                "looked",
                "looking",
                "watch",
                "watched",
                "bright",
                "dark",
                "light",
                "shadow",
                "color",
                "colorful",
                "shiny",
                "dull",
                "vivid",
                "brilliant",
                "gleaming",
                "glowing",
                "sparkling",
                "shimmering",
                "transparent",
                "opaque",
                "visible",
                "invisible",
                "appearance",
                "view",
                "glimpse",
                "glance",
                "stare",
                "gaze",
                "observe",
                "notice",
                "spot",
            ]
            .into_iter()
            .collect(),
        );

        map.insert(
            "sound",
            [
                "hear",
                "heard",
                "listen",
                "listened",
                "sound",
                "noise",
                "loud",
                "quiet",
                "silent",
                "whisper",
                "shout",
                "scream",
                "yell",
                "murmur",
                "mumble",
                "echo",
                "ring",
                "buzz",
                "hum",
                "bang",
                "crash",
                "thump",
                "click",
                "rustle",
                "crackle",
                "pop",
                "snap",
                "sizzle",
                "hiss",
                "roar",
                "howl",
                "musical",
                "melodious",
                "harmonious",
                "deafening",
                "piercing",
            ]
            .into_iter()
            .collect(),
        );

        map.insert(
            "touch",
            [
                "feel", "felt", "touch", "touched", "soft", "hard", "smooth", "rough", "texture",
                "cold", "hot", "warm", "cool", "freezing", "burning", "icy", "sticky", "slippery",
                "dry", "wet", "moist", "damp", "sharp", "dull", "coarse", "silky", "velvety",
                "grainy", "bumpy", "prickly", "tender", "firm", "solid", "squishy", "fluffy",
                "crisp", "brittle",
            ]
            .into_iter()
            .collect(),
        );

        map.insert(
            "smell",
            [
                "smell",
                "smelled",
                "smelling",
                "scent",
                "odor",
                "aroma",
                "fragrance",
                "perfume",
                "stink",
                "stench",
                "whiff",
                "sniff",
                "fragrant",
                "aromatic",
                "pungent",
                "acrid",
                "musty",
                "moldy",
                "fresh",
                "stale",
                "rancid",
                "sweet",
                "sour",
                "spicy",
                "floral",
                "earthy",
                "smoky",
                "putrid",
            ]
            .into_iter()
            .collect(),
        );

        map.insert(
            "taste",
            [
                "taste",
                "tasted",
                "tasting",
                "flavor",
                "flavored",
                "sweet",
                "sour",
                "bitter",
                "salty",
                "savory",
                "spicy",
                "tangy",
                "tart",
                "bland",
                "mild",
                "delicious",
                "tasty",
                "appetizing",
                "mouthwatering",
                "scrumptious",
                "palatable",
                "flavorful",
                "zesty",
                "peppery",
                "sugary",
                "acidic",
            ]
            .into_iter()
            .collect(),
        );

        map
    });

/// Hidden verbs: noun forms that could be replaced with their verb equivalents.
pub static HIDDEN_VERBS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
    [
        ("decision", "decide"),
        ("conclusion", "conclude"),
        ("assumption", "assume"),
        ("observation", "observe"),
        ("consideration", "consider"),
        ("implementation", "implement"),
        ("investigation", "investigate"),
        ("examination", "examine"),
        ("explanation", "explain"),
        ("discussion", "discuss"),
        ("analysis", "analyze"),
        ("recommendation", "recommend"),
        ("suggestion", "suggest"),
        ("description", "describe"),
    ]
    .into_iter()
    .collect()
});

/// Coordinating conjunctions.
pub static CONJUNCTIONS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
    ["and", "but", "or", "so", "yet", "for", "nor"]
        .into_iter()
        .collect()
});

/// Categorizes spelling differences between US and UK English.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SpellingPattern {
    /// -or vs -our (color/colour)
    OrOur,
    /// -er vs -re (center/centre)
    ErRe,
    /// -ize vs -ise (organize/organise)
    IzeIse,
    /// -ense vs -ence (defense/defence)
    EnseEnce,
    /// -og vs -ogue (catalog/catalogue)
    OgOgue,
    /// -am vs -amme (program/programme)
    AmAmme,
    /// Doubled consonant differences (traveling/travelling)
    Double,
    /// Miscellaneous spelling differences (gray/grey)
    Misc,
}

/// A US/UK spelling pair with its pattern category.
#[derive(Debug, Clone, Copy)]
pub struct SpellingPair {
    /// The US spelling.
    pub us: &'static str,
    /// The UK spelling.
    pub uk: &'static str,
    /// The pattern this pair belongs to.
    pub pattern: SpellingPattern,
}

impl SpellingPair {
    const fn new(us: &'static str, uk: &'static str, pattern: SpellingPattern) -> Self {
        Self { us, uk, pattern }
    }
}

use crate::config::Dialect;

impl Dialect {
    /// Whether this dialect prefers the US form for a given spelling pattern.
    ///
    /// Canadian English is hybrid: US for `-ize/-ise` and `-am/-amme`,
    /// UK for everything else.
    pub const fn prefers_us(&self, pattern: SpellingPattern) -> bool {
        match self {
            Self::EnUs => true,
            Self::EnGb | Self::EnAu => false,
            Self::EnCa => matches!(pattern, SpellingPattern::IzeIse | SpellingPattern::AmAmme),
        }
    }

    /// Returns the preferred spelling for a pair in this dialect.
    pub const fn preferred_form<'a>(&self, pair: &'a SpellingPair) -> &'a str {
        if self.prefers_us(pair.pattern) {
            pair.us
        } else {
            pair.uk
        }
    }
}

/// US/UK spelling pairs organized by pattern.
pub static SPELLING_PAIRS: LazyLock<Vec<SpellingPair>> = LazyLock::new(|| {
    use SpellingPattern::*;
    vec![
        // -or / -our
        SpellingPair::new("color", "colour", OrOur),
        SpellingPair::new("favor", "favour", OrOur),
        SpellingPair::new("honor", "honour", OrOur),
        SpellingPair::new("labor", "labour", OrOur),
        SpellingPair::new("neighbor", "neighbour", OrOur),
        SpellingPair::new("humor", "humour", OrOur),
        SpellingPair::new("flavor", "flavour", OrOur),
        SpellingPair::new("tumor", "tumour", OrOur),
        SpellingPair::new("vigor", "vigour", OrOur),
        SpellingPair::new("valor", "valour", OrOur),
        SpellingPair::new("behavior", "behaviour", OrOur),
        SpellingPair::new("harbor", "harbour", OrOur),
        SpellingPair::new("savior", "saviour", OrOur),
        SpellingPair::new("armor", "armour", OrOur),
        SpellingPair::new("clamor", "clamour", OrOur),
        SpellingPair::new("glamor", "glamour", OrOur),
        SpellingPair::new("parlor", "parlour", OrOur),
        SpellingPair::new("rancor", "rancour", OrOur),
        SpellingPair::new("endeavor", "endeavour", OrOur),
        SpellingPair::new("candor", "candour", OrOur),
        SpellingPair::new("demeanor", "demeanour", OrOur),
        SpellingPair::new("splendor", "splendour", OrOur),
        SpellingPair::new("odor", "odour", OrOur),
        SpellingPair::new("rumor", "rumour", OrOur),
        // -er / -re
        SpellingPair::new("center", "centre", ErRe),
        SpellingPair::new("meter", "metre", ErRe),
        SpellingPair::new("fiber", "fibre", ErRe),
        SpellingPair::new("theater", "theatre", ErRe),
        SpellingPair::new("somber", "sombre", ErRe),
        SpellingPair::new("luster", "lustre", ErRe),
        SpellingPair::new("meager", "meagre", ErRe),
        SpellingPair::new("caliber", "calibre", ErRe),
        SpellingPair::new("saber", "sabre", ErRe),
        SpellingPair::new("specter", "spectre", ErRe),
        SpellingPair::new("miter", "mitre", ErRe),
        SpellingPair::new("ocher", "ochre", ErRe),
        SpellingPair::new("maneuver", "manoeuvre", ErRe),
        SpellingPair::new("sepulcher", "sepulchre", ErRe),
        // -ize / -ise
        SpellingPair::new("organize", "organise", IzeIse),
        SpellingPair::new("recognize", "recognise", IzeIse),
        SpellingPair::new("analyze", "analyse", IzeIse),
        SpellingPair::new("realize", "realise", IzeIse),
        SpellingPair::new("customize", "customise", IzeIse),
        SpellingPair::new("specialize", "specialise", IzeIse),
        SpellingPair::new("apologize", "apologise", IzeIse),
        SpellingPair::new("minimize", "minimise", IzeIse),
        SpellingPair::new("optimize", "optimise", IzeIse),
        SpellingPair::new("authorize", "authorise", IzeIse),
        SpellingPair::new("categorize", "categorise", IzeIse),
        SpellingPair::new("criticize", "criticise", IzeIse),
        SpellingPair::new("emphasize", "emphasise", IzeIse),
        SpellingPair::new("finalize", "finalise", IzeIse),
        SpellingPair::new("initialize", "initialise", IzeIse),
        SpellingPair::new("standardize", "standardise", IzeIse),
        SpellingPair::new("summarize", "summarise", IzeIse),
        SpellingPair::new("utilize", "utilise", IzeIse),
        // -ense / -ence
        SpellingPair::new("defense", "defence", EnseEnce),
        SpellingPair::new("offense", "offence", EnseEnce),
        SpellingPair::new("license", "licence", EnseEnce),
        SpellingPair::new("pretense", "pretence", EnseEnce),
        // -og / -ogue
        SpellingPair::new("analog", "analogue", OgOgue),
        SpellingPair::new("catalog", "catalogue", OgOgue),
        SpellingPair::new("dialog", "dialogue", OgOgue),
        SpellingPair::new("monolog", "monologue", OgOgue),
        SpellingPair::new("prolog", "prologue", OgOgue),
        // -am / -amme
        SpellingPair::new("program", "programme", AmAmme),
        SpellingPair::new("gram", "gramme", AmAmme),
        // Doubled consonants
        SpellingPair::new("traveling", "travelling", Double),
        SpellingPair::new("canceled", "cancelled", Double),
        SpellingPair::new("counselor", "counsellor", Double),
        SpellingPair::new("modeling", "modelling", Double),
        SpellingPair::new("leveling", "levelling", Double),
        SpellingPair::new("labeled", "labelled", Double),
        SpellingPair::new("signaling", "signalling", Double),
        SpellingPair::new("marvelous", "marvellous", Double),
        SpellingPair::new("enrollment", "enrolment", Double),
        SpellingPair::new("fulfillment", "fulfilment", Double),
        SpellingPair::new("skillful", "skilful", Double),
        SpellingPair::new("installment", "instalment", Double),
        // Miscellaneous
        SpellingPair::new("gray", "grey", Misc),
        SpellingPair::new("artifact", "artefact", Misc),
        SpellingPair::new("skeptic", "sceptic", Misc),
        SpellingPair::new("jewelry", "jewellery", Misc),
        SpellingPair::new("aluminum", "aluminium", Misc),
        SpellingPair::new("pajamas", "pyjamas", Misc),
    ]
});

/// Backward-compatible accessor: US/UK spelling pairs as `(us, uk)` tuples.
pub static US_UK_PAIRS: LazyLock<Vec<(&'static str, &'static str)>> = LazyLock::new(|| {
    SPELLING_PAIRS
        .iter()
        .map(|pair| (pair.us, pair.uk))
        .collect()
});

/// Hyphenation variant pairs `(joined, hyphenated)`.
pub static HYPHEN_PATTERNS: LazyLock<Vec<(&'static str, &'static str)>> = LazyLock::new(|| {
    vec![
        ("email", "e-mail"),
        ("online", "on-line"),
        ("website", "web-site"),
        ("today", "to-day"),
        ("cooperate", "co-operate"),
        ("coordinate", "co-ordinate"),
    ]
});