Skip to content

Commit 4d99aee

Browse files
committed
fix(review): Re:Viewで脚注がルールの対象に含まれているのをオプション化
checkFootnote(デフォルト: false)で脚注をチェックするかをオプション化した 脚注自体がtextlintの対象として曖昧なので、このオプションはun-documentなものとした
1 parent 7f5ddde commit 4d99aee

File tree

7 files changed

+3170
-38
lines changed

7 files changed

+3170
-38
lines changed

.babelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ english only
6969
- 例外として許可したい文字列を設定する
7070
- `periodMark`に指定したものは自動的に許可リストに加わる
7171
- デフォルトは空 `[]`
72-
- `allowEmojiAtEnd`(bool):
72+
- `allowEmojiAtEnd`: `boolean`
7373
- 絵文字を末尾に置くことを許可するかどうか
74-
- デフォルト: false
74+
- デフォルト: `false`
7575
- `forceAppendPeriod`: `boolean`
7676
- 句点で終わって無い場合に`periodMark`を--fix時に追加するかどうか
77-
- デフォルト: false
77+
- デフォルト: `false`
7878

7979
```json
8080
{

package.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,18 @@
2222
"test": "test"
2323
},
2424
"scripts": {
25-
"test": "mocha test/",
26-
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
27-
"watch": "babel src --out-dir lib --watch --source-maps",
25+
"test": "textlint-scripts test",
26+
"build": "textlint-scripts build",
27+
"watch": "textlint-scripts build --watch",
2828
"prepublish": "npm run --if-present build"
2929
},
3030
"keywords": [
3131
"textlint",
3232
"textlintrule"
3333
],
3434
"devDependencies": {
35-
"babel-cli": "^6.10.1",
36-
"babel-preset-es2015": "^6.9.0",
37-
"babel-preset-jsdoc-to-assert": "^2.0.1",
38-
"babel-preset-power-assert": "^1.0.0",
39-
"babel-register": "^6.9.0",
40-
"mocha": "^2.5.3",
41-
"power-assert": "^1.4.1",
42-
"textlint-tester": "^2.0.0"
35+
"textlint-plugin-review": "^0.3.3",
36+
"textlint-scripts": "^2.1.0"
4337
},
4438
"dependencies": {
4539
"check-ends-with-period": "^1.0.1",

src/textlint-rule-ja-no-mixed-period.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ const defaultOptions = {
2020
allowEmojiAtEnd: false,
2121
// 句点で終わって無い場合に`periodMark`を--fix時に追加するかどうか
2222
// デフォルトでは自動的に追加しない
23-
forceAppendPeriod: false
23+
forceAppendPeriod: false,
24+
// [Note] このオプションは標準外なので隠しオプション扱い
25+
// [Warning] このオプションはsemverの範囲外なのでいつでも壊れる可能性がある
26+
// 脚注はチェック対象から外すかどうか(実質Re:View向け)
27+
// デフォルトでは脚注構文(Re:View)は無視する
28+
checkFootnote: false
2429
};
2530
const reporter = (context, options = {}) => {
2631
const { Syntax, RuleError, report, fixer, getSource } = context;
@@ -30,17 +35,27 @@ const reporter = (context, options = {}) => {
3035
// 優先する句点記号は常に句点として許可される
3136
const allowPeriodMarks = (options.allowPeriodMarks || defaultOptions.allowPeriodMarks).concat(preferPeriodMark);
3237
const allowEmojiAtEnd = options.allowEmojiAtEnd !== undefined
33-
? options.allowEmojiAtEnd
34-
: defaultOptions.allowEmojiAtEnd;
38+
? options.allowEmojiAtEnd
39+
: defaultOptions.allowEmojiAtEnd;
3540
const forceAppendPeriod = options.forceAppendPeriod !== undefined
36-
? options.forceAppendPeriod
37-
: defaultOptions.forceAppendPeriod;
38-
41+
? options.forceAppendPeriod
42+
: defaultOptions.forceAppendPeriod;
43+
const checkFootnote = options.checkFootnote !== undefined
44+
? options.checkFootnote
45+
: defaultOptions.checkFootnote;
46+
// 脚注のNode Typeを定義(TxtASTの定義外)
47+
const FootnoteNodes = [
48+
// https://github.com/orangain/textlint-plugin-review
49+
"Footnote",
50+
// https://github.com/textlint/textlint/blob/master/packages/%40textlint/markdown-to-ast/src/mapping/markdown-syntax-map.js
51+
// 実際にはmarkdown-to-astではこれはParagraphを含まないInlineNodeなのであまり意味はない
52+
"Definition"
53+
];
3954
const ignoredNodeTypes = [
4055
Syntax.ListItem, Syntax.Link, Syntax.Code, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis
41-
];
56+
].concat(checkFootnote ? FootnoteNodes : []);
4257
return {
43-
[Syntax.Paragraph](node){
58+
[Syntax.Paragraph](node) {
4459
if (helper.isChildNode(node, ignoredNodeTypes)) {
4560
return;
4661
}

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--compilers js:babel-register
1+
--require textlint-scripts/register

test/textlint-rule-ja-no-mixed-period-test.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1+
import rule from "../src/textlint-rule-ja-no-mixed-period";
2+
13
const TextLintTester = require("textlint-tester");
4+
const reviewPlugin = require("textlint-plugin-review");
25
const tester = new TextLintTester();
3-
import rule from "../src/textlint-rule-ja-no-mixed-period";
6+
tester.run("Re:view + textlint-rule-ja-no-mixed-period", {
7+
plugins: [
8+
{
9+
pluginId: "review",
10+
plugin: reviewPlugin
11+
}
12+
],
13+
rules: [
14+
{
15+
ruleId: "ja-no-mixed-period",
16+
rule: rule,
17+
options: {
18+
checkFootnote: true
19+
}
20+
},
21+
]
22+
}, {
23+
valid: [
24+
{
25+
text: `//footnote[test][脚注はデフォルトで無視される]`,
26+
ext: ".re"
27+
}
28+
]
29+
});
30+
431
tester.run("textlint-rule-ja-no-mixed-period", rule, {
532
valid: [
633
"これは問題ないです。",
@@ -39,7 +66,15 @@ tester.run("textlint-rule-ja-no-mixed-period", rule, {
3966
options: {
4067
allowPeriodMarks: [":"]
4168
},
69+
},
70+
// 脚注はMarkdownでは常に無視される
71+
{
72+
text: `テストです。[^1]
73+
74+
[^1]: 脚注はデフォルトで無視される`,
75+
ext: ".md"
4276
}
77+
4378
],
4479
invalid: [
4580
// single match
@@ -140,6 +175,6 @@ tester.run("textlint-rule-ja-no-mixed-period", rule, {
140175
column: 11
141176
}
142177
]
143-
},
178+
}
144179
]
145180
});

0 commit comments

Comments
 (0)