drep-ai 3.1.6

A local commit gate: runs the linters your repo configures, and sends changed code to an LLM for review
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
//! Indented code blocks (CommonMark 0.31.2, section 4.4).
//!
//! An indented chunk after a blank line is code, so the checks whose advice is
//! wrong inside a fence are wrong inside it too. Each case below is a document
//! that renders correctly. The pairs run the same snippet as prose and as code,
//! because a check that never fires would pass the silent half on its own.

use crate::docs::Check;
use crate::docs::tests::fence::{fence_blind, fence_sensitive};
use crate::docs::tests::{fires_once_at, of_kind, silent};

#[test]
fn fence_sensitive_checks_are_silent_in_an_indented_block() {
    for (check, snippet) in fence_sensitive() {
        silent(&format!("Intro.\n\n    {snippet}\n"), check);
    }
}

#[test]
fn fence_sensitive_checks_still_fire_in_the_prose_around_a_block() {
    for (check, snippet) in fence_sensitive() {
        let content = format!("{snippet}\n\n    code\n\n{snippet}\n");
        let lines: Vec<u32> = of_kind(&content, check).iter().map(|f| f.line).collect();
        assert_eq!(lines, vec![1, 5], "{} over {content:?}", check.as_str());
    }
}

#[test]
fn fence_blind_checks_fire_in_an_indented_block() {
    for (check, snippet) in fence_blind() {
        let content = format!("Intro.\n\n    {snippet}\n");
        fires_once_at(&content, check, 3, snippet.chars().count() as u32 + 4 - 1);
    }
}

#[test]
fn a_tab_indents_a_block() {
    silent("Intro.\n\n\tsee https://example.com/x\n", Check::BareUrl);
    silent("Intro.\n\n\tcol\tcol\n", Check::TabCharacter);
}

#[test]
fn a_block_starts_at_the_top_of_a_file() {
    silent("    see https://example.com/x\n", Check::BareUrl);
}

#[test]
fn a_block_runs_across_blank_lines() {
    silent(
        "Intro.\n\n    one\n\n    see https://example.com/x\n",
        Check::BareUrl,
    );
}

#[test]
fn a_block_ends_at_the_first_unindented_line() {
    fires_once_at(
        "Intro.\n\n    code\nsee https://example.com/x\n",
        Check::BareUrl,
        4,
        5,
    );
}

#[test]
fn three_spaces_do_not_make_a_block() {
    fires_once_at(
        "Intro.\n\n   see https://example.com/x\n",
        Check::BareUrl,
        3,
        8,
    );
}

#[test]
fn an_indented_line_continuing_a_paragraph_is_not_a_block() {
    // A block cannot interrupt a paragraph.
    fires_once_at(
        "Intro\n    see https://example.com/x\n",
        Check::BareUrl,
        2,
        9,
    );
}

#[test]
fn an_indented_paragraph_in_a_list_item_is_not_a_block() {
    // The item's content offset is not tracked, so under a list marker the
    // indentation is ambiguous and stays prose.
    fires_once_at(
        "- item\n\n    see https://example.com/x\n",
        Check::BareUrl,
        3,
        9,
    );
    fires_once_at(
        "1. item\n\n    see https://example.com/x\n",
        Check::BareUrl,
        3,
        9,
    );
}

#[test]
fn a_lazy_line_keeps_the_list_open() {
    fires_once_at(
        "- item\nlazy\n\n    see https://example.com/x\n",
        Check::BareUrl,
        4,
        9,
    );
}

#[test]
fn a_paragraph_after_a_list_closes_it() {
    silent(
        "- item\n\nText.\n\n    see https://example.com/x\n",
        Check::BareUrl,
    );
}

#[test]
fn a_marker_is_not_a_list_without_its_space() {
    silent("-item\n\n    see https://example.com/x\n", Check::BareUrl);
    silent(
        "1.5 apples\n\n    see https://example.com/x\n",
        Check::BareUrl,
    );
}

#[test]
fn a_block_after_a_closed_fence_is_a_block() {
    silent(
        "```text\nx\n```\n    see https://example.com/x\n",
        Check::BareUrl,
    );
}

#[test]
fn a_comment_opener_in_a_block_opens_nothing() {
    fires_once_at(
        "Intro.\n\n    <!-- x\n\nhttps://example.com\n-->\n",
        Check::BareUrl,
        5,
        1,
    );
}

#[test]
fn blank_lines_between_two_indented_lines_belong_to_the_block() {
    silent("Intro.\n\n    a\n\n\n\n    b\n", Check::MultipleBlankLines);
}

#[test]
fn blank_lines_after_a_block_are_still_a_run() {
    fires_once_at(
        "Intro.\n\n    a\n\n\n\ntext\n",
        Check::MultipleBlankLines,
        4,
        1,
    );
}

#[test]
fn blank_lines_between_two_fences_are_still_a_run() {
    fires_once_at(
        "```\na\n```\n\n\n\n```\nb\n```\n",
        Check::MultipleBlankLines,
        4,
        1,
    );
}

#[test]
fn a_tab_counts_to_the_next_tab_stop() {
    silent("Intro.\n\n  \tsee https://example.com/x\n", Check::BareUrl);
    silent("Intro.\n\n \t see https://example.com/x\n", Check::BareUrl);
    // Two spaces and a character are not four columns.
    fires_once_at(
        "Intro.\n\n  a https://example.com/x\n",
        Check::BareUrl,
        3,
        5,
    );
}

#[test]
fn every_list_marker_keeps_the_indentation_ambiguous() {
    for marker in [
        "- ",
        "* ",
        "+ ",
        "1. ",
        "1) ",
        "123456789. ",
        "-\t",
        "  - ",
        "   1. ",
    ] {
        let content = format!("{marker}item\n\n    see https://example.com/x\n");
        assert_eq!(
            of_kind(&content, Check::BareUrl).len(),
            1,
            "a `{marker}` line opens a list: {content:?}"
        );
    }
    // A marker with nothing after it is an empty item.
    for marker in ["-", "1."] {
        let content = format!("{marker}\n\n    see https://example.com/x\n");
        assert_eq!(of_kind(&content, Check::BareUrl).len(), 1, "{content:?}");
    }
}

#[test]
fn a_line_that_only_resembles_a_marker_opens_no_list() {
    for text in ["1234567890. item", "a. item", ". item", "1 item", "1.item"] {
        let content = format!("{text}\n\n    see https://example.com/x\n");
        silent(&content, Check::BareUrl);
    }
}

#[test]
fn indented_text_that_looks_like_a_marker_is_code_not_a_list() {
    silent(
        "Intro.\n\n    - a\n\n    see https://example.com/x\n",
        Check::BareUrl,
    );
}

#[test]
fn an_item_continuation_keeps_the_list_open_across_a_blank_line() {
    fires_once_at(
        "- a\n\n  more\n\n    see https://example.com/x\n",
        Check::BareUrl,
        5,
        9,
    );
}

#[test]
fn an_atx_heading_ends_the_paragraph_so_an_indented_line_is_code() {
    // A heading is a leaf block: no blank line is needed before the block.
    for heading in [
        "# Title",
        "###### Six",
        "   ## Indented",
        "#",
        "## Closed ##",
    ] {
        silent(
            &format!("{heading}\n    see https://example.com/x\n"),
            Check::BareUrl,
        );
    }
}

#[test]
fn text_that_only_resembles_a_heading_does_not_end_the_paragraph() {
    // Seven markers, no space after them and a four-column indent are not ATX
    // headings, so the indented line continues a paragraph.
    for text in ["####### Seven", "#hashtag", "\\# escaped"] {
        fires_once_at(
            &format!("{text}\n    see https://example.com/x\n"),
            Check::BareUrl,
            2,
            9,
        );
    }
}

#[test]
fn a_thematic_break_ends_the_paragraph_so_an_indented_line_is_code() {
    for rule in [
        "---", "***", "___", "- - -", " * * * *", "_\t_\t_", "-----   ",
    ] {
        silent(
            &format!("Text.\n{rule}\n    see https://example.com/x\n"),
            Check::BareUrl,
        );
    }
}

#[test]
fn two_marks_are_not_a_thematic_break() {
    // Each opens a paragraph after the blank line, so the indented line
    // continues it. Directly under a paragraph `--` would be a setext
    // underline instead (see the next test).
    fires_once_at(
        "Text.\n\n--\n    see https://example.com/x\n",
        Check::BareUrl,
        4,
        9,
    );
    // Mixed marks are not a break either.
    fires_once_at(
        "Text.\n\n-*-\n    see https://example.com/x\n",
        Check::BareUrl,
        4,
        9,
    );
}

#[test]
fn a_setext_underline_that_is_not_a_break_does_not_end_a_block_by_itself() {
    // CommonMark 0.31.2, section 4.3: an underline of any length turns the
    // paragraph above into a heading, so the next line could be code. Telling
    // an underline from a lazy list or quote continuation needs container
    // state drep does not track, so these stay text and the line stays prose.
    for underline in ["--", "-", "===", "="] {
        fires_once_at(
            &format!("Text.\n{underline}\n    see https://example.com/x\n"),
            Check::BareUrl,
            3,
            9,
        );
    }
}

#[test]
fn a_thematic_break_that_looks_like_a_list_item_opens_no_list() {
    silent("- - -\n\n    see https://example.com/x\n", Check::BareUrl);
}

#[test]
fn an_unindented_leaf_block_closes_a_list() {
    // Neither a heading nor a break can continue an item without indentation.
    silent(
        "- item\n# Title\n    see https://example.com/x\n",
        Check::BareUrl,
    );
    silent(
        "- item\n***\n    see https://example.com/x\n",
        Check::BareUrl,
    );
}

#[test]
fn an_indented_leaf_block_leaves_the_list_open() {
    fires_once_at(
        "- item\n  # Title\n    see https://example.com/x\n",
        Check::BareUrl,
        3,
        9,
    );
    fires_once_at(
        "- item\n\n  ***\n    see https://example.com/x\n",
        Check::BareUrl,
        4,
        9,
    );
}

#[test]
fn an_indented_hash_line_is_code_not_a_heading() {
    silent(
        "Intro.\n\n    # see https://example.com/x\n",
        Check::BareUrl,
    );
    silent(
        "Intro.\n\n    ---\n    see https://example.com/x\n",
        Check::BareUrl,
    );
}

#[test]
fn a_heading_line_inside_a_fence_ends_nothing() {
    // The `#` line is a shell comment: the list stays open around the fence.
    fires_once_at(
        "- item\n  ```sh\n# comment\n  ```\n\n    see https://example.com/x\n",
        Check::BareUrl,
        6,
        9,
    );
}

#[test]
fn blank_runs_at_either_end_of_a_file_are_runs() {
    fires_once_at("\n\n\n    a\n", Check::MultipleBlankLines, 1, 1);
    fires_once_at("    a\n\n\n\n", Check::MultipleBlankLines, 2, 1);
}

#[test]
fn indent_columns_expands_a_tab_to_the_next_stop() {
    // `mask` only compares the width against zero and four, and any tab within
    // the first four columns reaches four however it is counted, so no document
    // can tell an exact count from an inflated one. The width is pinned here.
    for (line, columns) in [
        ("", 0),
        ("x", 0),
        ("   x", 3),
        ("    x", 4),
        ("\tx", 4),
        (" \tx", 4),
        ("   \tx", 4),
        ("\t x", 5),
        ("    \tx", 8),
        ("\t\tx", 8),
    ] {
        assert_eq!(
            crate::docs::indented::indent_columns(line),
            columns,
            "{line:?}"
        );
    }
}