Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: added check for spaces at the end of the sentence
Elijah Potterdba1a05eb8a4
diff --git a/harper-core/src/linting/spaces.rs b/harper-core/src/linting/spaces.rsindex 3a2ac5fa8..066b8aabf 100644--- a/harper-core/src/linting/spaces.rs+++ b/harper-core/src/linting/spaces.rs@@ -1,6 +1,6 @@use super::{Lint, Linter};use crate::token::TokenStringExt;-use crate::{document, Document, LintKind, Suggestion, TokenKind};+use crate::{Document, LintKind, Suggestion, Token, TokenKind};#[derive(Debug, Default)]pub struct Spaces;@@ -28,8 +28,57 @@ impl Linter for Spaces {})}}++ if matches!(+ sentence,+ [+ ..,+ Token {+ kind: TokenKind::Word,+ ..+ },+ Token {+ kind: TokenKind::Space(_),+ ..+ },+ Token {+ kind: TokenKind::Punctuation(_),+ ..+ }+ ]+ ) {+ output.push(Lint {+ span: sentence[sentence.len() - 2..sentence.len() - 1]+ .span()+ .unwrap(),+ lint_kind: LintKind::Formatting,+ suggestions: vec![Suggestion::Remove],+ message: "Unnecessary space at the end of the sentence.".to_string(),+ priority: 63+ })+ }}output}}++#[cfg(test)]+mod tests {+ use super::Spaces;+ use crate::linting::tests::assert_lint_count;++ #[test]+ fn detects_space_before_period() {+ let source = "There is a space at the end of this sentence .";++ assert_lint_count(source, Spaces, 1)+ }++ #[test]+ fn allows_period_without_space() {+ let source = "There isn't a space at the end of this sentence.";++ assert_lint_count(source, Spaces, 0)+ }+}diff --git a/harper-core/src/token.rs b/harper-core/src/token.rsindex cbacf09c7..6e24e30e1 100644--- a/harper-core/src/token.rs+++ b/harper-core/src/token.rs@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};use crate::punctuation::Punctuation;use crate::span::Span;-use crate::{Document, Quote};+use crate::Quote;#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Default)]pub struct Token {