Skip to content

Commit 8b76cb5

Browse files
authored
chore(deps): remove husky (#11)
1 parent b68e4b7 commit 8b76cb5

File tree

6 files changed

+250
-297
lines changed

6 files changed

+250
-297
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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
},
2828
"scripts": {
2929
"build": "textlint-scripts build",
30-
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
3130
"prepublish": "npm run --if-present build",
3231
"test": "textlint-scripts test",
33-
"watch": "textlint-scripts build --watch"
32+
"watch": "textlint-scripts build --watch",
33+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
34+
"prepare": "git config --local core.hooksPath .githooks"
3435
},
3536
"husky": {
3637
"hooks": {
@@ -39,14 +40,14 @@
3940
},
4041
"lint-staged": {
4142
"*.{js,jsx,ts,tsx,css}": [
42-
"prettier --write",
43-
"git add"
43+
"prettier --write"
4444
]
4545
},
4646
"prettier": {
47-
"printWidth": 120,
4847
"singleQuote": false,
49-
"tabWidth": 4
48+
"printWidth": 120,
49+
"tabWidth": 4,
50+
"trailingComma": "none"
5051
},
5152
"dependencies": {
5253
"textlint-rule-helper": "^2.1.1",
@@ -55,9 +56,8 @@
5556
"devDependencies": {
5657
"@textlint/types": "^1.3.1",
5758
"@types/node": "^14.0.13",
58-
"husky": "^4.2.5",
59-
"lint-staged": "^10.2.11",
60-
"prettier": "^2.0.5",
59+
"lint-staged": "^11.1.2",
60+
"prettier": "^2.3.2",
6161
"sudachi-synonyms-dictionary": "^5.0.1",
6262
"textlint-scripts": "^3.0.0",
6363
"textlint-tester": "^5.1.15",

src/create-index.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ export type Midashi = string;
1515
* usedItemGroup.forEach
1616
*/
1717
export class ItemGroup {
18-
constructor(public items: SudachiSynonyms[]) {
19-
20-
}
18+
constructor(public items: SudachiSynonyms[]) {}
2119

2220
getItem(midashi: string): SudachiSynonyms | null {
23-
return this.items.find(item => item.midashi === midashi) ?? null
21+
return this.items.find((item) => item.midashi === midashi) ?? null;
2422
}
2523

26-
usedItems(usedItemSet: Set<SudachiSynonyms>, { allowAlphabet, allowNumber, allows }: { allowAlphabet: boolean; allowNumber: boolean; allows: string[] }): SudachiSynonyms[] {
24+
usedItems(
25+
usedItemSet: Set<SudachiSynonyms>,
26+
{ allowAlphabet, allowNumber, allows }: { allowAlphabet: boolean; allowNumber: boolean; allows: string[] }
27+
): SudachiSynonyms[] {
2728
// sort by used
28-
return Array.from(usedItemSet.values()).filter(item => {
29-
if (allowAlphabet && (item.hyoukiYure === "アルファベット表記" || item.ryakusyou === "略語・略称/アルファベット")) {
29+
return Array.from(usedItemSet.values()).filter((item) => {
30+
if (
31+
allowAlphabet &&
32+
(item.hyoukiYure === "アルファベット表記" || item.ryakusyou === "略語・略称/アルファベット")
33+
) {
3034
// アルファベット表記
3135
// blog <-> ブログ
3236
// 略語・略称/アルファベット
@@ -61,7 +65,10 @@ $ npm install sudachi-synonyms-dictionary
6165
`);
6266
}
6367
};
64-
export type IndexType = { keyItemGroupMap: Map<Midashi, ItemGroup[]>; SudachiSynonymsItemGroup: Map<SudachiSynonyms, ItemGroup>; };
68+
export type IndexType = {
69+
keyItemGroupMap: Map<Midashi, ItemGroup[]>;
70+
SudachiSynonymsItemGroup: Map<SudachiSynonyms, ItemGroup>;
71+
};
6572
let _ret: IndexType | null = null;
6673
export const createIndex = async (): Promise<IndexType> => {
6774
if (_ret) {
@@ -71,19 +78,21 @@ export const createIndex = async (): Promise<IndexType> => {
7178
const keyItemGroupMap: Map<Midashi, ItemGroup[]> = new Map();
7279
const SudachiSynonymsItemGroup: Map<SudachiSynonyms, ItemGroup> = new Map();
7380
const SynonymsDictionary = await fetchDictionary();
74-
SynonymsDictionary.forEach(group => {
81+
SynonymsDictionary.forEach((group) => {
7582
const groupByVocabularyNumber = group.items.reduce((res, item) => {
7683
res[item.vocabularyNumber!] = (res[item.vocabularyNumber!] || []).concat(item);
7784
return res;
7885
}, {} as { [index: string]: SudachiSynonyms[] });
79-
const itemGroups = Object.values(groupByVocabularyNumber).filter(items => {
80-
return items.length > 1;
81-
}).map(items => {
82-
return new ItemGroup(items);
83-
});
86+
const itemGroups = Object.values(groupByVocabularyNumber)
87+
.filter((items) => {
88+
return items.length > 1;
89+
})
90+
.map((items) => {
91+
return new ItemGroup(items);
92+
});
8493
// register key with itemGroup
85-
itemGroups.forEach(itemGroup => {
86-
itemGroup.items.forEach(item => {
94+
itemGroups.forEach((itemGroup) => {
95+
itemGroup.items.forEach((item) => {
8796
const oldItemGroup = keyItemGroupMap.get(item.midashi) || [];
8897
keyItemGroupMap.set(item.midashi, oldItemGroup.concat(itemGroup));
8998
SudachiSynonymsItemGroup.set(item, itemGroup);

src/textlint-rule-no-synonyms.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export interface Options {
3535
allowNumber?: boolean;
3636
}
3737

38-
3938
export const DefaultOptions: Required<Options> = {
4039
allows: [],
4140
preferWords: [],
@@ -58,10 +57,10 @@ const report: TextlintRuleReporter<Options> = (context, options = {}) => {
5857
if (!itemGroups) {
5958
return;
6059
}
61-
itemGroups.forEach(itemGroup => {
60+
itemGroups.forEach((itemGroup) => {
6261
// "アーカイブ" など同じ見出しを複数回もつItemGroupがあるため、ItemGroupごとに1度のみに限定
6362
let midashAtOnce = false;
64-
itemGroup.items.forEach(item => {
63+
itemGroup.items.forEach((item) => {
6564
if (!midashAtOnce && item.midashi === segment) {
6665
midashAtOnce = true;
6766
usedSudachiSynonyms.add(item);
@@ -71,9 +70,18 @@ const report: TextlintRuleReporter<Options> = (context, options = {}) => {
7170
});
7271
});
7372
};
74-
return wrapReportHandler(context,
73+
return wrapReportHandler(
74+
context,
7575
{
76-
ignoreNodeTypes: [Syntax.BlockQuote, Syntax.CodeBlock, Syntax.Code, Syntax.Html, Syntax.Link, Syntax.Image, Syntax.Comment]
76+
ignoreNodeTypes: [
77+
Syntax.BlockQuote,
78+
Syntax.CodeBlock,
79+
Syntax.Code,
80+
Syntax.Html,
81+
Syntax.Link,
82+
Syntax.Image,
83+
Syntax.Comment
84+
]
7785
},
7886
(report) => {
7987
return {
@@ -95,27 +103,33 @@ const report: TextlintRuleReporter<Options> = (context, options = {}) => {
95103
allowAlphabet,
96104
allowNumber
97105
});
98-
const preferWord = preferWords.find(midashi => itemGroup.getItem(midashi))
106+
const preferWord = preferWords.find((midashi) => itemGroup.getItem(midashi));
99107
if (preferWord) {
100-
const deniedItems = items.filter(item => item.midashi !== preferWord)
108+
const deniedItems = items.filter((item) => item.midashi !== preferWord);
101109
for (const item of deniedItems) {
102110
const index = locationMap.get(item)?.index ?? 0;
103-
const deniedWord = item.midashi
111+
const deniedWord = item.midashi;
104112
const message = `「${preferWord}」の同義語である「${deniedWord}」が利用されています`;
105-
report(node, new RuleError(message, {
106-
index,
107-
fix: fixer.replaceTextRange([index, index + deniedWord.length], preferWord),
108-
}));
113+
report(
114+
node,
115+
new RuleError(message, {
116+
index,
117+
fix: fixer.replaceTextRange([index, index + deniedWord.length], preferWord)
118+
})
119+
);
109120
}
110121
} else if (items.length >= 2) {
111-
const 同義の見出しList = items.map(item => item.midashi);
122+
const 同義の見出しList = items.map((item) => item.midashi);
112123
// select last used
113124
const matchSegment = locationMap.get(items[items.length - 1]);
114125
const index = matchSegment ? matchSegment.index : 0;
115126
const message = `同義語である「${同義の見出しList.join("」と「")}」が利用されています`;
116-
report(node, new RuleError(message, {
117-
index
118-
}));
127+
report(
128+
node,
129+
new RuleError(message, {
130+
index
131+
})
132+
);
119133
}
120134
}
121135
}
@@ -126,5 +140,5 @@ const report: TextlintRuleReporter<Options> = (context, options = {}) => {
126140

127141
export default {
128142
linter: report,
129-
fixer: report,
143+
fixer: report
130144
};

test/textlint-rule-no-synonyms.test.ts

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tester.run("textlint-rule-no-synonyms", rule, {
2222
{
2323
text: `ウェブアプリとウェブアプリケーションの違いは許容する`,
2424
options: {
25-
allows: ["ウェブアプリ"] // <= 片方が許可されていればOK
25+
allows: ["ウェブアプリ"] // <= 片方が許可されていればOK
2626
}
2727
},
2828
// preferWords
@@ -31,51 +31,63 @@ tester.run("textlint-rule-no-synonyms", rule, {
3131
options: {
3232
preferWords: ["ユーザー"]
3333
}
34-
},
34+
}
3535
],
36-
invalid: [{
37-
text: "サーバとサーバーの表記揺れがある",
38-
errors: [{
39-
message: "同義語である「サーバ」と「サーバー」が利用されています",
40-
index: 4
41-
}]
42-
}, {
43-
text: "この雇入と雇入れの違いは難しい問題だ",
44-
errors: [{
45-
message: "同義語である「雇入」と「雇入れ」が利用されています",
46-
index: 5
47-
}]
48-
},
36+
invalid: [
37+
{
38+
text: "サーバとサーバーの表記揺れがある",
39+
errors: [
40+
{
41+
message: "同義語である「サーバ」と「サーバー」が利用されています",
42+
index: 4
43+
}
44+
]
45+
},
46+
{
47+
text: "この雇入と雇入れの違いは難しい問題だ",
48+
errors: [
49+
{
50+
message: "同義語である「雇入」と「雇入れ」が利用されています",
51+
index: 5
52+
}
53+
]
54+
},
4955
{
5056
text: "blogはブログです",
5157
options: {
5258
allowAlphabet: false
5359
},
54-
errors: [{
55-
message: "同義語である「blog」と「ブログ」が利用されています",
56-
index: 5
57-
}]
60+
errors: [
61+
{
62+
message: "同義語である「blog」と「ブログ」が利用されています",
63+
index: 5
64+
}
65+
]
5866
},
5967
{
6068
text: "1は数字の一種です",
6169
options: {
6270
allowNumber: false
6371
},
64-
errors: [{
65-
message: "同義語である「1」と「一」が利用されています",
66-
index: 5
67-
}]
72+
errors: [
73+
{
74+
message: "同義語である「1」と「一」が利用されています",
75+
index: 5
76+
}
77+
]
6878
},
6979
{
7080
text: "ユーザーは許可しユーザはエラー。allowAlphabetがtrueならuserはエラーにならない",
7181
output: "ユーザーは許可しユーザーはエラー。allowAlphabetがtrueならuserはエラーにならない",
7282
options: {
7383
preferWords: ["ユーザー"]
7484
},
75-
errors: [{
76-
message: "「ユーザー」の同義語である「ユーザ」が利用されています",
77-
index: 8
78-
}]
85+
errors: [
86+
{
87+
message: "「ユーザー」の同義語である「ユーザ」が利用されています",
88+
index: 8
89+
}
90+
]
7991
},
8092
{
8193
text: "ユーザーは許可しallowAlphabetがfalseならユーザもuserもエラー",
@@ -84,24 +96,29 @@ tester.run("textlint-rule-no-synonyms", rule, {
8496
preferWords: ["ユーザー"],
8597
allowAlphabet: false
8698
},
87-
errors: [{
88-
message: "「ユーザー」の同義語である「ユーザ」が利用されています",
89-
index: 29
90-
}, {
91-
message: "「ユーザー」の同義語である「user」が利用されています",
92-
index: 33
93-
}]
99+
errors: [
100+
{
101+
message: "「ユーザー」の同義語である「ユーザ」が利用されています",
102+
index: 29
103+
},
104+
{
105+
message: "「ユーザー」の同義語である「user」が利用されています",
106+
index: 33
107+
}
108+
]
94109
},
95110
{
96111
text: "ユーザはエラー",
97112
output: "ユーザーはエラー",
98113
options: {
99114
preferWords: ["ユーザー"]
100115
},
101-
errors: [{
102-
message: "「ユーザー」の同義語である「ユーザ」が利用されています",
103-
index: 0
104-
}]
105-
},
116+
errors: [
117+
{
118+
message: "「ユーザー」の同義語である「ユーザ」が利用されています",
119+
index: 0
120+
}
121+
]
122+
}
106123
]
107124
});

0 commit comments

Comments
 (0)