bend-lint 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,39 @@
1
1
  import Base
2
- import bend-lint-api@0.2.2.0/shared/lists.bend as Lists
3
- import bend-lint-api@0.2.2.0/shared/names.bend as Names
4
- import bend-lint-api@0.2.2.0/shared/strings.bend as Strings
5
- import ../text/main.bend as Text
6
- import bend-lint-api@0.2.2.0/linter/lint.bend as Lint
2
+ import bend-lint-api@0.3.1.0/shared.bend as Shared
3
+ import bend-lint-api@0.3.1.0/linter/api/impl.bend as LintImpl
4
+ import bend-lint-api@0.3.1.0/linter/api/spec.bend as Lint
5
+ import ../shared/text/impl.bend as TextImpl
6
+ import ../shared/text/spec.bend as Text
7
+ import ./spec.bend as Spec
7
8
 
8
- # Scanning
9
- # ========
9
+ type Action is Data:
10
+ Disable{}
11
+ Expect{}
12
+
13
+ type Scope is Data:
14
+ WholeFile{}
15
+ Begin{}
16
+ End{}
17
+ NextLine{}
18
+ SameLine{}
19
+
20
+ type Linted is Data:
21
+ Linted{path: String, text: String, known: List<&2, String>, ran: List<&2, String>}
22
+
23
+ def Spec.Action():
24
+ Action
10
25
 
11
- # A comment: where it is (code points), its line (from 0), whether code comes before it on its line, and its text
12
- # after the #.
13
- type Comment is Data:
14
- Comment{beg: U32, end: U32, line: U32, trailing: Bool, body: String}
26
+ def Spec.Scope():
27
+ Scope
15
28
 
29
+ def Spec.Linted():
30
+ Linted
31
+
32
+ def Spec.Linted.of(path, text, known, ran):
33
+ Linted{path, text, known, ran}
34
+
35
+ # Scanning
36
+ # ========
16
37
  type Glyph is Data:
17
38
  LineEnd{}
18
39
  CarriageReturn{}
@@ -37,14 +58,11 @@ type Scan is Data:
37
58
  at: U32,
38
59
  line: U32,
39
60
  code: Bool,
40
- open: Comment,
41
- comments: List<&2, Comment>,
61
+ open: Spec.Comment,
62
+ comments: List<&2, Spec.Comment>,
42
63
  lines: List<&2, Bool>
43
64
  }
44
65
 
45
- type Scanned is Data:
46
- Scanned{comments: List<&2, Comment>, lines: List<&2, Bool>}
47
-
48
66
  def Glyph.of(+c: Char) -> Glyph:
49
67
  Bool.pick(
50
68
  Glyph,
@@ -79,34 +97,42 @@ def Glyph.of(+c: Char) -> Glyph:
79
97
  )
80
98
 
81
99
  # No comment: what the scan holds as its open comment outside one.
82
- def Comment.none() -> Comment:
83
- Comment{0, 0, 0, False{}, ""}
100
+ def Comment.none() -> Spec.Comment:
101
+ Spec.Comment{0, 0, 0, False{}, ""}
84
102
 
85
103
  # The comment `open`, ended at `at`, its body in order.
86
- def Comment.closed(open: Comment, at: U32) -> Comment:
104
+ def Comment.closed(open: Spec.Comment, at: U32) -> Spec.Comment:
87
105
  match open:
88
- case Comment{beg, end, line, trailing, body}:
89
- Comment{beg, at, line, trailing, String.reverse(body)}
106
+ case Spec.Comment{beg, end, line, trailing, body}:
107
+ Spec.Comment{beg, at, line, trailing, String.reverse(body)}
90
108
 
91
- def Comment.push(open: Comment, c: Char) -> Comment:
109
+ def Comment.push(open: Spec.Comment, c: Char) -> Spec.Comment:
92
110
  match open:
93
- case Comment{beg, end, line, trailing, body}:
94
- Comment{beg, end, line, trailing, SCon{c, body}}
111
+ case Spec.Comment{beg, end, line, trailing, body}:
112
+ Spec.Comment{beg, end, line, trailing, SCon{c, body}}
95
113
 
96
114
  def Scan.in_code(
97
115
  glyph: Glyph,
98
116
  +at: U32,
99
117
  +line: U32,
100
118
  +code: Bool,
101
- open: Comment,
102
- comments: List<&2, Comment>,
119
+ open: Spec.Comment,
120
+ comments: List<&2, Spec.Comment>,
103
121
  lines: List<&2, Bool>
104
122
  ) -> Scan:
105
123
  match glyph:
106
124
  case LineEnd{}:
107
125
  Scan{InCode{}, (at + 1: U32), (line + 1: U32), False{}, open, comments, code <> lines}
108
126
  case Hash{}:
109
- Scan{InComment{}, (at + 1: U32), line, code, Comment{at, at, line, code, ""}, comments, lines}
127
+ Scan{
128
+ InComment{},
129
+ (at + 1: U32),
130
+ line,
131
+ code,
132
+ Spec.Comment{at, at, line, code, ""},
133
+ comments,
134
+ lines
135
+ }
110
136
  case DoubleQuote{}:
111
137
  Scan{InQuote{True{}, False{}}, (at + 1: U32), line, True{}, open, comments, lines}
112
138
  case SingleQuote{}:
@@ -124,8 +150,8 @@ def Scan.in_comment(
124
150
  +at: U32,
125
151
  line: U32,
126
152
  code: Bool,
127
- open: Comment,
128
- comments: List<&2, Comment>,
153
+ open: Spec.Comment,
154
+ comments: List<&2, Spec.Comment>,
129
155
  lines: List<&2, Bool>
130
156
  ) -> Scan:
131
157
  match glyph:
@@ -171,8 +197,8 @@ def Scan.in_quote(
171
197
  at: U32,
172
198
  line: U32,
173
199
  code: Bool,
174
- open: Comment,
175
- comments: List<&2, Comment>,
200
+ open: Spec.Comment,
201
+ comments: List<&2, Spec.Comment>,
176
202
  lines: List<&2, Bool>
177
203
  ) -> Scan:
178
204
  match escaped glyph:
@@ -213,42 +239,21 @@ def Scan.go(text: String, s: Scan) -> Scan:
213
239
  case SCon{+c, t}:
214
240
  Scan.go(t, Scan.step(Glyph.of(c), c, s))
215
241
 
216
- def Scan.done(s: Scan) -> Scanned:
242
+ def Scan.done(s: Scan) -> Spec.Scanned:
217
243
  match s:
218
244
  case Scan{InComment{}, at, line, code, open, comments, lines}:
219
- Scanned{
220
- List.reverse(&2, Comment, Comment.closed(open, at) <> comments),
245
+ Spec.Scanned{
246
+ List.reverse(&2, Spec.Comment, Comment.closed(open, at) <> comments),
221
247
  List.reverse(&2, Bool, code <> lines)
222
248
  }
223
249
  case Scan{mode, at, line, code, open, comments, lines}:
224
- Scanned{List.reverse(&2, Comment, comments), List.reverse(&2, Bool, code <> lines)}
250
+ Spec.Scanned{List.reverse(&2, Spec.Comment, comments), List.reverse(&2, Bool, code <> lines)}
225
251
 
226
- def Scan.of(text: String) -> Scanned:
252
+ def Spec.Scan.of(text):
227
253
  Scan.done(Scan.go(text, Scan{InCode{}, 0, 0, False{}, Comment.none(), [], []}))
228
254
 
229
255
  # Parsing
230
256
  # =======
231
- type Action is Data:
232
- Disable{}
233
- Expect{}
234
-
235
- type Scope is Data:
236
- WholeFile{}
237
- Begin{}
238
- End{}
239
- NextLine{}
240
- SameLine{}
241
-
242
- type Keyword is Data:
243
- Keyword{action: Action, scope: Scope}
244
-
245
- # What a directive names: a rule, and the severity it pins, as written.
246
- type Target is Data:
247
- Target{rule: String, pinned: Maybe<&2, String>}
248
-
249
- # A directive as written, before its severity and rule are checked: its reasons are the texts after each `--`.
250
- type Draft is Data:
251
- Draft{keyword: Keyword, target: Target, reasons: List<&2, String>}
252
257
 
253
258
  # A directive: what it does, how far, the rule it names, the severity it pins, its comment, and its place among the
254
259
  # file's comments.
@@ -258,23 +263,23 @@ type Directive is Data:
258
263
  scope: Scope,
259
264
  rule: String,
260
265
  severity: Maybe<&2, Lint.Severity>,
261
- comment: Comment,
266
+ comment: Spec.Comment,
262
267
  index: U32
263
268
  }
264
269
 
265
270
  # A comment that says bend-lint: a directive, or what is wrong with it.
266
271
  type Said is Data:
267
272
  Said{directive: Directive}
268
- Wrong{comment: Comment, why: String}
273
+ Wrong{comment: Spec.Comment, why: String}
269
274
 
270
- def Action.show(a: Action) -> String:
275
+ def Spec.Action.show(a):
271
276
  match a:
272
277
  case Disable{}:
273
278
  "disable"
274
279
  case Expect{}:
275
280
  "expect"
276
281
 
277
- def Scope.show(s: Scope) -> String:
282
+ def Spec.Scope.show(s):
278
283
  match s:
279
284
  case WholeFile{}:
280
285
  "file"
@@ -287,11 +292,15 @@ def Scope.show(s: Scope) -> String:
287
292
  case SameLine{}:
288
293
  "line"
289
294
 
290
- def Action.names() -> List<&2, Names.Named<Action>>:
291
- Names.table(~Action, ~Action.show, [Disable{}, Expect{}])
295
+ def Action.names() -> List<&2, Shared.Names.Named<Action>>:
296
+ Shared.Names.table(~Action, ~Spec.Action.show, [Disable{}, Expect{}])
292
297
 
293
- def Scope.names() -> List<&2, Names.Named<Scope>>:
294
- Names.table(~Scope, ~Scope.show, [WholeFile{}, Begin{}, End{}, NextLine{}, SameLine{}])
298
+ def Scope.names() -> List<&2, Shared.Names.Named<Scope>>:
299
+ Shared.Names.table(
300
+ ~Scope,
301
+ ~Spec.Scope.show,
302
+ [WholeFile{}, Begin{}, End{}, NextLine{}, SameLine{}]
303
+ )
295
304
 
296
305
  def Severity.pinned(severity: Maybe<&2, Lint.Severity>) -> String:
297
306
  Maybe.default(&2, String, Maybe.map(&2, Lint.Severity, String, Lint.Severity.show, severity), "")
@@ -329,13 +338,13 @@ def Words.done(w: Words) -> List<&2, String>:
329
338
  def Words.of(s: String) -> List<&2, String>:
330
339
  Words.done(Words.go(s, Words{"", []}))
331
340
 
332
- def Draft.kind(parts: List<&2, String>) -> Maybe<&2, Keyword>:
341
+ def Draft.kind(parts: List<&2, String>) -> Maybe<&2, Spec.Keyword>:
333
342
  match parts:
334
343
  case Con{a, Con{s, Nil{}}}:
335
- do Maybe<&2, Keyword>:
336
- action: Action <- Names.lookup(Action, a, Action.names())
337
- scope: Scope <- Names.lookup(Scope, s, Scope.names())
338
- return Keyword{action, scope}
344
+ do Maybe<&2, Spec.Keyword>:
345
+ action: Action <- Shared.Names.lookup(Action, a, Action.names())
346
+ scope: Scope <- Shared.Names.lookup(Scope, s, Scope.names())
347
+ return Spec.Keyword{action, scope}
339
348
  case _:
340
349
  None{}
341
350
 
@@ -348,15 +357,19 @@ def Draft.is_rule_id(parts: List<&2, String>) -> Bool:
348
357
  False{}
349
358
 
350
359
  # `rule@severity`, split at its @s.
351
- def Draft.target(parts: List<&2, String>) -> Maybe<&2, Target>:
360
+ def Draft.target(parts: List<&2, String>) -> Maybe<&2, Spec.Target>:
352
361
  match parts:
353
362
  case Con{+rule, Nil{}}:
354
- Lists.when(Target, Draft.is_rule_id(String.split(rule, '/')), Target{rule, None{}})
363
+ Shared.Lists.when(
364
+ Spec.Target,
365
+ Draft.is_rule_id(String.split(rule, '/')),
366
+ Spec.Target{rule, None{}}
367
+ )
355
368
  case Con{+rule, Con{p, rest}}:
356
- Lists.when(
357
- Target,
369
+ Shared.Lists.when(
370
+ Spec.Target,
358
371
  Draft.is_rule_id(String.split(rule, '/')),
359
- Target{rule, Some{String.join(p <> rest, "@")}}
372
+ Spec.Target{rule, Some{String.join(p <> rest, "@")}}
360
373
  )
361
374
  case Nil{}:
362
375
  None{}
@@ -398,26 +411,30 @@ def Draft.reason(rest: List<&2, String>) -> Maybe<&2, List<&2, String>>:
398
411
  case Nil{}:
399
412
  Some{[]}
400
413
  case Con{dash, more}:
401
- Lists.when(List<&2, String>, String.eq(dash, "--"), Draft.reasons(more, ([], [])))
414
+ Shared.Lists.when(List<&2, String>, String.eq(dash, "--"), Draft.reasons(more, ([], [])))
402
415
 
403
416
  # The draft of a directive's words, after `bend-lint:`.
404
- def Draft.of(words: List<&2, String>) -> Maybe<&2, Draft>:
417
+ def Draft.of(words: List<&2, String>) -> Maybe<&2, Spec.Draft>:
405
418
  match words:
406
419
  case Con{kind, Con{named, rest}}:
407
- do Maybe<&2, Draft>:
408
- k: Keyword <- Draft.kind(String.split(kind, '-'))
409
- t: Target <- Draft.target(String.split(named, '@'))
420
+ do Maybe<&2, Spec.Draft>:
421
+ k: Spec.Keyword <- Draft.kind(String.split(kind, '-'))
422
+ t: Spec.Target <- Draft.target(String.split(named, '@'))
410
423
  r: List<&2, String> <- Draft.reason(rest)
411
- return Draft{k, t, r}
424
+ return Spec.Draft{k, t, r}
412
425
  case _:
413
426
  None{}
414
427
 
415
428
  def Problem.pinned(pinned: Maybe<&2, String>) -> Maybe<&2, String>:
416
429
  match pinned:
417
430
  case Some{+p}:
418
- Lists.when(
431
+ Shared.Lists.when(
419
432
  String,
420
- Maybe.is_none(&2, Lint.Severity, Names.lookup(Lint.Severity, p, Lint.Severity.names())),
433
+ Maybe.is_none(
434
+ &2,
435
+ Lint.Severity,
436
+ Shared.Names.lookup(Lint.Severity, p, Lint.Severity.names())
437
+ ),
421
438
  p ++ " is not a severity."
422
439
  )
423
440
  case None{}:
@@ -439,7 +456,7 @@ def Problem.reason(scope: Scope, reasons: List<&2, String>) -> Maybe<&2, String>
439
456
  case End{} _:
440
457
  Some{"An end takes no reason; the begin has it."}
441
458
  case _ Con{r, more}:
442
- Lists.when(String, String.is_empty(r), "A reason is required, after `--`.")
459
+ Shared.Lists.when(String, String.is_empty(r), "A reason is required, after `--`.")
443
460
  case _ Nil{}:
444
461
  Some{"A reason is required, after `--`."}
445
462
 
@@ -448,7 +465,11 @@ def Problem.because(action: Action, scope: Scope, reasons: List<&2, String>) ->
448
465
  case Disable{} End{} _:
449
466
  None{}
450
467
  case Disable{} _ Con{r, Con{b, more}}:
451
- Lists.when(String, String.is_empty(b), "Say why it is not an expect, after " ++ Draft.label())
468
+ Shared.Lists.when(
469
+ String,
470
+ String.is_empty(b),
471
+ "Say why it is not an expect, after " ++ Draft.label()
472
+ )
452
473
  case Disable{} _ _:
453
474
  Some{
454
475
  "A disable says why it is not an expect, after its reason: " ++ Draft.label() ++ " <why>"
@@ -475,11 +496,16 @@ def Problem.first(problems: List<&2, Maybe<&2, String>>) -> Maybe<&2, String>:
475
496
  def Rule.is_reserved(namespace: String) -> Bool:
476
497
  String.eq(namespace, "bend-lint")
477
498
 
478
- def Said.checked(why: Maybe<&2, String>, draft: Draft, comment: Comment, index: U32) -> Said:
499
+ def Said.checked(
500
+ why: Maybe<&2, String>,
501
+ draft: Spec.Draft,
502
+ comment: Spec.Comment,
503
+ index: U32
504
+ ) -> Said:
479
505
  match why draft:
480
506
  case Some{w} _:
481
507
  Wrong{comment, w}
482
- case None{} Draft{Keyword{action, scope}, Target{rule, pinned}, reasons}:
508
+ case None{} Spec.Draft{Spec.Keyword{action, scope}, Spec.Target{rule, pinned}, reasons}:
483
509
  Said{
484
510
  Directive{
485
511
  action,
@@ -490,7 +516,7 @@ def Said.checked(why: Maybe<&2, String>, draft: Draft, comment: Comment, index:
490
516
  String,
491
517
  Lint.Severity,
492
518
  pinned,
493
- p => Names.lookup(Lint.Severity, p, Lint.Severity.names())
519
+ p => Shared.Names.lookup(Lint.Severity, p, Lint.Severity.names())
494
520
  ),
495
521
  comment,
496
522
  index
@@ -499,9 +525,9 @@ def Said.checked(why: Maybe<&2, String>, draft: Draft, comment: Comment, index:
499
525
 
500
526
  # What a comment that holds `draft` (or not) says, checked against the rules there are.
501
527
  def Said.of(
502
- draft: Maybe<&2, Draft>,
528
+ draft: Maybe<&2, Spec.Draft>,
503
529
  trailing: Bool,
504
- comment: Comment,
530
+ comment: Spec.Comment,
505
531
  known: List<&2, String>,
506
532
  index: U32
507
533
  ) -> Said:
@@ -513,7 +539,7 @@ def Said.of(
513
539
  ++ Draft.label()
514
540
  ++ " <why> after it."
515
541
  }
516
- case Some{Draft{Keyword{+action, +scope}, Target{+rule, +pinned}, +reasons}}:
542
+ case Some{Spec.Draft{Spec.Keyword{+action, +scope}, Spec.Target{+rule, +pinned}, +reasons}}:
517
543
  Said.checked(
518
544
  Problem.first(
519
545
  [
@@ -522,54 +548,58 @@ def Said.of(
522
548
  Problem.reason(scope, reasons),
523
549
  Problem.because(action, scope, reasons),
524
550
  Problem.line(scope, trailing),
525
- Lists.when(
551
+ Shared.Lists.when(
526
552
  String,
527
- Rule.is_reserved(Strings.before(rule, '/')),
553
+ Rule.is_reserved(Shared.Strings.before(rule, '/')),
528
554
  rule ++ " findings cannot be suppressed."
529
555
  ),
530
- Lists.when(
556
+ Shared.Lists.when(
531
557
  String,
532
558
  Bool.not(List.contains(~String, ~String.eq, known, rule)),
533
559
  "There is no rule " ++ rule ++ "."
534
560
  )
535
561
  ]
536
562
  ),
537
- Draft{Keyword{action, scope}, Target{rule, pinned}, reasons},
563
+ Spec.Draft{Spec.Keyword{action, scope}, Spec.Target{rule, pinned}, reasons},
538
564
  comment,
539
565
  index
540
566
  )
541
567
 
542
- def Draft.read.if(marked: Bool, text: String) -> Maybe<&2, Maybe<&2, Draft>>:
568
+ def Draft.read.if(marked: Bool, text: String) -> Maybe<&2, Maybe<&2, Spec.Draft>>:
543
569
  match marked:
544
570
  case True{}:
545
571
  Some{Draft.of(Words.of(String.drop(text, 10n)))}
546
572
  case False{}:
547
573
  None{}
548
574
 
549
- # What a comment's text says, if it says bend-lint:: a directive's draft, if it is one.
550
- def Draft.read(+body: String) -> Maybe<&2, Maybe<&2, Draft>>:
575
+ def Spec.Draft.read(body):
551
576
  Draft.read.if(String.starts_with(String.trim_start(body), "bend-lint:"), String.trim_start(body))
552
577
 
553
578
  def Said.read.of(
554
- draft: Maybe<&2, Maybe<&2, Draft>>,
555
- +comment: Comment,
579
+ draft: Maybe<&2, Maybe<&2, Spec.Draft>>,
580
+ +comment: Spec.Comment,
556
581
  known: List<&2, String>,
557
582
  index: U32
558
583
  ) -> Maybe<&2, Said>:
559
584
  match draft comment:
560
- case Some{d} Comment{beg, end, line, +trailing, body}:
561
- Some{Said.of(d, trailing, Comment{beg, end, line, trailing, body}, known, index)}
585
+ case Some{d} Spec.Comment{beg, end, line, +trailing, body}:
586
+ Some{Said.of(d, trailing, Spec.Comment{beg, end, line, trailing, body}, known, index)}
562
587
  case None{} _:
563
588
  None{}
564
589
 
565
- def Said.read(+comment: Comment, known: List<&2, String>, index: U32) -> Maybe<&2, Said>:
590
+ def Said.read(+comment: Spec.Comment, known: List<&2, String>, index: U32) -> Maybe<&2, Said>:
566
591
  match comment:
567
- case Comment{beg, end, line, trailing, +body}:
568
- Said.read.of(Draft.read(body), Comment{beg, end, line, trailing, body}, known, index)
592
+ case Spec.Comment{beg, end, line, trailing, +body}:
593
+ Said.read.of(
594
+ Spec.Draft.read(body),
595
+ Spec.Comment{beg, end, line, trailing, body},
596
+ known,
597
+ index
598
+ )
569
599
 
570
600
  # What the comments say, in order, each numbered; `out` holds those so far, last first.
571
601
  def Said.all(
572
- comments: List<&2, Comment>,
602
+ comments: List<&2, Spec.Comment>,
573
603
  +known: List<&2, String>,
574
604
  +index: U32,
575
605
  out: List<&2, Said>
@@ -578,7 +608,12 @@ def Said.all(
578
608
  case Nil{}:
579
609
  List.reverse(&2, Said, out)
580
610
  case Con{c, rest}:
581
- Said.all(rest, known, (index + 1: U32), Lists.push(Said, Said.read(c, known, index), out))
611
+ Said.all(
612
+ rest,
613
+ known,
614
+ (index + 1: U32),
615
+ Shared.Lists.push(Said, Said.read(c, known, index), out)
616
+ )
582
617
 
583
618
  # Pairing
584
619
  # =======
@@ -606,9 +641,9 @@ def Open.latest(
606
641
  case Con{Directive{+a, s, +r, sev, c, i}, rest} None{}:
607
642
  Open.latest(
608
643
  rest,
609
- Lists.when(
644
+ Shared.Lists.when(
610
645
  Directive,
611
- String.eq(Action.show(a), action) && String.eq(r, rule),
646
+ String.eq(Spec.Action.show(a), action) && String.eq(r, rule),
612
647
  Directive{a, s, r, sev, c, i}
613
648
  ),
614
649
  action,
@@ -634,7 +669,7 @@ def Pairing.closing(
634
669
  +index: U32,
635
670
  line: U32,
636
671
  rule: String,
637
- comment: Comment,
672
+ comment: Spec.Comment,
638
673
  p: Pairing
639
674
  ) -> Pairing:
640
675
  match same p:
@@ -647,13 +682,20 @@ def Pairing.close(begin: Maybe<&2, Directive>, end: Directive, p: Pairing) -> Pa
647
682
  match begin end p:
648
683
  case Some{
649
684
  Directive{a, s, r, sev, c, i}
650
- } Directive{ea, es, er, esev, Comment{b, e, +line, t, body}, ei} Pairing{open, closed, wrong}:
685
+ } Directive{
686
+ ea,
687
+ es,
688
+ er,
689
+ esev,
690
+ Spec.Comment{b, e, +line, t, body},
691
+ ei
692
+ } Pairing{open, closed, wrong}:
651
693
  Pairing.closing(
652
694
  Severity.is_eq(sev, esev),
653
695
  i,
654
696
  line,
655
697
  er,
656
- Comment{b, e, line, t, body},
698
+ Spec.Comment{b, e, line, t, body},
657
699
  Pairing{open, closed, wrong}
658
700
  )
659
701
  case None{} Directive{ea, es, er, esev, ec, ei} Pairing{open, closed, wrong}:
@@ -665,7 +707,7 @@ def Pairing.step(said: Said, p: Pairing) -> Pairing:
665
707
  Pairing{Directive{a, Begin{}, r, sev, c, i} <> open, closed, wrong}
666
708
  case Said{Directive{+a, End{}, +r, sev, c, i}} Pairing{+open, closed, wrong}:
667
709
  Pairing.close(
668
- Open.latest(open, None{}, Action.show(a), r),
710
+ Open.latest(open, None{}, Spec.Action.show(a), r),
669
711
  Directive{a, End{}, r, sev, c, i},
670
712
  Pairing{open, closed, wrong}
671
713
  )
@@ -706,7 +748,12 @@ def Lines.next_code(
706
748
  case Nil{} None{}:
707
749
  None{}
708
750
  case Con{code, rest} None{}:
709
- Lines.next_code(rest, Lists.when(U32, code && U32.is_gt(i, after), i), (i + 1: U32), after)
751
+ Lines.next_code(
752
+ rest,
753
+ Shared.Lists.when(U32, code && U32.is_gt(i, after), i),
754
+ (i + 1: U32),
755
+ after
756
+ )
710
757
 
711
758
  def Closed.find(closed: List<&2, Closed>, found: Maybe<&2, U32>, +index: U32) -> Maybe<&2, U32>:
712
759
  match closed found:
@@ -715,7 +762,7 @@ def Closed.find(closed: List<&2, Closed>, found: Maybe<&2, U32>, +index: U32) ->
715
762
  case Nil{} None{}:
716
763
  None{}
717
764
  case Con{Closed{i, line}, rest} None{}:
718
- Closed.find(rest, Lists.when(U32, U32.is_eq(i, index), line), index)
765
+ Closed.find(rest, Shared.Lists.when(U32, U32.is_eq(i, index), line), index)
719
766
 
720
767
  def Covering.next(d: Directive, found: Maybe<&2, U32>) -> Covering:
721
768
  match found:
@@ -734,19 +781,19 @@ def Covering.of(
734
781
  match said:
735
782
  case Said{Directive{a, WholeFile{}, r, sev, c, i}}:
736
783
  Some{Covering{Directive{a, WholeFile{}, r, sev, c, i}, 0, last}}
737
- case Said{Directive{a, SameLine{}, r, sev, Comment{b, e, +l, t, body}, i}}:
738
- Some{Covering{Directive{a, SameLine{}, r, sev, Comment{b, e, l, t, body}, i}, l, l}}
739
- case Said{Directive{a, NextLine{}, r, sev, Comment{b, e, +l, t, body}, i}}:
784
+ case Said{Directive{a, SameLine{}, r, sev, Spec.Comment{b, e, +l, t, body}, i}}:
785
+ Some{Covering{Directive{a, SameLine{}, r, sev, Spec.Comment{b, e, l, t, body}, i}, l, l}}
786
+ case Said{Directive{a, NextLine{}, r, sev, Spec.Comment{b, e, +l, t, body}, i}}:
740
787
  Some{
741
788
  Covering.next(
742
- Directive{a, NextLine{}, r, sev, Comment{b, e, l, t, body}, i},
789
+ Directive{a, NextLine{}, r, sev, Spec.Comment{b, e, l, t, body}, i},
743
790
  Lines.next_code(lines, None{}, 0, l)
744
791
  )
745
792
  }
746
- case Said{Directive{a, Begin{}, r, sev, Comment{b, e, +l, t, body}, +i}}:
793
+ case Said{Directive{a, Begin{}, r, sev, Spec.Comment{b, e, +l, t, body}, +i}}:
747
794
  Some{
748
795
  Covering{
749
- Directive{a, Begin{}, r, sev, Comment{b, e, l, t, body}, i},
796
+ Directive{a, Begin{}, r, sev, Spec.Comment{b, e, l, t, body}, i},
750
797
  l,
751
798
  Maybe.default(&2, U32, Closed.find(closed, None{}, i), last)
752
799
  }
@@ -770,7 +817,7 @@ def Covering.all(
770
817
  lines,
771
818
  closed,
772
819
  last,
773
- Lists.push(Covering, Covering.of(s, lines, closed, last), out)
820
+ Shared.Lists.push(Covering, Covering.of(s, lines, closed, last), out)
774
821
  )
775
822
 
776
823
  def Covering.pins(
@@ -830,17 +877,12 @@ def Covering.hits(
830
877
  type Applied is Data:
831
878
  Applied{kept: List<&2, Lint.Found>, suppressed: List<&2, Lint.Found>, used: List<&2, U32>}
832
879
 
833
- # A file's findings after its directives: those that stay, then the findings about its directives, and those a
834
- # directive covers.
835
- type Suppressed is Data:
836
- Suppressed{kept: List<&2, Lint.Found>, suppressed: List<&2, Lint.Found>}
837
-
838
880
  def Applied.add(hits: List<&2, U32>, found: Lint.Found, a: Applied) -> Applied:
839
881
  match hits a:
840
882
  case Nil{} Applied{kept, suppressed, used}:
841
883
  Applied{found <> kept, suppressed, used}
842
884
  case Con{h, t} Applied{kept, suppressed, used}:
843
- Applied{kept, found <> suppressed, Lists.onto(&2, U32, Con{h, t}, used)}
885
+ Applied{kept, found <> suppressed, Shared.Lists.onto(&2, U32, Con{h, t}, used)}
844
886
 
845
887
  # The findings, each with where it starts (`at`, in order), sorted by the directives that cover their lines.
846
888
  def Applied.go(
@@ -915,7 +957,7 @@ def Unmet.go(
915
957
  match coverings:
916
958
  case Nil{}:
917
959
  List.reverse(&2, Lint.Found, out)
918
- case Con{Covering{Directive{a, s, r, sev, Comment{b, e, l, t, body}, i}, from, to}, rest}:
960
+ case Con{Covering{Directive{a, s, r, sev, Spec.Comment{b, e, l, t, body}, i}, from, to}, rest}:
919
961
  Unmet.go(
920
962
  rest,
921
963
  used,
@@ -931,7 +973,7 @@ def Wrong.found(
931
973
  match saids:
932
974
  case Nil{}:
933
975
  List.reverse(&2, Lint.Found, out)
934
- case Con{Wrong{Comment{b, e, l, t, body}, why}, rest}:
976
+ case Con{Wrong{Spec.Comment{b, e, l, t, body}, why}, rest}:
935
977
  Wrong.found(
936
978
  rest,
937
979
  path,
@@ -958,11 +1000,6 @@ def Found.offsets(founds: List<&2, Lint.Found>, out: List<&2, U32>) -> List<&2,
958
1000
  }:
959
1001
  Found.offsets(rest, beg <> out)
960
1002
 
961
- # A linted file: its path and text, the ids of the rules there are, and those of the rules that ran on it. A rule
962
- # turned off did not run, so its directives are never unused.
963
- type Linted is Data:
964
- Linted{path: String, text: String, known: List<&2, String>, ran: List<&2, String>}
965
-
966
1003
  def Linted.path(linted: Linted) -> String:
967
1004
  match linted:
968
1005
  case Linted{path, text, known, ran}:
@@ -1015,11 +1052,11 @@ def done(
1015
1052
  unpaired: List<&2, Said>,
1016
1053
  saids: List<&2, Said>,
1017
1054
  +linted: Linted
1018
- ) -> Suppressed:
1055
+ ) -> Spec.Suppressed:
1019
1056
  match a:
1020
1057
  case Applied{kept, suppressed, used}:
1021
- Suppressed{
1022
- Lists.concat(
1058
+ Spec.Suppressed{
1059
+ Shared.Lists.concat(
1023
1060
  &2,
1024
1061
  Lint.Found,
1025
1062
  [
@@ -1038,7 +1075,7 @@ def covered(
1038
1075
  saids: List<&2, Said>,
1039
1076
  +linted: Linted,
1040
1077
  +founds: List<&2, Lint.Found>
1041
- ) -> Suppressed:
1078
+ ) -> Spec.Suppressed:
1042
1079
  done(
1043
1080
  Applied.go(
1044
1081
  founds,
@@ -1058,7 +1095,7 @@ def paired(
1058
1095
  +lines: List<&2, Bool>,
1059
1096
  linted: Linted,
1060
1097
  founds: List<&2, Lint.Found>
1061
- ) -> Suppressed:
1098
+ ) -> Spec.Suppressed:
1062
1099
  match p:
1063
1100
  case Pairing{open, closed, wrong}:
1064
1101
  covered(
@@ -1066,7 +1103,7 @@ def paired(
1066
1103
  saids,
1067
1104
  lines,
1068
1105
  closed,
1069
- (U32.from_nat(Lists.length(&2, Bool, lines)) - 1: U32),
1106
+ (U32.from_nat(Shared.Lists.length(&2, Bool, lines)) - 1: U32),
1070
1107
  []
1071
1108
  ),
1072
1109
  Pairing.unclosed(open, wrong),
@@ -1080,32 +1117,35 @@ def said(
1080
1117
  lines: List<&2, Bool>,
1081
1118
  linted: Linted,
1082
1119
  founds: List<&2, Lint.Found>
1083
- ) -> Suppressed:
1120
+ ) -> Spec.Suppressed:
1084
1121
  paired(Pairing.go(saids, Pairing{[], [], []}), saids, lines, linted, founds)
1085
1122
 
1086
- def scanned(scanned: Scanned, +linted: Linted, founds: List<&2, Lint.Found>) -> Suppressed:
1123
+ def scanned(
1124
+ scanned: Spec.Scanned,
1125
+ +linted: Linted,
1126
+ founds: List<&2, Lint.Found>
1127
+ ) -> Spec.Suppressed:
1087
1128
  match scanned:
1088
- case Scanned{comments, lines}:
1129
+ case Spec.Scanned{comments, lines}:
1089
1130
  said(Said.all(comments, Linted.known(linted), 0, []), lines, linted, founds)
1090
1131
 
1091
- def when(has: Bool, +linted: Linted, founds: List<&2, Lint.Found>) -> Suppressed:
1132
+ def when(has: Bool, +linted: Linted, founds: List<&2, Lint.Found>) -> Spec.Suppressed:
1092
1133
  match has:
1093
1134
  case True{}:
1094
- scanned(Scan.of(Linted.text(linted)), linted, founds)
1135
+ scanned(Spec.Scan.of(Linted.text(linted)), linted, founds)
1095
1136
  case False{}:
1096
- Suppressed{founds, []}
1137
+ Spec.Suppressed{founds, []}
1097
1138
 
1098
- # Whether `text` has a directive's mark, "bend-lint:". Only a 'b' starts a comparison, so it is one pass.
1099
- def has_mark(text: String, found: Bool) -> Bool:
1139
+ def Spec.has_mark(text, found):
1100
1140
  match text found:
1101
1141
  case _ True{}:
1102
1142
  True{}
1103
1143
  case SNil{} False{}:
1104
1144
  False{}
1105
1145
  case SCon{'b', +rest} False{}:
1106
- has_mark(rest, String.starts_with(rest, "end-lint:"))
1146
+ Spec.has_mark(rest, String.starts_with(rest, "end-lint:"))
1107
1147
  case SCon{c, rest} False{}:
1108
- has_mark(rest, False{})
1148
+ Spec.has_mark(rest, False{})
1109
1149
 
1110
- def apply(+linted: Linted, founds: List<&2, Lint.Found>) -> Suppressed:
1111
- when(has_mark(Linted.text(linted), False{}), linted, founds)
1150
+ def Spec.apply(linted, founds):
1151
+ when(Spec.has_mark(Linted.text(linted), False{}), linted, founds)