Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into typst-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Jan 20, 2025
2 parents 89e1951 + 1a2e72a commit 1e6cb14
Show file tree
Hide file tree
Showing 27 changed files with 238 additions and 92 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Fuzz

on:
schedule:
- cron: "*/10 * * * *"

env:
CARGO_TERM_COLOR: always
# Run for 100 times the default
QUICKCHECK_TESTS: 10000

jobs:
precommit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: harden-title-case
- uses: extractions/setup-just@v2
- name: Test
run: cargo test
2 changes: 2 additions & 0 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

env:
CARGO_TERM_COLOR: always
# Run for 100 times the default
QUICKCHECK_TESTS: 10000

jobs:
precommit:
Expand Down
2 changes: 2 additions & 0 deletions harper-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use harper_core::parsers::{Markdown, MarkdownOptions};
use harper_core::{remove_overlaps, Dictionary, Document, FstDictionary, TokenKind};
use harper_literate_haskell::LiterateHaskellParser;

/// A debugging tool for the Harper grammar checker.
#[derive(Debug, Parser)]
#[command(version, about)]
enum Args {
/// Lint a provided document.
Lint {
Expand Down
2 changes: 1 addition & 1 deletion harper-comments/src/comment_parsers/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub(super) fn mark_inline_tags(tokens: &mut [Token]) {
}
}

/// Checks if the provided token slice begins with an inline tag, returning it's
/// Checks if the provided token slice begins with an inline tag, returning its
/// end if so.
fn parse_inline_tag(tokens: &[Token]) -> Option<usize> {
if !matches!(
Expand Down
1 change: 1 addition & 0 deletions harper-core/dictionary.dict
Original file line number Diff line number Diff line change
Expand Up @@ -49771,3 +49771,4 @@ Harper/SM
a8c/SM
a11n/1
a12s/9
intergenerational
16 changes: 16 additions & 0 deletions harper-core/src/lexing/email_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub fn lex_email_address(source: &[char]) -> Option<FoundToken> {

let domain_part_len = lex_hostname(&source[at_loc + 1..])?;

if domain_part_len == 0 {
return None;
}

Some(FoundToken {
next_index: at_loc + 1 + domain_part_len,
token: TokenKind::EmailAddress,
Expand Down Expand Up @@ -155,6 +159,18 @@ mod tests {
}
}

#[test]
fn does_not_allow_empty_domain() {
for local in example_local_parts() {
// Generate invalid email address
let mut address = local.clone();
address.push('@');
address.push(' ');

assert!(lex_email_address(&address).is_none());
}
}

/// Tests that the email parser will not throw a panic under some random
/// situations.
#[test]
Expand Down
13 changes: 13 additions & 0 deletions harper-core/src/lexing/hostname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ pub fn lex_hostname_token(source: &[char]) -> Option<FoundToken> {
pub fn lex_hostname(source: &[char]) -> Option<usize> {
let mut passed_chars = 0;

// The beginning has different requirements from the rest of the hostname.
let first = source.first()?;

if !matches!(first, 'A'..='Z' | 'a'..='z' | '0'..='9' ) {
return None;
}

for label in source.split(|c| *c == '.') {
for c in label {
passed_chars += 1;
Expand Down Expand Up @@ -78,4 +85,10 @@ pub mod tests {
assert_eq!(lex_hostname(&domain), Some(domain.len()));
}
}

#[test]
fn hyphen_cannot_open_hostname() {
let host: Vec<_> = "-something.com".chars().collect();
assert!(lex_hostname(&host).is_none())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ impl PatternLinter for AvoidContraction {
vec!['y', 'o', 'u', 'r'],
word,
)],
message: "I appears you intended to use the possessive version of this word".to_owned(),
message: "It appears you intended to use the possessive version of this word"
.to_owned(),
priority: 63,
}
}

fn description(&self) -> &'static str {
"This rule looks for situations where a contraction was used where it shouldn't."
"This rule looks for situations where a contraction was used where it shouldn't have been."
}
}

Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/linting/spelled_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Linter for SpelledNumbers {
}
}

/// Converts a number to it's spelled-out variant.
/// Converts a number to its spelled-out variant.
///
/// For example: 100 -> one hundred.
///
Expand Down
35 changes: 34 additions & 1 deletion harper-core/src/parsers/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Markdown {

/// Remove hidden Wikilink target text.
///
/// As in, the stuff to the left of the pipe operator:
/// As in the stuff to the left of the pipe operator:
///
/// ```markdown
/// [[Target text|Display Text]]
Expand All @@ -46,6 +46,10 @@ impl Markdown {
let mut to_remove = VecDeque::new();

for pipe_idx in tokens.iter_pipe_indices() {
if pipe_idx < 2 {
continue;
}

// Locate preceding `[[`
let mut cursor = pipe_idx - 2;
let mut open_bracket = None;
Expand Down Expand Up @@ -351,6 +355,35 @@ mod tests {
))
}

#[test]
fn just_pipe() {
let source = r"|";

let tokens = Markdown::default().parse_str(source);

let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();

dbg!(&token_kinds);

assert!(matches!(
token_kinds.as_slice(),
&[TokenKind::Punctuation(Punctuation::Pipe)]
))
}

#[test]
fn empty_wikilink_text() {
let source = r"[[|]]";

let tokens = Markdown::default().parse_str(source);

let token_kinds = tokens.iter().map(|t| t.kind).collect::<Vec<_>>();

dbg!(&token_kinds);

assert!(matches!(token_kinds.as_slice(), &[]))
}

#[test]
fn improper_wikilink_text() {
let source = r"this is shown|this is also shown]]";
Expand Down
2 changes: 1 addition & 1 deletion harper-core/src/parsers/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
let mut last_allowed: Option<Span> = None;

for (span, content) in mask.iter_allowed(source) {
// Check if there was a line break between the last chunk.
// Check for a line break separating the current chunk from the preceding one.
if let Some(last_allowed) = last_allowed {
let intervening = Span::new(last_allowed.end, span.start);

Expand Down
3 changes: 1 addition & 2 deletions harper-core/src/patterns/is_not_title_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ impl<D: Dictionary> Pattern for IsNotTitleCase<D> {
}

let matched_chars = tokens[0..inner_match].span().unwrap().get_content(source);

if make_title_case(tokens, source, &self.dict) != matched_chars {
if make_title_case(&tokens[0..inner_match], source, &self.dict) != matched_chars {
inner_match
} else {
0
Expand Down
Loading

0 comments on commit 1e6cb14

Please sign in to comment.