Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["harper-cli", "harper-core", "harper-ls", "harper-comments", "harper-wasm", "harper-tree-sitter", "harper-html", "harper-literate-haskell", "harper-typst", "harper-stats", "harper-pos-utils", "harper-brill", "harper-ink", "harper-python"]
members = ["harper-cli", "harper-core", "harper-ls", "harper-comments", "harper-wasm", "harper-tree-sitter", "harper-html", "harper-literate-haskell", "harper-typst", "harper-stats", "harper-pos-utils", "harper-brill", "harper-ink", "harper-python", "harper-git-commit"]
resolver = "2"

# Comment out the below lines if you plan to use a debugger.
Expand Down
16 changes: 16 additions & 0 deletions harper-git-commit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "harper-git-commit"
version = "0.68.0"
edition = "2024"
description = "The language checker for developers."
license = "Apache-2.0"
repository = "https://github.com/automattic/harper"

[dependencies]
harper-core = { path = "../harper-core", version = "0.68.0" }
harper-tree-sitter = { path = "../harper-tree-sitter", version = "0.68.0" }
tree-sitter-gitcommit = { git = "https://github.com/gbprod/tree-sitter-gitcommit", rev = "a716678c0f00645fed1e6f1d0eb221481dbd6f6d" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, Harper can't include git dependencies. crates.io doesn't allow it. Would it be possible for you to upload the crate to crates.io and reference that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crate is already on crates.io, but it does not have the newest commits in the repo unfortunately. I could ask for a release or use the released version there; however, the version there does not have separate tree-sitter nodes for comments in between actual message lines, meaning that I can't remove those comments from the mask.

I'll ask upstream for a new release and version bump on crates.io.

Sorry, I'm not really knowledgeable about the rust packaging ecosystem, and didn't know that git dependencies aren't allowed when publishing on crates.io.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not really knowledgeable about the rust packaging ecosystem, and didn't know that git dependencies aren't allowed when publishing on crates.io.

Absolutely no worries. Hopefully they'll release an update.

tree-sitter = "0.25.10"

[dev-dependencies]
paste = "1.0.15"
30 changes: 30 additions & 0 deletions harper-git-commit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use harper_core::Token;
use harper_core::parsers::{self, Markdown, MarkdownOptions, Parser};
use harper_tree_sitter::TreeSitterMasker;
use tree_sitter::Node;

pub struct GitCommitParser {
/// Used to grab the text nodes, and parse them as markdown.
inner: parsers::Mask<TreeSitterMasker, Markdown>,
}

impl GitCommitParser {
fn node_condition(n: &Node) -> bool {
matches!(n.kind(), "subject" | "message_line" | "breaking_change")
}

pub fn new(markdown_options: MarkdownOptions) -> Self {
Self {
inner: parsers::Mask::new(
TreeSitterMasker::new(tree_sitter_gitcommit::language(), Self::node_condition),
Markdown::new(markdown_options),
),
}
}
}

impl Parser for GitCommitParser {
fn parse(&self, source: &[char]) -> Vec<Token> {
self.inner.parse(source)
}
}
41 changes: 41 additions & 0 deletions harper-git-commit/tests/run_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use harper_core::linting::{LintGroup, Linter};
use harper_core::parsers::MarkdownOptions;
use harper_core::spell::FstDictionary;
use harper_core::{Dialect, Document};
use harper_git_commit::GitCommitParser;

/// Creates a unit test checking that the linting of a git commit document (in
/// `tests_sources`) produces the expected number of lints.
macro_rules! create_test {
($filename:ident.txt, $correct_expected:expr) => {
paste::paste! {
#[test]
fn [<lints_ $filename _correctly>](){
let source = include_str!(
concat!(
"./test_sources/",
concat!(stringify!($filename), ".txt")
)
);

let dict = FstDictionary::curated();
let document = Document::new(source, &GitCommitParser::new(MarkdownOptions::default()), &dict);

let mut linter = LintGroup::new_curated(dict, Dialect::American);
let lints = linter.lint(&document);

dbg!(&lints);
assert_eq!(lints.len(), $correct_expected);

// Make sure that all generated tokens span real characters
for token in document.tokens(){
assert!(token.span.try_get_content(document.get_source()).is_some());
}
}
}
};
}

create_test!(simple_commit.txt, 1);
create_test!(complex_verbose_commit.txt, 2);
create_test!(conventional_commit.txt, 3);
26 changes: 26 additions & 0 deletions harper-git-commit/tests/test_sources/complex_verbose_commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
This is the the subject

This is a first line without typos
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good tests!

# This is a comment with a typooo that should be ignored
This is a line below the comment with typooos

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
#
# Initial commit
#
# Changes to be committed:
#new file: myfile.txt
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/myfile.txt b/myfile.txt
new file mode 100644
index 0000000..485c415
--- /dev/null
+++ b/myfile.txt
@@ -0,0 +1 @@
+some textt in the file that was added (the typo should be ignored)
17 changes: 17 additions & 0 deletions harper-git-commit/tests/test_sources/conventional_commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
feat(stuff): use session-based authentiation

BREAKING CHANGE: JWT authentication removed. API clients mustt now use
session cookies instead of Authorization headers with bearer tokens.

Sessions expire after 24 hours of inactvity.

Closes: #247
Reviewed-by: John Doe <[email protected]>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Changes to be committed:
# modified: myfile.txt
#
1 change: 1 addition & 0 deletions harper-git-commit/tests/test_sources/simple_commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple commit with a typo: comit
1 change: 1 addition & 0 deletions harper-ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ harper-stats = { path = "../harper-stats", version = "0.68.0" }
harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.68.0" }
harper-core = { path = "../harper-core", version = "0.68.0", features = ["concurrent"] }
harper-comments = { path = "../harper-comments", version = "0.68.0" }
harper-git-commit = { path = "../harper-git-commit", version = "0.68.0" }
harper-typst = { path = "../harper-typst", version = "0.68.0" }
harper-html = { path = "../harper-html", version = "0.68.0" }
harper-python = { path = "../harper-python", version = "0.68.0" }
Expand Down
6 changes: 2 additions & 4 deletions harper-ls/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::sync::Arc;
use crate::config::Config;
use crate::dictionary_io::{load_dict, save_dict};
use crate::document_state::DocumentState;
use crate::git_commit_parser::GitCommitParser;
use crate::ignored_lints_io::{load_ignored_lints, save_ignored_lints};
use crate::io_utils::fileify_path;
use anyhow::{Context, Result, anyhow};
Expand All @@ -19,6 +18,7 @@ use harper_core::parsers::{
};
use harper_core::spell::{Dictionary, FstDictionary, MergedDictionary, MutableDictionary};
use harper_core::{Dialect, DictWordMetadata, Document, IgnoredLints};
use harper_git_commit::GitCommitParser;
use harper_html::HtmlParser;
use harper_ink::InkParser;
use harper_literate_haskell::LiterateHaskellParser;
Expand Down Expand Up @@ -382,9 +382,7 @@ impl Backend {
}
"ink" => Some(Box::new(InkParser::default())),
"markdown" => Some(Box::new(Markdown::new(markdown_options))),
"git-commit" | "gitcommit" => {
Some(Box::new(GitCommitParser::new_markdown(markdown_options)))
}
"git-commit" | "gitcommit" => Some(Box::new(GitCommitParser::new(markdown_options))),
"html" => Some(Box::new(HtmlParser::default())),
"mail" | "plaintext" | "text" => Some(Box::new(PlainEnglish)),
"typst" => Some(Box::new(Typst)),
Expand Down
32 changes: 0 additions & 32 deletions harper-ls/src/git_commit_parser.rs

This file was deleted.

2 changes: 1 addition & 1 deletion harper-ls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod config;
mod diagnostics;
mod dictionary_io;
mod document_state;
mod git_commit_parser;

mod ignored_lints_io;
mod io_utils;
mod pos_conv;
Expand Down
Loading