Skip to content

Commit c0fe3bc

Browse files
committed
feat(rule): ignore specifix node type
1 parent b494db2 commit c0fe3bc

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,25 @@ textlint --rule ja-no-mixed-period README.md
4949
}
5050
```
5151

52-
## 参考情報
53-
54-
- [句点 - Wikipedia](https://ja.wikipedia.org/wiki/%E5%8F%A5%E7%82%B9 "句点 - Wikipedia")
55-
- [小説家になろう Hint&Tips - 区切り符号について](http://ncode.syosetu.com/n8977bb/12/ "小説家になろう Hint&Tips - 区切り符号について")
52+
## 例外
5653

5754
末尾に`。`がない場合でも、代わりに感嘆符や疑問符、括弧などがある場合は例外として扱います。
5855

5956
> これは問題ない文章ですか!?
6057
> 「会話文は括弧で括れば末尾に。がなくても問題ありません」
6158

59+
箇条書きの中はチェックせず無視します。
60+
61+
```
62+
- これは問題ないです
63+
- これも問題ないです
64+
```
65+
66+
## 参考情報
67+
68+
- [句点 - Wikipedia](https://ja.wikipedia.org/wiki/%E5%8F%A5%E7%82%B9 "句点 - Wikipedia")
69+
- [小説家になろう Hint&Tips - 区切り符号について](http://ncode.syosetu.com/n8977bb/12/ "小説家になろう Hint&Tips - 区切り符号について")
70+
6271
## Changelog
6372

6473
See [Releases page](https://github.com/textlint-ja/textlint-rule-ja-no-mixed-period/releases).

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@
3939
"mocha": "^2.5.3",
4040
"power-assert": "^1.4.1",
4141
"textlint-tester": "^2.0.0"
42+
},
43+
"dependencies": {
44+
"textlint-rule-helper": "^2.0.0"
4245
}
43-
}
46+
}

src/textlint-rule-ja-no-mixed-period.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// LICENSE : MIT
22
"use strict";
3+
const RuleHelper = require("textlint-rule-helper").RuleHelper;
34
const exceptionMarkRegExp = /[!?!?\))」 』]/;
45
const defaultPeriodMark = /[。\.]/;
56
const defaultOptions = {
@@ -8,9 +9,14 @@ const defaultOptions = {
89
};
910
const reporter = (context, options = {}) => {
1011
const {Syntax, RuleError, report, fixer, getSource} = context;
12+
const helper = new RuleHelper(context);
1113
const periodMark = options.periodMark || defaultOptions.periodMark;
14+
const ignoredNodeTypes = [Syntax.ListItem, Syntax.Link, Syntax.Code, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis];
1215
return {
1316
[Syntax.Paragraph](node){
17+
if (helper.isChildNode(node, ignoredNodeTypes)) {
18+
return;
19+
}
1420
const lastNode = node.children[node.children.length - 1];
1521
if (lastNode === undefined || lastNode.type !== Syntax.Str) {
1622
return;

test/textlint-rule-ja-no-mixed-period-test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ tester.run("textlint-rule-ja-no-mixed-period", rule, {
77
"1行目。\n2行目。\n3行目。",
88
"1行目。 \nHard Breakを入れるパターン。",
99
"1行目 空白はあるけど末尾に句点はある。",
10-
// 感嘆符などが末尾にある場合は問題なし
11-
"末尾に句点はある!"
10+
// 例外: 感嘆符などが末尾にある場合は問題なし
11+
"末尾に句点はある!",
12+
// 例外のNode type
13+
`- 箇条書きは無視される`,
14+
`![画像の説明も無視される](img/img.png)`,
15+
`[リンクの説明も無視される](http://example.com)`,
16+
`[リンクリファレンスも][]`,
17+
`__強調表示も同じく__`,
18+
`> 引用も無視される`,
1219
],
1320
invalid: [
1421
// single match

0 commit comments

Comments
 (0)