1use harper_core::{
2 linting::{FlatConfig, Lint, LintKind},
3 Document, FatStringToken,
4};
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)]
9pub struct Record {
10 pub kind: RecordKind,
11 pub when: i64,
13 pub uuid: Uuid,
14}
15
16impl Record {
17 pub fn now(kind: RecordKind) -> Self {
19 Self {
20 kind,
21 when: chrono::Utc::now().timestamp(),
22 uuid: Uuid::new_v4(),
23 }
24 }
25}
26
27#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)]
28pub enum RecordKind {
29 Lint {
30 kind: LintKind,
31 context: Vec<FatStringToken>,
32 },
33 LintConfigUpdate(FlatConfig),
34}
35
36impl RecordKind {
37 pub fn from_lint(lint: &Lint, doc: &Document) -> Self {
38 Self::Lint {
39 kind: lint.lint_kind,
40 context: doc
41 .fat_tokens_intersecting(lint.span)
42 .into_iter()
43 .map(|t| t.into())
44 .collect(),
45 }
46 }
47}