Skip to content

Commit 93e17ad

Browse files
committed
Merge pull request #8 from orangain/fix-not-reported-issue
Report error correctly when pattern starts with expected value
2 parents 0f1243f + ee0c484 commit 93e17ad

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/prh-rule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ function reporter(context, options = {}) {
7777
// | ----[match------|
7878
var matchedText = slicedText.slice(0, changeSet.matches[0].length);
7979
var expected = matchedText.replace(changeSet.pattern, changeSet.expected);
80-
// Avoid accidental match(ignore case, expected contain actual pattern)
81-
if (slicedText.indexOf(expected) === 0) {
80+
// Avoid accidental match(ignore case)
81+
if (matchedText === expected) {
8282
return;
8383
}
8484
/*

test/fixtures/rule.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ rules:
4848
to: 日経ソフトウエア
4949

5050
- expected: ベンダー
51-
pattern: ベンダ
51+
pattern: /ベンダ(?!ー)/
5252
specs:
5353
- from: ベンダ
5454
to: ベンダー
55+
- from: ベンダー
56+
to: ベンダー
5557
# 単語境界の区別
5658
- expected: js
5759
# pattern: "/\b[JjJj][SsSs]\b/g" # と等価 \b が前後に付与される
@@ -65,3 +67,7 @@ rules:
6567
# 日本語+単語境界の仕様は自分で調べてね…!
6668
- from: 今日もJS祭り
6769
to: 今日もjs祭り
70+
71+
# 全角括弧前後の空白を除去
72+
- expected:
73+
pattern: /) | )/

test/prh-rule-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ describe("prh-rule-test", function () {
2525
});
2626
});
2727
});
28+
context("when match word and s/) /)/ pattern", function () {
29+
it("should report error", function () {
30+
return textlint.lintMarkdown("(図1) ").then(result => {
31+
assert(result.messages.length > 0);
32+
assert(result.messages[0].line === 1);
33+
assert(result.messages[0].column === 4);
34+
});
35+
});
36+
});
2837
context("when match word but s/Web/Web/i pattern", function () {
2938
// fix ignore (the) case
3039
it("should not report", function () {

0 commit comments

Comments
 (0)