@yuu1111/quality-check 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +2 -2
- package/README.md +2 -2
- package/dist/cli.js +5 -4
- package/package.json +1 -1
- package/src/config.ts +29 -2
- package/src/engines.ts +26 -0
package/README.ja.md
CHANGED
|
@@ -90,7 +90,7 @@ engineは `biome` → `typecheck` → `knip` → `code-style-check` → `comment
|
|
|
90
90
|
| `code-style-check` | `code-style-check --json` | `ignore`、`targets`、`args` |
|
|
91
91
|
| `comment-check` | `comment-check --json` | `ignore`、`targets`、`args`、`enable`(有効にするrule名) |
|
|
92
92
|
| `document-style-check` | `document-style-check lint --json` | `ignore`、`targets`、`args`、`enable`(有効にするrule名) |
|
|
93
|
-
| `tsdoc-check` | `tsdoc-check --json` | `ignore`、`targets`、`args`、`error`(違反として扱うrule名) |
|
|
93
|
+
| `tsdoc-check` | `tsdoc-check --json` | `ignore`、`targets`、`args`、`enable`(有効にするrule名)、`error`(違反として扱うrule名) |
|
|
94
94
|
|
|
95
95
|
`args` はengineの既定引数の後ろへ足す
|
|
96
96
|
設定fileで表せない起動条件や、engineの引数が変わったときの逃げ道として使う
|
|
@@ -102,7 +102,7 @@ engineが受け取らない条件は渡さず、その旨をそのengineのsecti
|
|
|
102
102
|
biome: ignore skipped (biome.json holds its settings)
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
`enable` は `comment-check` と `document-style-check` の `--enable <rule>` になり、他のengineでは拒否される
|
|
105
|
+
`enable` は `comment-check` と `document-style-check` と `tsdoc-check` の `--enable <rule>` になり、他のengineでは拒否される
|
|
106
106
|
このCLIはengineを同梱しないため、opt-in ruleを有効にするProjectは対応するengine packageも同じ変更で更新する
|
|
107
107
|
|
|
108
108
|
`comment-check` はbaseline差分を無効化する未作成のpathを渡して起動する
|
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ Each engine runs:
|
|
|
94
94
|
| `code-style-check` | `code-style-check --json` | `ignore`, `targets`, `args` |
|
|
95
95
|
| `comment-check` | `comment-check --json` | `ignore`, `targets`, `args`, `enable` (rule names to turn on) |
|
|
96
96
|
| `document-style-check` | `document-style-check lint --json` | `ignore`, `targets`, `args`, `enable` (rule names to turn on) |
|
|
97
|
-
| `tsdoc-check` | `tsdoc-check --json` | `ignore`, `targets`, `args`, `error` (rule names to fail on) |
|
|
97
|
+
| `tsdoc-check` | `tsdoc-check --json` | `ignore`, `targets`, `args`, `enable` (rule names to turn on), `error` (rule names to fail on) |
|
|
98
98
|
|
|
99
99
|
`args` is appended after the engine defaults, for conditions the config cannot express and for the case where an engine changes its arguments.
|
|
100
100
|
|
|
@@ -105,7 +105,7 @@ A condition that an engine does not take is not passed on, and the section says
|
|
|
105
105
|
biome: ignore skipped (biome.json holds its settings)
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
`enable` becomes `--enable <rule>` on `comment-check
|
|
108
|
+
`enable` becomes `--enable <rule>` on `comment-check`, `document-style-check`, and `tsdoc-check`, and the other engines reject the field.
|
|
109
109
|
This CLI ships no engine of its own, so a project that turns an opt-in rule on updates the matching engine package in the same change.
|
|
110
110
|
|
|
111
111
|
`comment-check` runs with an unwritten baseline path so that it reports every finding.
|
package/dist/cli.js
CHANGED
|
@@ -223,7 +223,7 @@ var ENGINE_OPTION_KEYS = {
|
|
|
223
223
|
"code-style-check": ["args", "ignore", "targets"],
|
|
224
224
|
"comment-check": ["args", "enable", "ignore", "targets"],
|
|
225
225
|
"document-style-check": ["args", "enable", "ignore", "targets"],
|
|
226
|
-
"tsdoc-check": ["args", "error", "ignore", "targets"]
|
|
226
|
+
"tsdoc-check": ["args", "enable", "error", "ignore", "targets"]
|
|
227
227
|
};
|
|
228
228
|
function readStringArray(value, field) {
|
|
229
229
|
if (value === undefined) {
|
|
@@ -264,7 +264,7 @@ function parseEngines(value, source) {
|
|
|
264
264
|
}
|
|
265
265
|
function parseEngineExtras(value, source, name) {
|
|
266
266
|
const extras = {};
|
|
267
|
-
if (name === "comment-check" || name === "document-style-check") {
|
|
267
|
+
if (name === "comment-check" || name === "document-style-check" || name === "tsdoc-check") {
|
|
268
268
|
const enable = readStringArray(value.enable, `${source}: config.${name}.enable`);
|
|
269
269
|
if (enable !== undefined) {
|
|
270
270
|
extras.enable = enable;
|
|
@@ -517,6 +517,7 @@ function buildEngineCommand(name, executable, context) {
|
|
|
517
517
|
return [
|
|
518
518
|
executable,
|
|
519
519
|
"--json",
|
|
520
|
+
...enableArguments(engineConfig(context.config, "tsdoc-check")),
|
|
520
521
|
...errorArguments,
|
|
521
522
|
...targets,
|
|
522
523
|
...ignoreArguments,
|
|
@@ -646,8 +647,8 @@ function parseJson(engine, stdout) {
|
|
|
646
647
|
let value;
|
|
647
648
|
try {
|
|
648
649
|
value = JSON.parse(stdout);
|
|
649
|
-
} catch {
|
|
650
|
-
throw new Error(`${engine} did not print JSON
|
|
650
|
+
} catch (error) {
|
|
651
|
+
throw new Error(`${engine} did not print JSON`, { cause: error });
|
|
651
652
|
}
|
|
652
653
|
if (!isJsonObject(value)) {
|
|
653
654
|
throw new Error(`${engine} printed an unexpected JSON value`);
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface DocumentStyleCheckOptions extends EngineOptions {
|
|
|
52
52
|
* TSDoc検査へ渡す起動条件
|
|
53
53
|
*/
|
|
54
54
|
export interface TsdocCheckOptions extends EngineOptions {
|
|
55
|
+
/** 既定で無効のopt-in ruleのうち有効にするrule名 */
|
|
56
|
+
enable?: string[];
|
|
55
57
|
/** 違反として扱うrule名 */
|
|
56
58
|
error?: string[];
|
|
57
59
|
}
|
|
@@ -91,6 +93,9 @@ export interface QualityConfig {
|
|
|
91
93
|
|
|
92
94
|
/**
|
|
93
95
|
* 設定fileを型付けするための恒等関数
|
|
96
|
+
*
|
|
97
|
+
* @param config - 型付けする統合検査の設定
|
|
98
|
+
* @returns 引数をそのまま返した統合検査の設定
|
|
94
99
|
*/
|
|
95
100
|
export function defineConfig(config: QualityConfig): QualityConfig {
|
|
96
101
|
return config;
|
|
@@ -128,7 +133,7 @@ const ENGINE_OPTION_KEYS: Record<EngineName, readonly string[]> = {
|
|
|
128
133
|
"code-style-check": ["args", "ignore", "targets"],
|
|
129
134
|
"comment-check": ["args", "enable", "ignore", "targets"],
|
|
130
135
|
"document-style-check": ["args", "enable", "ignore", "targets"],
|
|
131
|
-
"tsdoc-check": ["args", "error", "ignore", "targets"],
|
|
136
|
+
"tsdoc-check": ["args", "enable", "error", "ignore", "targets"],
|
|
132
137
|
};
|
|
133
138
|
|
|
134
139
|
function readStringArray(value: unknown, field: string): string[] | undefined {
|
|
@@ -197,7 +202,11 @@ function parseEngineExtras(
|
|
|
197
202
|
name: EngineName,
|
|
198
203
|
): ParsedEngineOptions {
|
|
199
204
|
const extras: ParsedEngineOptions = {};
|
|
200
|
-
if (
|
|
205
|
+
if (
|
|
206
|
+
name === "comment-check" ||
|
|
207
|
+
name === "document-style-check" ||
|
|
208
|
+
name === "tsdoc-check"
|
|
209
|
+
) {
|
|
201
210
|
const enable = readStringArray(
|
|
202
211
|
value.enable,
|
|
203
212
|
`${source}: config.${name}.enable`,
|
|
@@ -290,6 +299,10 @@ function parseEngineConfig(
|
|
|
290
299
|
|
|
291
300
|
/**
|
|
292
301
|
* 読み込んだ設定を検証して不足分を補う
|
|
302
|
+
*
|
|
303
|
+
* @param value - config fileがexportした検証前の値
|
|
304
|
+
* @param source - errorメッセージへ載せるconfig fileのpath
|
|
305
|
+
* @returns 検証して既定値を補った統合検査の設定
|
|
293
306
|
*/
|
|
294
307
|
export function parseConfig(value: unknown, source: string): QualityConfig {
|
|
295
308
|
if (!isJsonObject(value)) {
|
|
@@ -311,6 +324,9 @@ export function parseConfig(value: unknown, source: string): QualityConfig {
|
|
|
311
324
|
|
|
312
325
|
/**
|
|
313
326
|
* 有効なengineを実行順で返す
|
|
327
|
+
*
|
|
328
|
+
* @param config - engineの有効無効を持つ統合検査の設定
|
|
329
|
+
* @returns 有効なengine名を実行順に並べた配列
|
|
314
330
|
*/
|
|
315
331
|
export function enabledEngines(config: QualityConfig): EngineName[] {
|
|
316
332
|
return ENGINE_NAMES.filter((name) => Boolean(config.engines[name]));
|
|
@@ -318,6 +334,11 @@ export function enabledEngines(config: QualityConfig): EngineName[] {
|
|
|
318
334
|
|
|
319
335
|
/**
|
|
320
336
|
* engineの起動条件を返す 無効なengineにはnullを返す
|
|
337
|
+
*
|
|
338
|
+
* @typeParam K - 起動条件を取り出すengine名の型
|
|
339
|
+
* @param config - engineごとの起動条件を持つ統合検査の設定
|
|
340
|
+
* @param name - 起動条件を取り出すengine名
|
|
341
|
+
* @returns 指定したengineの起動条件 無効なengineならnull
|
|
321
342
|
*/
|
|
322
343
|
export function engineConfig<K extends EngineName>(
|
|
323
344
|
config: QualityConfig,
|
|
@@ -331,6 +352,9 @@ export function engineConfig<K extends EngineName>(
|
|
|
331
352
|
|
|
332
353
|
/**
|
|
333
354
|
* 作業ディレクトリからconfig fileを探す
|
|
355
|
+
*
|
|
356
|
+
* @param cwd - 探索を開始する作業ディレクトリのpath
|
|
357
|
+
* @returns 見つけたconfig fileのpath 見つからなければnull
|
|
334
358
|
*/
|
|
335
359
|
export function findConfigFile(cwd: string): string | null {
|
|
336
360
|
for (const name of DEFAULT_CONFIG_FILES) {
|
|
@@ -344,6 +368,9 @@ export function findConfigFile(cwd: string): string | null {
|
|
|
344
368
|
|
|
345
369
|
/**
|
|
346
370
|
* config fileを読み込んで検証する
|
|
371
|
+
*
|
|
372
|
+
* @param path - 読み込むconfig fileのpath
|
|
373
|
+
* @returns 読み込んで検証した統合検査の設定
|
|
347
374
|
*/
|
|
348
375
|
export async function loadConfig(path: string): Promise<QualityConfig> {
|
|
349
376
|
const module: unknown = await import(pathToFileURL(path).href);
|
package/src/engines.ts
CHANGED
|
@@ -85,6 +85,10 @@ export const ENGINE_LIMITS: Record<
|
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* engineが受け取らないため渡さなかった起動条件を返す
|
|
88
|
+
*
|
|
89
|
+
* @param name - 受け取れない起動条件を引くengine名
|
|
90
|
+
* @param options - engineへ渡そうとした起動条件
|
|
91
|
+
* @returns 渡さなかった起動条件とその理由の一覧
|
|
88
92
|
*/
|
|
89
93
|
export function skippedEngineOptions(
|
|
90
94
|
name: EngineName,
|
|
@@ -106,6 +110,9 @@ export function skippedEngineOptions(
|
|
|
106
110
|
|
|
107
111
|
/**
|
|
108
112
|
* 検出をJSONで返すengineか
|
|
113
|
+
*
|
|
114
|
+
* @param name - 判定するengine名
|
|
115
|
+
* @returns 検出をJSONで返すengineならtrue
|
|
109
116
|
*/
|
|
110
117
|
export function isFindingEngine(name: EngineName): boolean {
|
|
111
118
|
return (
|
|
@@ -118,6 +125,10 @@ export function isFindingEngine(name: EngineName): boolean {
|
|
|
118
125
|
|
|
119
126
|
/**
|
|
120
127
|
* node_modules/.binとPATHからengineの実行fileを探す
|
|
128
|
+
*
|
|
129
|
+
* @param name - 実行fileを探すengine名
|
|
130
|
+
* @param cwd - 探索を開始する作業ディレクトリのpath
|
|
131
|
+
* @returns 見つけた実行fileのpath PATHにも無ければnull
|
|
121
132
|
*/
|
|
122
133
|
export function resolveExecutable(
|
|
123
134
|
name: EngineName,
|
|
@@ -193,6 +204,11 @@ function enableArguments(
|
|
|
193
204
|
|
|
194
205
|
/**
|
|
195
206
|
* engineへ渡すコマンドを組み立てる
|
|
207
|
+
*
|
|
208
|
+
* @param name - コマンドを組み立てるengine名
|
|
209
|
+
* @param executable - 起動するengineの実行fileのpath
|
|
210
|
+
* @param context - 設定と上書きを持つ実行条件
|
|
211
|
+
* @returns engineへ渡す引数を並べたコマンド
|
|
196
212
|
*/
|
|
197
213
|
export function buildEngineCommand(
|
|
198
214
|
name: EngineName,
|
|
@@ -258,6 +274,7 @@ export function buildEngineCommand(
|
|
|
258
274
|
return [
|
|
259
275
|
executable,
|
|
260
276
|
"--json",
|
|
277
|
+
...enableArguments(engineConfig(context.config, "tsdoc-check")),
|
|
261
278
|
...errorArguments,
|
|
262
279
|
...targets,
|
|
263
280
|
...ignoreArguments,
|
|
@@ -267,6 +284,11 @@ export function buildEngineCommand(
|
|
|
267
284
|
|
|
268
285
|
/**
|
|
269
286
|
* engineの起動コマンドを順番に返す 型検査だけはprojectsごとに起動する
|
|
287
|
+
*
|
|
288
|
+
* @param name - コマンドを組み立てるengine名
|
|
289
|
+
* @param executable - 起動するengineの実行fileのpath
|
|
290
|
+
* @param context - 設定と上書きを持つ実行条件
|
|
291
|
+
* @returns 起動する順に並べたコマンドの配列
|
|
270
292
|
*/
|
|
271
293
|
export function buildEngineCommands(
|
|
272
294
|
name: EngineName,
|
|
@@ -287,6 +309,10 @@ export function buildEngineCommands(
|
|
|
287
309
|
|
|
288
310
|
/**
|
|
289
311
|
* Bun.spawnでengineを起動する既定のrunner
|
|
312
|
+
*
|
|
313
|
+
* @param command - 実行fileと引数を並べたコマンド
|
|
314
|
+
* @param options - engineを起動する作業ディレクトリを持つ条件
|
|
315
|
+
* @returns 終了codeと標準出力と標準エラーを持つ結果
|
|
290
316
|
*/
|
|
291
317
|
export async function runEngineProcess(
|
|
292
318
|
command: string[],
|