-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlinting.test.ts
More file actions
173 lines (163 loc) · 4.5 KB
/
linting.test.ts
File metadata and controls
173 lines (163 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import fs from "node:fs";
import path from "node:path";
import {
TextlintKernel,
type TextlintKernelRule,
type TextlintResult,
} from "@textlint/kernel";
// @ts-expect-error
import { rules } from "textlint-rule-preset-ja-technical-writing";
import { beforeAll, describe, expect, it } from "vitest";
import typstPlugin from "../../src";
describe("linting", () => {
describe("smoke tests", () => {
describe("textlint-rule-preset-ja-technical-writing", () => {
let textlintResult: TextlintResult;
beforeAll(async () => {
const kernel = new TextlintKernel();
textlintResult = await kernel.lintText(
fs.readFileSync(
path.join(
__dirname,
"./fixtures/smoke/textlint-rule-preset-ja-technical-writing/main.typ",
),
"utf-8",
),
{
ext: ".typ",
plugins: [
{
pluginId: "typst",
plugin: typstPlugin,
},
],
rules: [
// Set each rule in the preset individually
...Object.entries(rules).map(
([id, rule]) =>
({
ruleId: `ja-technical-writing/${id}`,
rule: rule,
}) as TextlintKernelRule,
),
],
},
);
});
// Rule test configurations
const ruleTests = [
{
ruleId: "sentence-length",
expectedMessage: "exceeds the maximum sentence length",
},
{
ruleId: "max-ten",
expectedMessage: '一つの文で"、"を4つ以上使用',
},
{
ruleId: "max-kanji-continuous-len",
expectedMessage: "漢字が6つ以上連続",
},
{
ruleId: "no-mix-dearu-desumasu",
expectedMessage: 'である"調 と "ですます"調 が混在',
},
{
ruleId: "ja-no-mixed-period",
expectedMessage: '文末が"。"で終わっていません',
},
{
ruleId: "no-doubled-joshi",
expectedMessage: "一文に二回以上利用されている助詞",
},
{
ruleId: "no-dropping-the-ra",
expectedMessage: "ら抜き言葉を使用",
},
{
ruleId: "no-doubled-conjunctive-particle-ga",
expectedMessage: '逆接の接続助詞 "が" が二回以上使われています',
},
{
ruleId: "no-doubled-conjunction",
expectedMessage: "同じ接続詞(しかし)が連続",
},
{
ruleId: "no-exclamation-question-mark",
expectedMessage: 'Disallow to use "!"',
},
{
ruleId: "no-hankaku-kana",
expectedMessage: "Disallow to use 半角カタカナ",
},
{
ruleId: "ja-no-weak-phrase",
expectedMessage: '弱い表現: "かも" が使われています',
},
{
ruleId: "ja-no-successive-word",
expectedMessage: "が連続して2回使われています",
},
{
ruleId: "ja-no-redundant-expression",
expectedMessage: 'することが可能です"は冗長な表現',
},
{
ruleId: "ja-unnatural-alphabet",
expectedMessage: "不自然なアルファベット",
},
{
ruleId: "no-unmatched-pair",
expectedMessage: "Cannot find a pairing character for (",
},
];
// Special cases with multiple expected messages
const multiMessageTests = [
{
ruleId: "arabic-kanji-numbers",
expectedMessages: ["十番目 => 10番目", "1時的 => 一時的"],
},
{
ruleId: "no-double-negative-ja",
expectedMessages: [
"二重否定: 〜なくもない",
"二重否定: 〜ないことはない",
],
},
{
ruleId: "no-nfd",
expectedMessages: ['ホ゜" => "ポ"', 'シ゛" => "ジ"'],
},
{
ruleId: "ja-no-abusage",
expectedMessages: ["可変する", "適用"],
},
];
const getViolations = (ruleId: string) => {
return textlintResult.messages.filter(
(message) => message.ruleId === `ja-technical-writing/${ruleId}`,
);
};
// Single message tests
for (const { ruleId, expectedMessage } of ruleTests) {
it(`should detect ${ruleId} violations`, () => {
const violations = getViolations(ruleId);
expect(violations.length).toBeGreaterThan(0);
expect(violations[0].message).toContain(expectedMessage);
});
}
// Multi-message tests
for (const { ruleId, expectedMessages } of multiMessageTests) {
it(`should detect ${ruleId} violations`, () => {
const violations = getViolations(ruleId);
expect(violations.length).toBeGreaterThan(0);
for (const expectedMessage of expectedMessages) {
expect(
violations.some((v) => v.message.includes(expectedMessage)),
).toBe(true);
}
});
}
});
});
});