Skip to content

Commit

Permalink
feat(space-between-half-and-full): add option to lint styled nodes (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6b committed Jul 22, 2021
1 parent ff9d3c9 commit fcbaa66
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ textlint --rule ja-space-between-half-and-full-width README.md
- `exceptPunctuation`: `boolean`
- デフォルト: `true`
- 句読点(、。)を例外として扱うかどうか
- `lintStyledNode`: `boolean`
- デフォルト: `false`
- プレーンテキスト以外(リンクや画像のキャプションなど)を lint の対象とするかどうか (プレーンテキストの判断基準は [textlint/textlint-rule-helper: This is helper library for creating textlint rule](https://github.com/textlint/textlint-rule-helper#rulehelperisplainstrnodenode-boolean) を参照してください)

```json
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const defaultOptions = {
// "never" or "always"
space: "never",
// [。、,.]を例外とするかどうか
exceptPunctuation: true
exceptPunctuation: true,
// プレーンテキスト以外を対象とするか See https://github.com/textlint/textlint-rule-helper#rulehelperisplainstrnodenode-boolean
lintStyledNode: false,
};
function reporter(context, options = {}) {
const {Syntax, RuleError, report, fixer, getSource} = context;
Expand All @@ -21,6 +23,9 @@ function reporter(context, options = {}) {
const exceptPunctuation = options.exceptPunctuation !== undefined
? options.exceptPunctuation
: defaultOptions.exceptPunctuation;
const lintStyledNode = options.lintStyledNode !== undefined
? options.lintStyledNode
: defaultOptions.lintStyledNode;
assert(spaceOption === "always" || spaceOption === "never", `"space" options should be "always" or "never".`);
/**
* `text`を対象に例外オプションを取り除くfilter関数を返す
Expand Down Expand Up @@ -76,7 +81,7 @@ function reporter(context, options = {}) {
};
return {
[Syntax.Str](node){
if (!helper.isPlainStrNode(node)) {
if (!lintStyledNode && !helper.isPlainStrNode(node)) {
return;
}
const text = getSource(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ Pull Request、コミットのやりかたなどが書かれています。`,
}
]
},
{
text: "[Unicodeのサイト](https://home.unicode.org/)です。",
output: "[Unicode のサイト](https://home.unicode.org/)です。",
options: {
space: "always",
lintStyledNode: true
},
errors: [
{
message: "原則として、全角文字と半角文字の間にスペースを入れます。",
column: 8
}
]
},
{
text: "日本語とenglishの間に半角スペースを入れる",
output: "日本語と english の間に半角スペースを入れる",
Expand Down

0 comments on commit fcbaa66

Please sign in to comment.