Skip to content

Commit 0779997

Browse files
committed
fix(rule): Strが空の文字列である場合でもエラーを投げないように
https://twitter.com/chezou/status/838726472923664385
1 parent 5466a60 commit 0779997

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/no-dropping-the-ra.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,25 @@ function isKoreru(token) {
2323

2424
module.exports = function(context) {
2525
const helper = new RuleHelper(context);
26-
let {Syntax, report, getSource, RuleError} = context;
26+
const {Syntax, report, getSource, RuleError} = context;
2727
return {
2828
[Syntax.Str](node){
2929
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
3030
return;
3131
}
32-
let text = getSource(node);
32+
const text = getSource(node);
3333
return kuromojin(text).then(tokens => {
3434
tokens.forEach((token) => {
3535
if (isKoreru(token)) {
3636
report(node, new RuleError("ら抜き言葉を使用しています。", {
3737
index: (token.word_position)
3838
}));
39-
};
39+
}
4040
});
41-
41+
// tokenのペアがない場合は無視する
42+
if (tokens.length <= 1) {
43+
return;
44+
}
4245
tokens.reduce((prev, current) => {
4346
if (isTargetVerb(prev) && isRaWord(current)) {
4447
report(node, new RuleError("ら抜き言葉を使用しています。", {

test/no-double-joshi-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import assert from "power-assert";
21
import rule from "../src/no-dropping-the-ra";
32
import TextLintTester from "textlint-tester";
4-
var tester = new TextLintTester();
3+
const tester = new TextLintTester();
54
tester.run("no-dropping-the-ra", rule, {
65
valid: [
76
"お刺身を食べられない。",
87
"見られる",
98
"出られる",
10-
"来られる"
9+
"来られる",
10+
"![](http://example.com)",
11+
"[](http://example.com)"
1112
],
1213
invalid: [
1314
{

0 commit comments

Comments
 (0)