Skip to content

Commit 70a3ac1

Browse files
authored
chore(rule): Update prh and format rules (#62)
1 parent 73a5c3e commit 70a3ac1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+709
-646
lines changed

.babelrc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"presets": [
3-
"es2015"
4-
],
5-
"plugins": [
6-
"add-module-exports"
3+
"env"
74
]
85
}

package.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
"prepublish": "npm run --if-present build",
2929
"pretest": "node tool/create-fixtures.js",
3030
"test": "mocha && npm run test:textlint",
31-
"test:textlint": "(cd example && npm i && npm test)"
31+
"test:textlint": "(cd example && npm i && npm test)",
32+
"precommit": "lint-staged",
33+
"postcommit": "git reset",
34+
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css}'"
3235
},
3336
"keywords": [
3437
"textlint",
@@ -38,11 +41,14 @@
3841
],
3942
"devDependencies": {
4043
"babel-cli": "^6.26.0",
41-
"babel-plugin-add-module-exports": "^0.1.2",
44+
"babel-preset-env": "^1.6.0",
4245
"babel-preset-es2015": "^6.24.1",
4346
"babel-register": "^6.26.0",
4447
"glob": "^7.1.2",
48+
"husky": "^0.14.3",
49+
"lint-staged": "^4.2.3",
4550
"mocha": "^3.5.3",
51+
"prettier": "^1.7.0",
4652
"textlint": "^8.2.1",
4753
"textlint-tester": "^2.2.4"
4854
},
@@ -54,10 +60,20 @@
5460
"regexp.prototype.flags": "^1.1.1",
5561
"regx": "^1.0.4",
5662
"sorted-joyo-kanji": "^0.2.0",
57-
"textlint-rule-helper": "^1.2.0",
58-
"textlint-rule-prh": "^4.0.1"
63+
"textlint-rule-helper": "^2.0.0",
64+
"textlint-rule-prh": "^5.0.0"
5965
},
6066
"peerDependencies": {
6167
"textlint": ">= 5.6.0"
68+
},
69+
"prettier": {
70+
"printWidth": 120,
71+
"tabWidth": 4
72+
},
73+
"lint-staged": {
74+
"*.{js,jsx,ts,tsx,css}": [
75+
"prettier --write",
76+
"git add"
77+
]
6278
}
6379
}

src/1.1.1.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,40 @@
1515
常体は、簡潔に、力強い雰囲気で内容を伝えることができる文体です
1616
丁寧ではない印象を読み手に与える場合があるため、通常、一般向けのマニュアルの本文では使われません。
1717
*/
18-
import {analyzeDesumasu, analyzeDearu} from "analyze-desumasu-dearu";
19-
import {RuleHelper} from "textlint-rule-helper";
20-
export default function (context) {
21-
let {Syntax, RuleError, report, getSource} = context;
18+
import { analyzeDesumasu, analyzeDearu } from "analyze-desumasu-dearu";
19+
import { RuleHelper } from "textlint-rule-helper";
20+
module.exports = function(context) {
21+
let { Syntax, RuleError, report, getSource } = context;
2222
let helper = new RuleHelper(context);
2323
let desumasuList = [];
2424
let dearuList = [];
2525

26-
function reportResult(list, {desumasu, dearu}) {
27-
list.forEach(({node, matches}) => {
26+
function reportResult(list, { desumasu, dearu }) {
27+
list.forEach(({ node, matches }) => {
2828
matches.forEach(match => {
2929
let message;
3030
if (desumasu) {
31-
message = `本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が敬体(ですます調)です。`
31+
message = `本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が敬体(ですます調)です。`;
3232
} else if (dearu) {
33-
message = `本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が常体(である調)です。`
33+
message = `本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が常体(である調)です。`;
3434
}
35-
report(node, new RuleError(message, {
36-
line: match.lineNumber - 1,
37-
column: match.columnIndex
38-
}));
35+
report(
36+
node,
37+
new RuleError(message, {
38+
line: match.lineNumber - 1,
39+
column: match.columnIndex
40+
})
41+
);
3942
});
4043
});
4144
}
4245

43-
4446
return {
45-
[Syntax.Document](){
47+
[Syntax.Document]() {
4648
desumasuList = [];
4749
dearuList = [];
4850
},
49-
[Syntax.Str](node){
51+
[Syntax.Str](node) {
5052
// 本文以外は無視する
5153
// => isUserWrittenNode
5254
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
@@ -72,19 +74,19 @@ export default function (context) {
7274
});
7375
}
7476
},
75-
[`${Syntax.Document}:exit`](){
76-
let desumasuCount = desumasuList.reduce((count, {matches}) => count + matches.length, 0);
77-
let dearuCount = dearuList.reduce((count, {matches}) => count + matches.length, 0);
77+
[`${Syntax.Document}:exit`]() {
78+
let desumasuCount = desumasuList.reduce((count, { matches }) => count + matches.length, 0);
79+
let dearuCount = dearuList.reduce((count, { matches }) => count + matches.length, 0);
7880
if (desumasuCount === 0 || dearuCount === 0) {
7981
return;
8082
}
8183
if (desumasuCount > dearuCount) {
82-
reportResult(dearuList, {dearu: true});
84+
reportResult(dearuList, { dearu: true });
8385
} else if (desumasuCount < dearuCount) {
84-
reportResult(desumasuList, {desumasu: true});
86+
reportResult(desumasuList, { desumasu: true });
8587
} else {
86-
reportResult(dearuList, {dearu: true});
88+
reportResult(dearuList, { dearu: true });
8789
}
8890
}
89-
}
90-
}
91+
};
92+
};

src/1.1.2.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Header
1616
1717
は無視する
1818
*/
19-
import {isUserWrittenNode} from "./util/node-util";
19+
import { isUserWrittenNode } from "./util/node-util";
2020
function mixer(context) {
21-
let {Syntax, RuleError, report, getSource, fixer} = context;
21+
let { Syntax, RuleError, report, getSource, fixer } = context;
2222
return {
23-
[Syntax.Header](node){
23+
[Syntax.Header](node) {
2424
if (!isUserWrittenNode(node, context)) {
2525
return;
2626
}
@@ -29,16 +29,19 @@ function mixer(context) {
2929
let matchReg = /(\s*?)$/;
3030
let index = text.search(matchReg);
3131
if (index !== -1) {
32-
report(node, new RuleError("見出しの文末には、句点(。)を付けません。", {
33-
index: index,
34-
fix: fixer.removeRange([index, index + 1])
35-
}));
32+
report(
33+
node,
34+
new RuleError("見出しの文末には、句点(。)を付けません。", {
35+
index: index,
36+
fix: fixer.removeRange([index, index + 1])
37+
})
38+
);
3639
}
3740
// TODO: いずれの場合も、すべての見出しを通して複数の文体をできるだけ混在させないことが重要です。
3841
}
39-
}
42+
};
4043
}
41-
export default {
44+
module.exports = {
4245
linter: mixer,
4346
fixer: mixer
44-
}
47+
};

src/1.1.3.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,51 @@
99
本文が「常体」である場合、箇条書きには「常体」または「体言止め」を使います。「敬体」は使いません。
1010
いずれの場合も、ひとまとまりの箇条書きでは、敬体と常体を混在させません。文末に句点(。)を付けるかどうかも統一します。
1111
*/
12-
import {analyzeDesumasu, analyzeDearu} from "analyze-desumasu-dearu";
13-
export default function (context) {
14-
let {Syntax, RuleError, report, getSource} = context;
12+
import { analyzeDesumasu, analyzeDearu } from "analyze-desumasu-dearu";
13+
module.exports = function(context) {
14+
let { Syntax, RuleError, report, getSource } = context;
1515
let desumasuList = [];
1616
let dearuList = [];
1717
// 。付きのListItem
1818
let withPointList = [];
1919
// 。なしのListItem
2020
let withoutPointList = [];
21-
21+
2222
function resetList() {
2323
dearuList = [];
2424
desumasuList = [];
2525
withPointList = [];
2626
withoutPointList = [];
2727
}
28-
29-
function reportPointResult(nodeList, {shouldUsePoint}) {
28+
29+
function reportPointResult(nodeList, { shouldUsePoint }) {
3030
nodeList.forEach(node => {
3131
let message;
3232
if (shouldUsePoint) {
33-
message = `箇条書きの文末に句点(。)を付けて下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。`
33+
message = `箇条書きの文末に句点(。)を付けて下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。`;
3434
} else {
35-
message = `箇条書きの文末から句点(。)を外して下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。`
35+
message = `箇条書きの文末から句点(。)を外して下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。`;
3636
}
3737
report(node, new RuleError(message));
3838
});
3939
}
40-
41-
function reportDesumaruDearuResult(list, {desumasu,dearu}) {
42-
list.forEach(({node, matches}) => {
40+
41+
function reportDesumaruDearuResult(list, { desumasu, dearu }) {
42+
list.forEach(({ node, matches }) => {
4343
matches.forEach(match => {
4444
let message;
4545
if (desumasu) {
46-
message = `箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が常体(である調)です。`
46+
message = `箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が常体(である調)です。`;
4747
} else if (dearu) {
48-
message = `箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が敬体(ですます調)です。`
48+
message = `箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が敬体(ですます調)です。`;
4949
}
50-
report(node, new RuleError(message, {
51-
line: match.lineNumber - 1,
52-
column: match.columnIndex
53-
}));
50+
report(
51+
node,
52+
new RuleError(message, {
53+
line: match.lineNumber - 1,
54+
column: match.columnIndex
55+
})
56+
);
5457
});
5558
});
5659
}
@@ -80,8 +83,8 @@ export default function (context) {
8083

8184
// 敬体(ですます調)あるいは常体(である調)なのかのチェック
8285
function countingDesumasuDearu(desumasuList, dearuList) {
83-
let desumasuCount = desumasuList.reduce((count, {matches}) => count + matches.length, 0);
84-
let dearuCount = dearuList.reduce((count, {matches}) => count + matches.length, 0);
86+
let desumasuCount = desumasuList.reduce((count, { matches }) => count + matches.length, 0);
87+
let dearuCount = dearuList.reduce((count, { matches }) => count + matches.length, 0);
8588
if (desumasuCount === 0 || dearuCount === 0) {
8689
return;
8790
}
@@ -102,12 +105,12 @@ export default function (context) {
102105
});
103106
}
104107
}
105-
108+
106109
return {
107-
[Syntax.List](node){
108-
resetList()
110+
[Syntax.List](node) {
111+
resetList();
109112
},
110-
[Syntax.ListItem](node){
113+
[Syntax.ListItem](node) {
111114
let text = getSource(node);
112115
// 末尾に。があるかが統一されているのチェック
113116
let matchPointReg = /(\s*?)$/;
@@ -134,10 +137,10 @@ export default function (context) {
134137
});
135138
}
136139
},
137-
[`${Syntax.List}:exit`](node){
140+
[`${Syntax.List}:exit`](node) {
138141
countingPoint(withPointList, withoutPointList);
139-
142+
140143
countingDesumasuDearu(desumasuList, dearuList);
141144
}
142-
}
143-
}
145+
};
146+
};

src/1.1.5.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
99
キャプション間で文体が混ざっていないことを確認する。
1010
*/
11-
import {analyzeDesumasu, analyzeDearu} from "analyze-desumasu-dearu";
12-
export default function (context) {
13-
let {Syntax, RuleError, report, getSource} = context;
11+
import { analyzeDesumasu, analyzeDearu } from "analyze-desumasu-dearu";
12+
module.exports = function(context) {
13+
let { Syntax, RuleError, report, getSource } = context;
1414
let desumasuList = [];
1515
let dearuList = [];
1616

@@ -19,27 +19,30 @@ export default function (context) {
1919
dearuList = [];
2020
}
2121

22-
const imagePaddingLet = 2;// ![ の分paddingを付ける
23-
function reportResult(list, {desumasu,dearu}) {
24-
list.forEach(({node, matches}) => {
22+
const imagePaddingLet = 2; // ![ の分paddingを付ける
23+
function reportResult(list, { desumasu, dearu }) {
24+
list.forEach(({ node, matches }) => {
2525
matches.forEach(match => {
2626
let message;
2727
if (desumasu) {
28-
message = `図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が常体(である調)です。`
28+
message = `図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が常体(である調)です。`;
2929
} else if (dearu) {
30-
message = `図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が敬体(ですます調)です。`
30+
message = `図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が敬体(ですます調)です。`;
3131
}
32-
report(node, new RuleError(message, {
33-
line: match.lineNumber - 1,
34-
column: match.columnIndex + imagePaddingLet
35-
}));
32+
report(
33+
node,
34+
new RuleError(message, {
35+
line: match.lineNumber - 1,
36+
column: match.columnIndex + imagePaddingLet
37+
})
38+
);
3639
});
3740
});
3841
}
3942

4043
return {
4144
[Syntax.Document]: resetState,
42-
[Syntax.Image](node){
45+
[Syntax.Image](node) {
4346
let text = node.alt;
4447
// alt がない場合は無視する
4548
if (text === undefined || text === null) {
@@ -60,9 +63,9 @@ export default function (context) {
6063
});
6164
}
6265
},
63-
[`${Syntax.Document}:exit`](){
64-
let desumasuCount = desumasuList.reduce((count, {matches}) => count + matches.length, 0);
65-
let dearuCount = dearuList.reduce((count, {matches}) => count + matches.length, 0);
66+
[`${Syntax.Document}:exit`]() {
67+
let desumasuCount = desumasuList.reduce((count, { matches }) => count + matches.length, 0);
68+
let dearuCount = dearuList.reduce((count, { matches }) => count + matches.length, 0);
6669
if (desumasuCount === 0 || dearuCount === 0) {
6770
return;
6871
}
@@ -80,5 +83,5 @@ export default function (context) {
8083
});
8184
}
8285
}
83-
}
84-
}
86+
};
87+
};

0 commit comments

Comments
 (0)