Skip to content

Commit 7dccdca

Browse files
committed
feat(textlint): fixer support
- Update textlint-rule-prh for fixer support - Update textlint-tester for fixer - Update README about fixer
1 parent 0497911 commit 7dccdca

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# textlint-rule-preset-JTF-style [![Build Status](https://travis-ci.org/azu/textlint-rule-preset-JTF-style.svg?branch=master)](https://travis-ci.org/azu/textlint-rule-preset-JTF-style)
1+
# textlint-rule-preset-JTF-style [![textlint rule](https://img.shields.io/badge/textlint-fixable-green.svg?style=social)](https://textlint.github.io/) [![Build Status](https://travis-ci.org/azu/textlint-rule-preset-JTF-style.svg?branch=master)](https://travis-ci.org/azu/textlint-rule-preset-JTF-style)
22

33
[JTF日本語標準スタイルガイド(翻訳用)](https://www.jtf.jp/jp/style_guide/styleguide_top.html "JTF日本語標準スタイルガイド(翻訳用)") for [textlint](https://github.com/textlint/textlint "textlint").
44

@@ -54,6 +54,22 @@ npm run-script経由で実行すれば、`node_modules/.bin/`は省略出来ま
5454

5555
- [npm で依存もタスクも一元化する - Qiita](http://qiita.com/Jxck_/items/efaff21b977ddc782971#%E3%82%BF%E3%82%B9%E3%82%AF%E3%81%AE%E5%AE%9F%E8%A1%8C "npm で依存もタスクも一元化する - Qiita")
5656

57+
## 自動修正
58+
59+
使用するルールの設定が終わったら、`textlint`を実行してみてください。
60+
沢山のエラーが表示されると思います。
61+
62+
[![textlint rule](https://img.shields.io/badge/textlint-fixable-green.svg?style=social)](https://textlint.github.io/)
63+
64+
`textlint-rule-preset-JTF-style`の一部ルールは`textlint``--fix`にも対応しています。
65+
`--fix`を使うことで機械的に判断して修正出来る部分は自動修正します。
66+
67+
```sh
68+
textlint --fix /path/to/target.md
69+
```
70+
71+
実際にファイルを書き換えるので、必ずファイルをコピーしておくなどしてファイルを戻せるようにしてから実行してください。
72+
5773
### サンプル
5874

5975
[example/](example/) に実行できるサンプルプロジェクトがあります。

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"author": "azu",
1212
"license": "MIT",
1313
"devDependencies": {
14-
"textlint": "^5.5.2-0",
14+
"textlint": "^5.5.3",
1515
"textlint-rule-preset-jtf-style": "file:.."
1616
}
1717
}

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"glob": "^7.0.0",
4242
"mocha": "^2.3.3",
4343
"textlint": "^5.5.2-0",
44-
"textlint-tester": "^0.5.1-0"
44+
"textlint-tester": "^0.5.1"
4545
},
4646
"dependencies": {
4747
"analyze-desumasu-dearu": "^2.1.2",
@@ -50,9 +50,6 @@
5050
"regx": "^1.0.4",
5151
"sorted-joyo-kanji": "^0.2.0",
5252
"textlint-rule-helper": "^1.1.3",
53-
"textlint-rule-prh": "^2.0.0"
54-
},
55-
"peerDependencies": {
56-
"textlint": ">= 5.1.0 || 5.5.2-0"
53+
"textlint-rule-prh": "^2.4.0"
5754
}
5855
}

src/2.1.5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function toZenkaku(string) {
2828
function reporter(context) {
2929
let {Syntax, fixer, report, getSource} = context;
3030
// 辞書ベースのカタカタ表記のチェックを行う
31-
let dictRule = prh(context, {
31+
let dictRule = prh.fixer(context, {
3232
rulePaths: [path.join(__dirname, "..", "dict", "2.1.5.yml")]
3333
});
3434
let originalStrRule = dictRule[Syntax.Str];

src/2.1.6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import prh from "textlint-rule-prh";
1111
import path from "path";
1212
export default function (context) {
1313
// 辞書ベースのカタカナ末尾の長音のチェックを行う
14-
return prh(context, {
14+
return prh.fixer(context, {
1515
rulePaths: [path.join(__dirname, "..", "dict", "2.1.6.yml")]
1616
});
1717
}

src/2.2.1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ JTFスタイルガイドは、ひらがなと漢字の使い分けについて
1717
import prh from "textlint-rule-prh";
1818
import path from "path";
1919
export default function (context) {
20-
return prh(context, {
20+
return prh.fixer(context, {
2121
rulePaths: [path.join(__dirname, "..", "dict", "2.2.1.yml")]
2222
});
2323
}

src/2.2.3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import prh from "textlint-rule-prh";
88
import path from "path";
99
export default function (context) {
10-
return prh(context, {
10+
return prh.fixer(context, {
1111
rulePaths: [path.join(__dirname, "..", "dict", "2.2.3.yml")]
1212
});
1313
}

0 commit comments

Comments
 (0)