Skip to content

Commit

Permalink
fix: check for token.Skip before re-order
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Jun 19, 2024
1 parent 5a7c925 commit 08a5471
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions internal/check/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,17 @@ func sequenceMatches(idx int, chk Sequence, target NLPToken, words []tag.Token)
word := words[jdx-i]
text = append([]string{word.Text}, text...)

mat := tokensMatch(tok, word)
// NOTE: We have to perform this conversion because the token slice is made
// with the right-hand orientation in mind. For example,
//
// optional (start), optional, required (end) -> required, optional, optional
//
// (from right to left).
tok.optional = (tok.optional || tok.end) && !tok.start
if tok.Skip > 0 {
tok.optional = (tok.optional || tok.end) && !tok.start
}

mat := tokensMatch(tok, word)
if !mat && !tok.optional {
return []string{}, index
} else if mat && tok.optional {
Expand Down
1 change: 1 addition & 0 deletions testdata/features/checks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Feature: Checks
test.md:21:5:LanguageTool.APOS_ARE:Did you mean "endpoints" instead of "endpoint's"?
test.md:25:1:LanguageTool.Metadata:Use data and metadata as plural nouns.
test.md:29:1:LanguageTool.Metadata:Use data and metadata as plural nouns.
test.md:31:17:LanguageTool.ARE_USING:Use 'by using' instead of 'using' when it follows a noun for clarity and grammatical correctness.
test.txt:3:4:LanguageTool.WOULD_BE_JJ_VB:The infinitive 'write' after 'be' requries 'to'. Did you mean 'be great *to* write'?
test.txt:9:88:LanguageTool.WOULD_BE_JJ_VB:The infinitive 'come' after 'be' requries 'to'. Did you mean 'be available *to* come'?
test.txt:11:32:LanguageTool.OF_ALL_TIMES:In this context, the idiom needs to be spelled 'of all time'.
Expand Down
1 change: 1 addition & 0 deletions testdata/fixtures/checks/Sequence/.vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ LanguageTool.WOULD_BE_JJ_VB = YES
LanguageTool.OF_ALL_TIMES = YES
LanguageTool.APOS_ARE = YES
LanguageTool.Metadata = YES
LanguageTool.ARE_USING = YES
6 changes: 5 additions & 1 deletion testdata/fixtures/checks/Sequence/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ Metadata for this one purpose is valid.

Metadata for this one two purpose is valid.

Metadata for this purpose is valid.
Metadata for this purpose is valid.

We improved the system using new algorithms.

If you are using the ElasticSearch log store do nothing.
7 changes: 7 additions & 0 deletions testdata/styles/LanguageTool/ARE_USING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
extends: sequence
level: warning
message: Use 'by using' instead of 'using' when it follows a noun for clarity and grammatical correctness.
tokens:
- tag: NN|NNP|NNPS|NNS
- pattern: using

0 comments on commit 08a5471

Please sign in to comment.