Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(stats): store `LintGroupConfig` changes
Elijah Potter88b0aea00ad2
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 1313fc45e..a42a5013b 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -68,7 +68,7 @@ use crate::linting::{closed_compounds, phrase_corrections};use crate::{CharString, Dialect, Document, TokenStringExt};use crate::{Dictionary, MutableDictionary};-#[derive(Debug, Serialize, Deserialize, Default, Clone)]+#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq)]#[serde(transparent)]pub struct LintGroupConfig {inner: HashMap<String, Option<bool>>,@@ -426,9 +426,11 @@ impl Linter for LintGroup {mod tests {use std::sync::Arc;+ use quickcheck::Arbitrary;+use crate::{Dialect, Document, FstDictionary, MutableDictionary, linting::Linter};- use super::LintGroup;+ use super::{LintGroup, LintGroupConfig};#[test]fn can_get_all_descriptions() {diff --git a/harper-stats/src/lib.rs b/harper-stats/src/lib.rsindex d810bc9f6..de7c07771 100644--- a/harper-stats/src/lib.rs+++ b/harper-stats/src/lib.rs@@ -28,8 +28,11 @@ impl Stats {let mut summary = Summary::new();for record in &self.records {- match record.kind {- RecordKind::Lint(lint_kind) => summary.inc_lint_count(lint_kind),+ match &record.kind {+ RecordKind::Lint(lint_kind) => summary.inc_lint_count(*lint_kind),+ RecordKind::LintConfigUpdate(lint_group_config) => {+ summary.final_config = lint_group_config.clone();+ }}}diff --git a/harper-stats/src/record.rs b/harper-stats/src/record.rsindex f1cce59b0..17c215de3 100644--- a/harper-stats/src/record.rs+++ b/harper-stats/src/record.rs@@ -1,6 +1,6 @@use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH};-use harper_core::linting::LintKind;+use harper_core::linting::{LintGroupConfig, LintKind};use serde::{Deserialize, Serialize};use uuid::Uuid;@@ -23,21 +23,34 @@ impl Record {}}-#[derive(Debug, Deserialize, Serialize, Clone, Copy, Eq, PartialEq)]+#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)]pub enum RecordKind {Lint(LintKind),+ LintConfigUpdate(LintGroupConfig),}#[cfg(test)]mod tests {- use harper_core::linting::LintKind;+ use harper_core::linting::{LintGroupConfig, LintKind};use quickcheck::Arbitrary;use super::{Record, RecordKind};+ fn arbitrary_lintconfig(g: &mut quickcheck::Gen) -> LintGroupConfig {+ let mut config = LintGroupConfig::default();++ for _ in 0..g.size() {+ config.set_rule_enabled(String::arbitrary(g), bool::arbitrary(g));+ }++ config+ }+impl Arbitrary for RecordKind {fn arbitrary(g: &mut quickcheck::Gen) -> Self {- *g.choose(&[+ let lcu = Self::LintConfigUpdate(arbitrary_lintconfig(g));++ g.choose(&[Self::Lint(LintKind::Spelling),Self::Lint(LintKind::Capitalization),Self::Lint(LintKind::Style),@@ -47,8 +60,10 @@ mod tests {Self::Lint(LintKind::Readability),Self::Lint(LintKind::WordChoice),Self::Lint(LintKind::Miscellaneous),+ lcu,]).unwrap()+ .clone()}}diff --git a/harper-stats/src/summary.rs b/harper-stats/src/summary.rsindex 5d2a492fa..ae4dd7962 100644--- a/harper-stats/src/summary.rs+++ b/harper-stats/src/summary.rs@@ -1,15 +1,17 @@use std::{collections::HashMap, fmt::Display};-use harper_core::linting::LintKind;+use harper_core::linting::{LintGroupConfig, LintKind};pub struct Summary {- lint_counts: HashMap<LintKind, usize>,+ pub lint_counts: HashMap<LintKind, usize>,+ pub final_config: LintGroupConfig,}impl Summary {pub fn new() -> Self {Self {lint_counts: HashMap::new(),+ final_config: LintGroupConfig::default(),}}@@ -22,7 +24,7 @@ impl Summary {}/// Get the count for a particular lint kind.- pub fn get(&self, kind: LintKind) -> usize {+ pub fn get_count(&self, kind: LintKind) -> usize {self.lint_counts.get(&kind).copied().unwrap_or(0)}}