Skip to content

Commit 62bb108

Browse files
committed
feat(rule): オプションを分割
1 parent 1a2452c commit 62bb108

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ textlint --rule ja-unnatural-alphabet README.md
5656
```json5
5757
{
5858
// 無視するアルファベット
59-
"allow": ["X"]
59+
// 例) ["X"]
60+
// デフォルトでは母音とnを除外
61+
"allow": [
62+
"a", "i", "u", "e", "o", "n"
63+
],
64+
// ビルトインの典型例を除外するかどうか
65+
// 例) C言語
66+
"allowCommonCase": true
6067
}
6168
```
6269

src/textlint-rule-ja-unnatural-alphabet.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,38 @@ const createIgnoreRanges = (input, allowAlphabets) => {
5858
}, []);
5959
};
6060

61+
/**
62+
* ビルトインの無視するリスト
63+
* @type {[*]}
64+
*/
65+
const builtInCommonAllow = [
66+
"/[a-zA-Za-zA-Z]言語/",
67+
"/[x-zX-Z]座標/",
68+
"/[x-zX-Z]軸/",
69+
"Eメール"
70+
];
6171
const defaultOptions = {
6272
// 無視するアルファベット
6373
// 例) ["X"]
64-
// デフォルトでは母音とnと典型例を除外している
74+
// デフォルトでは母音とnを除外
6575
"allow": [
66-
"a", "i", "u", "e", "o",
67-
"n",
68-
"/[a-zA-Za-zA-Z]言語/",
69-
"/[x-zX-Z]座標/",
70-
"/[x-zX-Z]軸/",
71-
"Eメール"
72-
]
76+
"a", "i", "u", "e", "o", "n"
77+
],
78+
// ビルトインの典型例を除外するかどうか
79+
// 例) C言語
80+
"allowCommonCase": true
7381
};
7482
const report = (context, options = {}) => {
7583
const { Syntax, RuleError, report, getSource } = context;
7684
const allowAlphabets = options.allow || defaultOptions.allow;
85+
const allowCommonCase = options.allowCommonCase !== undefined
86+
? options.allowCommonCase
87+
: defaultOptions.allowCommonCase;
88+
const allow = allowCommonCase ? allowAlphabets.concat(builtInCommonAllow) : allowAlphabets;
7789
return {
7890
[Syntax.Str](node){
7991
const text = getSource(node);
80-
const ignoreMatch = createIgnoreRanges(text, allowAlphabets);
92+
const ignoreMatch = createIgnoreRanges(text, allow);
8193
matchUnnaturalAlphabet(text).forEach((actual) => {
8294
const { text, index } = actual;
8395
// 無視する単語を含んでいるなら無視

0 commit comments

Comments
 (0)