Skip to content

Commit 4a4dfd4

Browse files
committed
fix(rule): fix 略語・略称/アルファベット handling
DB <-> データベース is allowed by `allowAlphabet`
1 parent 8b1485c commit 4a4dfd4

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Install with [npm](https://www.npmjs.com/):
1818
npm install @textlint-ja/textlint-rule-no-synonyms sudachi-synonyms-dictionary
1919

2020
辞書となる[sudachi-synonyms-dictionary](https://github.com/azu/sudachi-synonyms-dictionary)[peerDependencies](https://npm.github.io/using-pkgs-docs/package-json/types/peerdependencies.html)なので、ルールとは別途インストールする必要があります。
21-
ルール間で[sudachi-synonyms-dictionary](https://github.com/azu/sudachi-synonyms-dictionary)を共有した際に、辞書を一意にするためです
21+
ルール間で1つの辞書ファイルを共有するためです
2222

2323
> Cannot find module 'sudachi-synonyms-dictionary'
2424

src/create-index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export class ItemGroup {
2121
usedItems(usedItemSet: Set<SudachiSynonyms>, { allowAlphabet, allows }: { allowAlphabet: boolean, allows: string[] }): SudachiSynonyms[] {
2222
// sort by used
2323
return Array.from(usedItemSet.values()).filter(item => {
24-
if (allowAlphabet && item.hyoukiYure === "アルファベット表記") {
24+
if (allowAlphabet && (item.hyoukiYure === "アルファベット表記" || item.ryakusyou === "略語・略称/アルファベット")) {
25+
// アルファベット表記
26+
// blog <-> ブログ
27+
// 略語・略称/アルファベット
28+
// OS <-> オペレーションシステム
2529
return false;
2630
}
2731
if (allows.includes(item.midashi)) {
@@ -32,12 +36,29 @@ export class ItemGroup {
3236
}
3337
}
3438

39+
/**
40+
* インストールのチェック
41+
*/
42+
const assertInstallationSudachiSynonymsDictionary = () => {
43+
try {
44+
require("sudachi-synonyms-dictionary");
45+
} catch (error) {
46+
throw new Error(`sudachi-synonyms-dictionaryがインストールされていません。
47+
ルールとは別にsudachi-synonyms-dictionaryをインストールしてください。
48+
49+
$ npm install sudachi-synonyms-dictionary
50+
51+
52+
`)
53+
}
54+
};
3555
export type IndexType = { keyItemGroupMap: Map<Midashi, ItemGroup[]>; SudachiSynonymsItemGroup: Map<SudachiSynonyms, ItemGroup>; };
3656
let _ret: IndexType | null = null;
3757
export const createIndex = async (): Promise<IndexType> => {
3858
if (_ret) {
3959
return Promise.resolve(_ret);
4060
}
61+
assertInstallationSudachiSynonymsDictionary();
4162
const keyItemGroupMap: Map<Midashi, ItemGroup[]> = new Map();
4263
const SudachiSynonymsItemGroup: Map<SudachiSynonyms, ItemGroup> = new Map();
4364
const SynonymsDictionary = await fetchDictionary();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import rule from "../src/textlint-rule-no-synonyms";
77
tester.run("textlint-rule-no-synonyms", rule, {
88
valid: [
99
"新参入、借り入れ、問題のパスポート、マネー、雇入 片方のペアだけならOKです",
10+
"インターフェースとインターフェースは同じなのでOK",
1011
"This is アーカイブ",
1112
// allowAlphabet: true
13+
// item.hyoukiYure === "アルファベット表記"
1214
"blogはブログです",
13-
// allow links
15+
// item.ryakusyou === "略語・略称/アルファベット"
16+
"「データベース」「DB」",
17+
// allow links by default
1418
`「[インターフェース](https://example.com)」と「[インタフェース](https://example.com)」`,
1519
// "allows
1620
{

0 commit comments

Comments
 (0)