Skip to content

Commit f150588

Browse files
committed
style: apply prettier
1 parent 5d6b738 commit f150588

Some content is hidden

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

43 files changed

+1607
-1759
lines changed

.githooks/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
npx --no-install lint-staged

package.json

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"pretest": "node tool/create-fixtures.js",
3030
"test": "textlint-scripts test && npm run test:textlint",
3131
"test:textlint": "(cd example && npm i --no-save && npm test)",
32-
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css}'"
32+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
33+
"prepare": "git config --local core.hooksPath .githooks"
3334
},
3435
"keywords": [
3536
"textlint",
@@ -39,9 +40,8 @@
3940
],
4041
"devDependencies": {
4142
"glob": "^7.1.4",
42-
"husky": "^3.0.9",
43-
"lint-staged": "^9.4.2",
44-
"prettier": "^1.18.2",
43+
"lint-staged": "^11.0.0",
44+
"prettier": "^2.2.1",
4545
"textlint-scripts": "^3.0.0"
4646
},
4747
"dependencies": {
@@ -59,19 +59,14 @@
5959
"textlint": ">= 5.6.0"
6060
},
6161
"prettier": {
62+
"singleQuote": false,
6263
"printWidth": 120,
63-
"tabWidth": 4
64+
"tabWidth": 4,
65+
"trailingComma": "none"
6466
},
6567
"lint-staged": {
6668
"*.{js,jsx,ts,tsx,css}": [
67-
"prettier --write",
68-
"git add"
69+
"prettier --write"
6970
]
70-
},
71-
"husky": {
72-
"hooks": {
73-
"post-commit": "git reset",
74-
"pre-commit": "lint-staged"
75-
}
7671
}
7772
}

src/1.1.1.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,20 @@
1717
*/
1818
import { analyzeDesumasu, analyzeDearu } from "analyze-desumasu-dearu";
1919
import { RuleHelper } from "textlint-rule-helper";
20-
module.exports = function(context) {
20+
module.exports = function (context) {
2121
let { Syntax, RuleError, report, getSource } = context;
2222
let helper = new RuleHelper(context);
2323
let desumasuList = [];
2424
let dearuList = [];
2525

2626
function reportResult(list, { desumasu, dearu }) {
2727
list.forEach(({ node, matches }) => {
28-
matches.forEach(match => {
28+
matches.forEach((match) => {
2929
let message;
3030
if (desumasu) {
31-
message = `本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${
32-
match.value
33-
}"が敬体(ですます調)です。`;
31+
message = `本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が敬体(ですます調)です。`;
3432
} else if (dearu) {
35-
message = `本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${
36-
match.value
37-
}"が常体(である調)です。`;
33+
message = `本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が常体(である調)です。`;
3834
}
3935
report(
4036
node,

src/1.1.3.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
いずれの場合も、ひとまとまりの箇条書きでは、敬体と常体を混在させません。文末に句点(。)を付けるかどうかも統一します。
1111
*/
1212
import { analyzeDesumasu, analyzeDearu } from "analyze-desumasu-dearu";
13-
module.exports = function(context) {
13+
module.exports = function (context) {
1414
let { Syntax, RuleError, report, getSource } = context;
1515
let desumasuList = [];
1616
let dearuList = [];
@@ -27,7 +27,7 @@ module.exports = function(context) {
2727
}
2828

2929
function reportPointResult(nodeList, { shouldUsePoint }) {
30-
nodeList.forEach(node => {
30+
nodeList.forEach((node) => {
3131
let message;
3232
if (shouldUsePoint) {
3333
message = `箇条書きの文末に句点(。)を付けて下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。`;
@@ -40,16 +40,12 @@ module.exports = function(context) {
4040

4141
function reportDesumaruDearuResult(list, { desumasu, dearu }) {
4242
list.forEach(({ node, matches }) => {
43-
matches.forEach(match => {
43+
matches.forEach((match) => {
4444
let message;
4545
if (desumasu) {
46-
message = `箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${
47-
match.value
48-
}"が常体(である調)です。`;
46+
message = `箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が常体(である調)です。`;
4947
} else if (dearu) {
50-
message = `箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${
51-
match.value
52-
}"が敬体(ですます調)です。`;
48+
message = `箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が敬体(ですます調)です。`;
5349
}
5450
report(
5551
node,

src/1.1.5.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
キャプション間で文体が混ざっていないことを確認する。
1010
*/
1111
import { analyzeDesumasu, analyzeDearu } from "analyze-desumasu-dearu";
12-
module.exports = function(context) {
12+
module.exports = function (context) {
1313
let { Syntax, RuleError, report, getSource } = context;
1414
let desumasuList = [];
1515
let dearuList = [];
@@ -22,16 +22,12 @@ module.exports = function(context) {
2222
const imagePaddingLet = 2; // ![ の分paddingを付ける
2323
function reportResult(list, { desumasu, dearu }) {
2424
list.forEach(({ node, matches }) => {
25-
matches.forEach(match => {
25+
matches.forEach((match) => {
2626
let message;
2727
if (desumasu) {
28-
message = `図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${
29-
match.value
30-
}"が常体(である調)です。`;
28+
message = `図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が常体(である調)です。`;
3129
} else if (dearu) {
32-
message = `図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${
33-
match.value
34-
}"が敬体(ですます調)です。`;
30+
message = `図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が敬体(ですます調)です。`;
3531
}
3632
report(
3733
node,

src/1.2.1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const replaceSymbol = {
2828
",": "、"
2929
};
3030

31-
const reporter = context => {
31+
const reporter = (context) => {
3232
let { Syntax, RuleError, report, fixer, getSource } = context;
3333
return {
3434
[Syntax.Str](node) {
@@ -39,7 +39,7 @@ const reporter = context => {
3939
const leftMatches = matchCaptureGroupAll(text, leftTarget);
4040
const rightMatches = matchCaptureGroupAll(text, rightTarget);
4141
const matches = mergeMatches(leftMatches, rightMatches);
42-
matches.forEach(match => {
42+
matches.forEach((match) => {
4343
const symbol = replaceSymbol[match.text];
4444
const indexOfSymbol = match.index;
4545
report(

src/2.1.10.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function reporter(context) {
2424
// この段階では 10,000 も含まれている
2525
// ^0,xxx をだけを取り出す
2626
let matchedString = match[0];
27-
matchCaptureGroupAll(matchedString, strictMatchReg).forEach(subMatch => {
27+
matchCaptureGroupAll(matchedString, strictMatchReg).forEach((subMatch) => {
2828
const { index } = subMatch;
2929
report(
3030
node,

src/2.1.2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function stringToArray(value) {
1313
return value.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
1414
}
1515

16-
module.exports = function(context) {
16+
module.exports = function (context) {
1717
let { Syntax, RuleError, report, getSource } = context;
1818
return {
1919
[Syntax.Str](node) {

src/2.1.5.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import moji from "moji";
2121
* @param {String} str 変換したい文字列
2222
*/
2323
function toZenkaku(string) {
24-
return moji(string)
25-
.convert("HK", "ZK")
26-
.toString();
24+
return moji(string).convert("HK", "ZK").toString();
2725
}
2826

2927
function reporter(context) {
@@ -34,14 +32,14 @@ function reporter(context) {
3432
});
3533
let originalStrRule = dictRule[Syntax.Str];
3634
// 半角カタカナの使用をチェックする
37-
dictRule[Syntax.Str] = function(node) {
35+
dictRule[Syntax.Str] = function (node) {
3836
originalStrRule(node);
3937
if (!isUserWrittenNode(node, context)) {
4038
return;
4139
}
4240
const text = getSource(node);
4341
const matches = matchCaptureGroupAll(text, /([\uFF65-\uFF9F]+)/g);
44-
matches.forEach(match => {
42+
matches.forEach((match) => {
4543
const { index, text } = match;
4644
report(
4745
node,

src/2.1.6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import fs from "fs";
1010
import path from "path";
1111
import prh from "textlint-rule-prh";
1212

13-
module.exports = function(context) {
13+
module.exports = function (context) {
1414
// 辞書ベースのカタカナ末尾の長音のチェックを行う
1515
return prh.fixer(context, {
1616
ruleContents: [fs.readFileSync(path.join(__dirname, "..", "dict", "2.1.6.yml"), "utf-8")]

src/2.1.8.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { isUserWrittenNode } from "./util/node-util";
1010
import moji from "moji";
1111
import { matchCaptureGroupAll } from "match-index";
1212
function toHankaku(string) {
13-
return moji(string)
14-
.convert("ZE", "HE")
15-
.toString();
13+
return moji(string).convert("ZE", "HE").toString();
1614
}
1715
function reporter(context) {
1816
let { Syntax, RuleError, report, fixer, getSource } = context;
@@ -23,7 +21,7 @@ function reporter(context) {
2321
}
2422
const text = getSource(node);
2523
const matchRegExp = /([-]+)/;
26-
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
24+
matchCaptureGroupAll(text, matchRegExp).forEach((match) => {
2725
const { index, text } = match;
2826
report(
2927
node,

src/2.1.9.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { isUserWrittenNode } from "./util/node-util";
1010
import { matchCaptureGroupAll } from "match-index";
1111
import moji from "moji";
1212
function toHankaku(string) {
13-
return moji(string)
14-
.convert("ZE", "HE")
15-
.toString();
13+
return moji(string).convert("ZE", "HE").toString();
1614
}
1715
function reporter(context) {
1816
let { Syntax, RuleError, report, fixer, getSource } = context;
@@ -23,7 +21,7 @@ function reporter(context) {
2321
}
2422
const text = getSource(node);
2523
const matchRegExp = /([-]+)/;
26-
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
24+
matchCaptureGroupAll(text, matchRegExp).forEach((match) => {
2725
const { index, text } = match;
2826
report(
2927
node,

src/2.2.1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import fs from "fs";
1818
import path from "path";
1919
import prh from "textlint-rule-prh";
2020

21-
module.exports = function(context) {
21+
module.exports = function (context) {
2222
return prh.fixer(context, {
2323
ruleContents: [fs.readFileSync(path.join(__dirname, "..", "dict", "2.2.1.yml"), "utf-8")]
2424
});

src/2.2.2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function reporter(context) {
116116
const toNumber = (text, pattern, match) => {
117117
const matchedString = match[0];
118118
const index = match.index;
119-
const expected = matchedString.replace(pattern, function(all, match) {
119+
const expected = matchedString.replace(pattern, function (all, match) {
120120
return all.replace(match, ja2num(match));
121121
});
122122
const ruleError = new RuleError(
@@ -138,7 +138,7 @@ function reporter(context) {
138138
*/
139139
const toKanNumber = (text, pattern, match) => {
140140
const matchedString = match[0];
141-
const expected = matchedString.replace(pattern, function(all, match) {
141+
const expected = matchedString.replace(pattern, function (all, match) {
142142
return all.replace(match, _num2ja(match, { with_arabic: false }));
143143
});
144144
const index = match.index;
@@ -158,7 +158,7 @@ function reporter(context) {
158158
// ignorePatternにマッチしたらmatchFnを呼ばないようにする(エラーを無視する)
159159
const ignoreWhenMatched = (ignorePatterns, matchFn) => {
160160
return (text, pattern, match) => {
161-
if (ignorePatterns.some(p => p.test(text))) {
161+
if (ignorePatterns.some((p) => p.test(text))) {
162162
return null;
163163
} else {
164164
return matchFn(text, pattern, match);

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
import fs from "fs";
10-
module.exports = function(context) {
10+
module.exports = function (context) {
1111
return prh.fixer(context, {
1212
ruleContents: [fs.readFileSync(path.join(__dirname, "..", "dict", "2.2.3.yml"), "utf-8")]
1313
});

src/3.1.1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function reporter(context) {
2525
text,
2626
/(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])( )[A-Za-z0-9]/
2727
);
28-
const reportMatch = match => {
28+
const reportMatch = (match) => {
2929
const { index } = match;
3030
report(
3131
node,

src/3.1.2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ function reporter(context) {
2222
// 全角同士の間は半角スペースを入れない
2323
const matchReg = rx`${japaneseRegExp}( )${japaneseRegExp}`;
2424
const katakakana = /[-]( )[-]/;
25-
matchAll(text, matchReg).forEach(match => {
25+
matchAll(text, matchReg).forEach((match) => {
2626
const { input, captureGroups } = match;
2727
// ただしカタカナ複合語の場合を除きます。
2828
if (katakakana.test(input)) {
2929
return;
3030
}
31-
captureGroups.forEach(captureGroup => {
31+
captureGroups.forEach((captureGroup) => {
3232
const index = captureGroup.index;
3333
report(
3434
node,

src/3.2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { isUserWrittenNode } from "./util/node-util";
99
import { matchCaptureGroupAll } from "match-index";
1010

11-
module.exports = function(context) {
11+
module.exports = function (context) {
1212
let { Syntax, RuleError, report, getSource } = context;
1313
return {
1414
[Syntax.Str](node) {
@@ -17,7 +17,7 @@ module.exports = function(context) {
1717
}
1818
const text = getSource(node);
1919
// カタカナ(カタカナ以外)カタカナ のパターンを取り出す
20-
matchCaptureGroupAll(text, /[-]([^[-])[-]/).forEach(match => {
20+
matchCaptureGroupAll(text, /[-]([^[-])[-]/).forEach((match) => {
2121
// カタカナの間を全角スペースでは区切らない
2222
const { text } = match;
2323
if (text === " ") {

src/3.3.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { matchCaptureGroupAll } from "match-index";
99

1010
const brackets = ["\\[", "\\]", "(", ")", "[", "]", "「", "」", "『", "』"];
1111

12-
const leftBrackets = brackets.map(bracket => {
12+
const leftBrackets = brackets.map((bracket) => {
1313
return new RegExp("([  ])" + bracket, "g");
1414
});
15-
const rightBrackets = brackets.map(bracket => {
15+
const rightBrackets = brackets.map((bracket) => {
1616
return new RegExp(bracket + "([  ])", "g");
1717
});
1818
function reporter(context) {
@@ -24,8 +24,8 @@ function reporter(context) {
2424
}
2525
const text = getSource(node);
2626
// 左にスペース
27-
leftBrackets.forEach(pattern => {
28-
matchCaptureGroupAll(text, pattern).forEach(match => {
27+
leftBrackets.forEach((pattern) => {
28+
matchCaptureGroupAll(text, pattern).forEach((match) => {
2929
const { index } = match;
3030
report(
3131
node,
@@ -37,8 +37,8 @@ function reporter(context) {
3737
});
3838
});
3939
// 右にスペース
40-
rightBrackets.forEach(pattern => {
41-
matchCaptureGroupAll(text, pattern).forEach(match => {
40+
rightBrackets.forEach((pattern) => {
41+
matchCaptureGroupAll(text, pattern).forEach((match) => {
4242
const { index, text } = match;
4343
report(
4444
node,

0 commit comments

Comments
 (0)