Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into literate-haskell
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Dec 31, 2024
2 parents 50a7c14 + 2c9c340 commit 3f75fb0
Show file tree
Hide file tree
Showing 56 changed files with 958 additions and 64 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If you want to use Harper on your machine, you have three choices.

`harper-ls` provides an integration that works for most code editors.

[Read more here.](./harper-ls/README.md)
[Read more here.](https://writewithharper.com/docs/integrations/language-server)

### Harper Obsidian Integration

Expand Down
6 changes: 3 additions & 3 deletions harper-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/automattic/harper"
anyhow = "1.0.95"
ariadne = "0.4.1"
clap = { version = "4.5.23", features = ["derive"] }
harper-core = { path = "../harper-core", version = "0.13.0" }
harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.13.0" }
harper-comments = { path = "../harper-comments", version = "0.13.0" }
harper-core = { path = "../harper-core", version = "0.14.0" }
harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.14.0" }
harper-comments = { path = "../harper-comments", version = "0.14.0" }
serde_json = "1.0.133"
8 changes: 4 additions & 4 deletions harper-comments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "harper-comments"
version = "0.13.0"
version = "0.14.0"
edition = "2021"
description = "The language checker for developers."
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/automattic/harper"

[dependencies]
harper-core = { path = "../harper-core", version = "0.13.0" }
harper-html = { path = "../harper-html", version = "0.13.0" }
harper-tree-sitter = { path = "../harper-tree-sitter", version = "0.13.0" }
harper-core = { path = "../harper-core", version = "0.14.0" }
harper-html = { path = "../harper-html", version = "0.14.0" }
harper-tree-sitter = { path = "../harper-tree-sitter", version = "0.14.0" }
tree-sitter = "0.20.10"
tree-sitter-rust = "0.20.4"
tree-sitter-typescript = "0.20.3"
Expand Down
2 changes: 1 addition & 1 deletion harper-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "harper-core"
version = "0.13.0"
version = "0.14.0"
edition = "2021"
description = "The language checker for developers."
license = "Apache-2.0"
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/an_a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ impl Linter for AnA {

lints
}

fn description(&self) -> &'static str {
"A rule that looks for incorrect indefinite articles. For example, \"this is an mule\" would be flagged as incorrect."
}
}

fn to_lower_word(word: &[char]) -> Cow<'_, [char]> {
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/avoid_curses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl Linter for AvoidCurses {
})
.collect()
}

fn description(&self) -> &'static str {
"A rule that looks for common offensive language."
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/boring_words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ impl PatternLinter for BoringWords {
priority: 127,
}
}

fn description(&self) -> &'static str {
"This rule looks for particularly boring or overused words. Using varied language is an easy way to keep a reader's attention."
}
}
4 changes: 4 additions & 0 deletions harper-core/src/linting/capitalize_personal_pronouns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl Linter for CapitalizePersonalPronouns {

lints
}

fn description(&self) -> &'static str {
"Forgetting to capitalize personal pronouns, like \"I\" or \"I'm\" is one of the most common errors. This rule helps with that."
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/correct_number_suffix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ impl Linter for CorrectNumberSuffix {

output
}

fn description(&self) -> &'static str {
"When making quick edits, it is common for authors to change the value of a number without changing its suffix. This rule looks for these cases, for example: \"2st\"."
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/dot_initialisms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl PatternLinter for DotInitialisms {
priority: 63,
}
}

fn description(&self) -> &'static str {
"Ensures common initialisms (like \"i.e.\") are properly dot-separated."
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/ellipsis_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ impl Linter for EllipsisLength {

lints
}

fn description(&self) -> &'static str {
"Make sure you have the correct number of dots in your ellipsis."
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/linking_verbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl Linter for LinkingVerbs {

output
}

fn description(&self) -> &'static str {
"Linking verbs connect nouns to other ideas. Make sure you do not accidentaly link words that aren't nouns."
}
}

#[cfg(test)]
Expand Down
54 changes: 52 additions & 2 deletions harper-core/src/linting/lint_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ use super::long_sentences::LongSentences;
use super::matcher::Matcher;
use super::multiple_sequential_pronouns::MultipleSequentialPronouns;
use super::number_suffix_capitalization::NumberSuffixCapitalization;
use super::proper_noun_capitalization_linters::{
AmazonNames, Americas, AppleNames, AzureNames, ChineseCommunistParty, GoogleNames, Holidays,
MetaNames, MicrosoftNames, UnitedOrganizations,
};
use super::repeated_words::RepeatedWords;
use super::sentence_capitalization::SentenceCapitalization;
use super::spaces::Spaces;
Expand All @@ -29,6 +33,16 @@ use crate::{Dictionary, Document};
macro_rules! create_lint_group_config {
($($linter:ident => $default:expr),*) => {
paste! {
/// A collection of all the descriptions from the composing linters.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
pub struct LintGroupDescriptions<'a> {
$(
#[doc = "The description for the [`" $linter "`] linter."]
pub [<$linter:snake>]: &'a str,
)*
pub spell_check: &'a str
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
pub struct LintGroupConfig {
$(
Expand Down Expand Up @@ -85,10 +99,19 @@ macro_rules! create_lint_group_config {
config,
}
}

pub fn all_descriptions(&self) -> LintGroupDescriptions<'_> {
LintGroupDescriptions {
$(
[<$linter:snake>]: self.[<$linter:snake>].description(),
)*
spell_check: self.spell_check.description(),
}
}
}

impl<T: Dictionary> Linter for LintGroup<T> {
fn lint(&mut self, document: &Document) -> Vec<Lint>{
fn lint(&mut self, document: &Document) -> Vec<Lint> {
let mut lints = Vec::new();

let mut config = self.config.clone();
Expand All @@ -107,6 +130,10 @@ macro_rules! create_lint_group_config {

lints
}

fn description(&self) -> &'static str {
"A collection of linters that can be run as one."
}
}
}
};
Expand All @@ -133,11 +160,34 @@ create_lint_group_config!(
BoringWords => false,
UseGenitive => false,
ThatWhich => true,
CapitalizePersonalPronouns => true
CapitalizePersonalPronouns => true,
Americas => true,
ChineseCommunistParty => true,
UnitedOrganizations => true,
Holidays => true,
AmazonNames => true,
GoogleNames => true,
MetaNames => true,
MicrosoftNames => true,
AppleNames => true,
AzureNames => true
);

impl<T: Dictionary + Default> Default for LintGroup<T> {
fn default() -> Self {
Self::new(LintGroupConfig::default(), T::default())
}
}

#[cfg(test)]
mod tests {
use crate::FullDictionary;

use super::LintGroup;

#[test]
fn can_get_all_descriptions() {
let group = LintGroup::<FullDictionary>::default();
group.all_descriptions();
}
}
5 changes: 5 additions & 0 deletions harper-core/src/linting/long_sentences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ impl Linter for LongSentences {

output
}

fn description(&self) -> &'static str {
"This rule looks for run-on sentences, which can make your work harder to grok.
"
}
}
10 changes: 4 additions & 6 deletions harper-core/src/linting/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ impl Matcher {
"ngram" => "n-gram",
"grammer" => "grammar",
"There","fore" => "Therefore",
"south","America" => "South America",
"South","america" => "South America",
"south","america" => "South America",
"North","america" => "North America",
"north","America" => "North America",
"north","america" => "North America",
"fatal","outcome" => "death",
"geiger","counter" => "Geiger counter",
"veterans","day" => "Veterans Day",
Expand Down Expand Up @@ -364,6 +358,10 @@ impl Linter for Matcher {

lints
}

fn description(&self) -> &'static str {
"A collection of curated rules. A catch-all that will be removed in the future."
}
}

#[cfg(test)]
Expand Down
7 changes: 7 additions & 0 deletions harper-core/src/linting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod matcher;
mod multiple_sequential_pronouns;
mod number_suffix_capitalization;
mod pattern_linter;
mod proper_noun_capitalization_linters;
mod repeated_words;
mod sentence_capitalization;
mod spaces;
Expand All @@ -39,6 +40,10 @@ pub use matcher::Matcher;
pub use multiple_sequential_pronouns::MultipleSequentialPronouns;
pub use number_suffix_capitalization::NumberSuffixCapitalization;
pub use pattern_linter::PatternLinter;
pub use proper_noun_capitalization_linters::{
AmazonNames, Americas, AppleNames, AzureNames, ChineseCommunistParty, GoogleNames, Holidays,
MetaNames, MicrosoftNames, UnitedOrganizations,
};
pub use repeated_words::RepeatedWords;
pub use sentence_capitalization::SentenceCapitalization;
pub use spaces::Spaces;
Expand All @@ -55,10 +60,12 @@ use crate::Document;
#[cfg(not(feature = "concurrent"))]
pub trait Linter {
fn lint(&mut self, document: &Document) -> Vec<Lint>;
fn description(&self) -> &str;
}
#[cfg(feature = "concurrent")]
pub trait Linter: Send + Sync {
fn lint(&mut self, document: &Document) -> Vec<Lint>;
fn description(&self) -> &str;
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/multiple_sequential_pronouns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ impl PatternLinter for MultipleSequentialPronouns {
suggestions,
}
}

fn description(&self) -> &'static str {
"When editing work to change point of view (i.e. first-person or third-person) it is common to add pronouns while neglecting to remove old ones. This rule catches cases where you have multiple disparate pronouns in sequence."
}
}

impl Default for MultipleSequentialPronouns {
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/linting/number_suffix_capitalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ impl Linter for NumberSuffixCapitalization {

output
}

fn description(&self) -> &'static str {
"You should never capitalize number suffixes."
}
}

#[cfg(test)]
Expand Down
6 changes: 6 additions & 0 deletions harper-core/src/linting/pattern_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ pub trait PatternLinter {
/// A simple getter for the pattern to be searched for.
fn pattern(&self) -> &dyn Pattern;
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint;
fn description<'a>(&'a self) -> &'a str;
}

#[cfg(feature = "concurrent")]
pub trait PatternLinter: Send + Sync {
/// A simple getter for the pattern to be searched for.
fn pattern(&self) -> &dyn Pattern;
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint;
fn description(&self) -> &str;
}

impl<L> Linter for L
Expand Down Expand Up @@ -48,4 +50,8 @@ where

lints
}

fn description(&self) -> &str {
self.description()
}
}
Loading

0 comments on commit 3f75fb0

Please sign in to comment.