def Said.of

bend-lint-rules@0.2.0.0 · lib/linter/directives.bend:500

import bend-lint-rules@0.2.0.0/lib/linter/directives.bend as Directives
import Base
import bend-lint-api@0.2.0.0/shared/lists.bend as Lists
import bend-lint-api@0.2.0.0/shared/strings.bend as Strings

500# What a comment that holds `draft` (or not) says, checked against the rules there are.
501def Said.of(
502  draft: Maybe<&2, Draft>,
503  trailing: Bool,
504  comment: Comment,
505  known: List<&2, String>,
506  index: U32
507) -> Said:
508  match draft:
509    case None{}:
510      Wrong{
511        comment,
512        "Write `# bend-lint: <disable|expect>-<file|begin|end|next|line> <rule>[@severity] -- <reason>`, and, for a disable, "
513          ++ Draft.label()
514          ++ " <why> after it."
515      }
516    case Some{Draft{Keyword{+action, +scope}, Target{+rule, +pinned}, +reasons}}:
517      Said.checked(
518        Problem.first(
519          [
520            Problem.pinned(pinned),
521            Problem.severity(action, Maybe.is_some(&2, String, pinned), rule),
522            Problem.reason(scope, reasons),
523            Problem.because(action, scope, reasons),
524            Problem.line(scope, trailing),
525            Lists.when(
526              String,
527              Rule.is_reserved(Strings.before(rule, '/')),
528              rule ++ " findings cannot be suppressed."
529            ),
530            Lists.when(
531              String,
532              Bool.not(List.contains(~String, ~String.eq, known, rule)),
533              "There is no rule " ++ rule ++ "."
534            )
535          ]
536        ),
537        Draft{Keyword{action, scope}, Target{rule, pinned}, reasons},
538        comment,
539        index
540      )

Uses (27)

Used by (1)