Skip to content

Commit fcbaa66

Browse files
authored
feat(space-between-half-and-full): add option to lint styled nodes (#30)
1 parent ff9d3c9 commit fcbaa66

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/textlint-rule-ja-space-between-half-and-full-width/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ textlint --rule ja-space-between-half-and-full-width README.md
4848
- `exceptPunctuation`: `boolean`
4949
- デフォルト: `true`
5050
- 句読点(、。)を例外として扱うかどうか
51+
- `lintStyledNode`: `boolean`
52+
- デフォルト: `false`
53+
- プレーンテキスト以外(リンクや画像のキャプションなど)を lint の対象とするかどうか (プレーンテキストの判断基準は [textlint/textlint-rule-helper: This is helper library for creating textlint rule](https://github.com/textlint/textlint-rule-helper#rulehelperisplainstrnodenode-boolean) を参照してください)
5154

5255
```json
5356
{

packages/textlint-rule-ja-space-between-half-and-full-width/src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const defaultOptions = {
1212
// "never" or "always"
1313
space: "never",
1414
// [。、,.]を例外とするかどうか
15-
exceptPunctuation: true
15+
exceptPunctuation: true,
16+
// プレーンテキスト以外を対象とするか See https://github.com/textlint/textlint-rule-helper#rulehelperisplainstrnodenode-boolean
17+
lintStyledNode: false,
1618
};
1719
function reporter(context, options = {}) {
1820
const {Syntax, RuleError, report, fixer, getSource} = context;
@@ -21,6 +23,9 @@ function reporter(context, options = {}) {
2123
const exceptPunctuation = options.exceptPunctuation !== undefined
2224
? options.exceptPunctuation
2325
: defaultOptions.exceptPunctuation;
26+
const lintStyledNode = options.lintStyledNode !== undefined
27+
? options.lintStyledNode
28+
: defaultOptions.lintStyledNode;
2429
assert(spaceOption === "always" || spaceOption === "never", `"space" options should be "always" or "never".`);
2530
/**
2631
* `text`を対象に例外オプションを取り除くfilter関数を返す
@@ -76,7 +81,7 @@ function reporter(context, options = {}) {
7681
};
7782
return {
7883
[Syntax.Str](node){
79-
if (!helper.isPlainStrNode(node)) {
84+
if (!lintStyledNode && !helper.isPlainStrNode(node)) {
8085
return;
8186
}
8287
const text = getSource(node);

packages/textlint-rule-ja-space-between-half-and-full-width/test/index-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ Pull Request、コミットのやりかたなどが書かれています。`,
186186
}
187187
]
188188
},
189+
{
190+
text: "[Unicodeのサイト](https://home.unicode.org/)です。",
191+
output: "[Unicode のサイト](https://home.unicode.org/)です。",
192+
options: {
193+
space: "always",
194+
lintStyledNode: true
195+
},
196+
errors: [
197+
{
198+
message: "原則として、全角文字と半角文字の間にスペースを入れます。",
199+
column: 8
200+
}
201+
]
202+
},
189203
{
190204
text: "日本語とenglishの間に半角スペースを入れる",
191205
output: "日本語と english の間に半角スペースを入れる",

0 commit comments

Comments
 (0)