Skip to content

Commit b22399b

Browse files
takahashimazu
authored andcommitted
feat(option): add new option allowed_joshi (#11)
* feat(option): add new option allowed_joshi * rename: allowed_joshi -> allow
1 parent 5f6a53d commit b22399b

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Via `.textlintrc`(推奨)
2929
"rules": {
3030
"no-doubled-joshi": {
3131
"min_interval" : 1,
32-
"strict": false
32+
"strict": false,
33+
"allow": []
3334
}
3435
}
3536
}
@@ -53,7 +54,9 @@ textlint --rule no-doubled-joshi README.md
5354
// 助詞のtoken同士の距離が2以下ならエラー
5455
"min_interval" : 2,
5556
// 例外を許可するかどうか
56-
"strict": false
57+
"strict": false,
58+
// 助詞のうち「も」「や」は複数回の出現を許す
59+
"allow": ["",""]
5760
}
5861
}
5962
}
@@ -63,6 +66,8 @@ textlint --rule no-doubled-joshi README.md
6366
- 指定した間隔値以下で同じ助詞が出現した場合エラーが出力されます。
6467
- `strict`(default: false) :例外もエラーとするかどうか
6568
- 下記参照。例外としているものもエラーとするかどうか
69+
- `allow`(default: []) :複数回の出現を許す助詞
70+
- 並立の助詞など、複数回出現しても無視する助詞を指定します。
6671

6772
> ********好き
6873

src/no-doubled-joshi.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ function matchExceptionRule(tokens) {
5050
*/
5151
const defaultOptions = {
5252
min_interval: 1,
53-
strict: false
53+
strict: false,
54+
allow: []
5455
};
5556

5657
/*
@@ -66,6 +67,7 @@ export default function (context, options = {}) {
6667
// 最低間隔値
6768
const minInterval = options.min_interval || defaultOptions.min_interval;
6869
const isStrict = options.strict || defaultOptions.strict;
70+
const allow = options.allow || defaultOptions.allow;
6971
const {Syntax, report, getSource, RuleError} = context;
7072
return {
7173
[Syntax.Paragraph](node){
@@ -105,6 +107,10 @@ export default function (context, options = {}) {
105107
Object.keys(joshiTokenSurfaceKeyMap).forEach(key => {
106108
const tokens = joshiTokenSurfaceKeyMap[key];
107109
const joshiName = restoreToSurfaceFromKey(key);
110+
// check allow
111+
if (allow.indexOf(joshiName) >= 0) {
112+
return;
113+
}
108114
// strict mode ではない時例外を除去する
109115
if (!isStrict) {
110116
if (matchExceptionRule(tokens)) {

test/no-doubled-joshi-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ tester.run("no-double-joshi", rule, {
1818
// 接続助詞のてが重複は許容
1919
"まずは試していただいて",
2020
// 1個目の「と」は格助詞、2個めの「と」は接続助詞
21-
"ターミナルで「test」**と**入力する**と**、画面に表示されます。"
21+
"ターミナルで「test」**と**入力する**と**、画面に表示されます。",
22+
{
23+
text: "太字も強調も同じように無視されます。",
24+
options: {allow: ["も"]}
25+
},
2226
],
2327
invalid: [
2428
// エラー位置は最後の助詞の位置を表示する

0 commit comments

Comments
 (0)