Skip to content

Commit 6afcfa3

Browse files
yujioramaazu
authored andcommitted
add separatorChars to options for sentenceSplitter's argument (#14)
* add separatorChars to options for sentenceSplitter\'s argument * tweak typo
1 parent b927048 commit 6afcfa3

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ textlint --rule no-doubled-joshi README.md
5656
// 例外を許可するかどうか
5757
"strict": false,
5858
// 助詞のうち「も」「や」は複数回の出現を許す
59-
"allow": ["",""]
59+
"allow": ["",""],
60+
// 文区切り文字の配列
61+
"separatorChars": ["",,"?","!","",""]
6062
}
6163
}
6264
}
@@ -68,6 +70,8 @@ textlint --rule no-doubled-joshi README.md
6870
- 下記参照。例外としているものもエラーとするかどうか
6971
- `allow`(default: []) :複数回の出現を許す助詞
7072
- 並立の助詞など、複数回出現しても無視する助詞を指定します。
73+
- `separatorChars`(default: ["。","?","!","?","!"]) : 文の区切り文字として使用する文字の配列
74+
- ピリオドや全角ピリオドを句点とする文章を評価するときは明示的に指定します。
7175

7276
> ********好き
7377

src/no-doubled-joshi.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function matchExceptionRule(tokens) {
5151
const defaultOptions = {
5252
min_interval: 1,
5353
strict: false,
54-
allow: []
54+
allow: [],
55+
separatorChars: ["。", "?", "!", "?", "!"]
5556
};
5657

5758
/*
@@ -68,6 +69,7 @@ export default function(context, options = {}) {
6869
const minInterval = options.min_interval || defaultOptions.min_interval;
6970
const isStrict = options.strict || defaultOptions.strict;
7071
const allow = options.allow || defaultOptions.allow;
72+
const separatorChars = options.separatorChars || defaultOptions.separatorChars;
7173
const {Syntax, report, getSource, RuleError} = context;
7274
return {
7375
[Syntax.Paragraph](node){
@@ -80,7 +82,7 @@ export default function(context, options = {}) {
8082
return node.type === SentenceSyntax.Sentence;
8183
};
8284
let sentences = splitSentences(text, {
83-
charRegExp: /[\?\!]/
85+
separatorChars: separatorChars
8486
}).filter(isSentenceNode);
8587
return getTokenizer().then(tokenizer => {
8688
const checkSentence = (sentence) => {

test/no-doubled-joshi-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ tester.run("no-double-joshi", rule, {
2222
{
2323
text: "太字も強調も同じように無視されます。",
2424
options: {allow: ["も"]}
25+
},
26+
// 全角ピリオドを文区切り文字に含める
27+
{
28+
text: "画面に表示されます.それ以外には表示されません.",
29+
options: {separatorChars: ["。",".","?","!","?","!"]}
2530
}
2631
],
2732
invalid: [

0 commit comments

Comments
 (0)