@yuu1111/quality-check 0.6.0 → 0.7.1

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 CHANGED
@@ -35,8 +35,16 @@ export default defineConfig({
35
35
  "tsdoc-check": true,
36
36
  },
37
37
  config: {
38
- "comment-check": { ignore: ["another-project"] },
39
- "tsdoc-check": { error: ["missing-doc"] },
38
+ "comment-check": {
39
+ enable: ["japanese-period"],
40
+ ignore: ["another-project"],
41
+ },
42
+ "document-style-check": {
43
+ enable: ["japanese-period"],
44
+ },
45
+ "tsdoc-check": {
46
+ error: ["missing-doc"],
47
+ },
40
48
  },
41
49
  });
42
50
  ```
@@ -67,15 +75,15 @@ quality-check: 1 of 3 engines failed
67
75
 
68
76
  engineは `biome` → `typecheck` → `knip` → `comment-check` → `document-style-check` → `tsdoc-check` の順に実行する
69
77
 
70
- `engines` は起動の委任だけを表し、起動条件は `config` のengineの下へ置く engineが受け取る条件は次のとおり
78
+ `engines` は起動の委任だけを表し、起動条件は `config` のengineの下へ置く engineごとの条件は複数行のobjectとして書き、ruleやoptionを足しても他のengineの行が動かないようにする engineが受け取る条件は次のとおり
71
79
 
72
80
  | engine | 起動するcommand | 受け取る条件 |
73
81
  |--------|-----------------|--------------|
74
82
  | `biome` | `biome check` | `targets`、`args` 除外pathは `biome.json` が持つ |
75
83
  | `typecheck` | `tsc --noEmit` | `args`、`projects` 設定は `tsconfig.json` が持つ |
76
84
  | `knip` | `knip` | `args` 設定は `knip.ts` が持つ |
77
- | `comment-check` | `comment-check --json` | `ignore`、`targets`、`args` |
78
- | `document-style-check` | `document-style-check lint --json` | `ignore`、`targets`、`args` |
85
+ | `comment-check` | `comment-check --json` | `ignore`、`targets`、`args`、`enable`(有効にするrule名) |
86
+ | `document-style-check` | `document-style-check lint --json` | `ignore`、`targets`、`args`、`enable`(有効にするrule名) |
79
87
  | `tsdoc-check` | `tsdoc-check --json` | `ignore`、`targets`、`args`、`error`(違反として扱うrule名) |
80
88
 
81
89
  `args` はengineの既定引数の後ろへ足す 設定fileで表せない起動条件や、engineの引数が変わったときの逃げ道として使う
@@ -113,5 +121,7 @@ engineのbinaryは利用Projectの `node_modules/.bin` から実行時に解決
113
121
 
114
122
  `comment-check` はbaseline差分を無効化する未作成のpathを渡して起動する 新規と解消済みの判定はengineごとではなく統合CLIが1つのbaseline fileで行うため、既存の `comment-baseline.json` がある場合は `--update-baseline` で移す
115
123
 
124
+ `enable` は `comment-check` と `document-style-check` のopt-in ruleだけを受け取り、それぞれのcommandの `--enable <rule>` になる 他のengineへ書くとunknown optionとして拒否し、既定のrule集合は変えない このCLIはengineを同梱しないため、opt-in ruleを有効にするProjectは対応するengine packageも同じ変更で更新する
125
+
116
126
  `typecheck` は `projects` に並べたtsconfigごとに `tsc --noEmit -p <path>` を起動する 省略時はカレントの `tsconfig.json` を1回だけ読み、`args` はすべての起動へ足す
117
127
 
package/README.md CHANGED
@@ -38,8 +38,16 @@ export default defineConfig({
38
38
  "tsdoc-check": true,
39
39
  },
40
40
  config: {
41
- "comment-check": { ignore: ["another-project"] },
42
- "tsdoc-check": { error: ["missing-doc"] },
41
+ "comment-check": {
42
+ enable: ["japanese-period"],
43
+ ignore: ["another-project"],
44
+ },
45
+ "document-style-check": {
46
+ enable: ["japanese-period"],
47
+ },
48
+ "tsdoc-check": {
49
+ error: ["missing-doc"],
50
+ },
43
51
  },
44
52
  });
45
53
  ```
@@ -73,15 +81,16 @@ Engines run in the order `biome`, `typecheck`, `knip`, `comment-check`,
73
81
  `document-style-check`, `tsdoc-check`.
74
82
 
75
83
  `engines` only delegates the start-up, and the conditions belong under the
76
- engine in `config`. Each engine runs:
84
+ engine in `config`. Write an engine's conditions as a multi-line object, so a
85
+ new rule or option changes one engine's block alone. Each engine runs:
77
86
 
78
87
  | Engine | Command | Conditions |
79
88
  |--------|---------|------------|
80
89
  | `biome` | `biome check` | `targets`, `args`; `biome.json` holds the excluded paths |
81
90
  | `typecheck` | `tsc --noEmit` | `args`, `projects`; `tsconfig.json` holds the settings |
82
91
  | `knip` | `knip` | `args`; `knip.ts` holds the settings |
83
- | `comment-check` | `comment-check --json` | `ignore`, `targets`, `args` |
84
- | `document-style-check` | `document-style-check lint --json` | `ignore`, `targets`, `args` |
92
+ | `comment-check` | `comment-check --json` | `ignore`, `targets`, `args`, `enable` (rule names to turn on) |
93
+ | `document-style-check` | `document-style-check lint --json` | `ignore`, `targets`, `args`, `enable` (rule names to turn on) |
85
94
  | `tsdoc-check` | `tsdoc-check --json` | `ignore`, `targets`, `args`, `error` (rule names to fail on) |
86
95
 
87
96
  `args` is appended after the engine defaults, for conditions the config cannot
@@ -132,6 +141,12 @@ finding. The new-and-resolved diff is done by this CLI from a single baseline
132
141
  file, so an existing `comment-baseline.json` is moved over with
133
142
  `--update-baseline`.
134
143
 
144
+ `enable` names the opt-in rules of `comment-check` and `document-style-check`
145
+ and becomes `--enable <rule>` on each of their commands. The other engines
146
+ reject the field, and the default rule set stays as it is. This CLI ships no
147
+ engine of its own, so a project that turns an opt-in rule on updates the
148
+ matching engine package in the same change.
149
+
135
150
  `typecheck` starts `tsc --noEmit -p <path>` once per path in `projects`. Without
136
151
  it the current `tsconfig.json` is read once, and `args` are added to every
137
152
  start.
package/bin/cli.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bun
2
+ import { run } from "../dist/cli.js";
3
+
4
+ run();
package/dist/cli.js CHANGED
@@ -219,8 +219,8 @@ var ENGINE_OPTION_KEYS = {
219
219
  biome: ["args", "ignore", "targets"],
220
220
  typecheck: ["args", "ignore", "projects", "targets"],
221
221
  knip: ["args", "ignore", "targets"],
222
- "comment-check": ["args", "ignore", "targets"],
223
- "document-style-check": ["args", "ignore", "targets"],
222
+ "comment-check": ["args", "enable", "ignore", "targets"],
223
+ "document-style-check": ["args", "enable", "ignore", "targets"],
224
224
  "tsdoc-check": ["args", "error", "ignore", "targets"]
225
225
  };
226
226
  function readStringArray(value, field) {
@@ -260,6 +260,31 @@ function parseEngines(value, source) {
260
260
  }
261
261
  return engines;
262
262
  }
263
+ function parseEngineExtras(value, source, name) {
264
+ const extras = {};
265
+ if (name === "comment-check" || name === "document-style-check") {
266
+ const enable = readStringArray(value.enable, `${source}: config.${name}.enable`);
267
+ if (enable !== undefined) {
268
+ extras.enable = enable;
269
+ }
270
+ }
271
+ if (name === "tsdoc-check") {
272
+ const error = readStringArray(value.error, `${source}: config.${name}.error`);
273
+ if (error !== undefined) {
274
+ extras.error = error;
275
+ }
276
+ }
277
+ if (name === "typecheck") {
278
+ const projects = readStringArray(value.projects, `${source}: config.${name}.projects`);
279
+ if (projects !== undefined) {
280
+ if (projects.length === 0) {
281
+ throw new Error(`${source}: config.${name}.projects must not be empty`);
282
+ }
283
+ extras.projects = projects;
284
+ }
285
+ }
286
+ return extras;
287
+ }
263
288
  function parseEngineOptions(value, source, name) {
264
289
  const unknown = Object.keys(value).filter((key) => !ENGINE_OPTION_KEYS[name].includes(key));
265
290
  if (unknown.length > 0) {
@@ -278,22 +303,7 @@ function parseEngineOptions(value, source, name) {
278
303
  if (args !== undefined) {
279
304
  options.args = args;
280
305
  }
281
- if (name === "tsdoc-check") {
282
- const error = readStringArray(value.error, `${source}: config.${name}.error`);
283
- if (error !== undefined) {
284
- options.error = error;
285
- }
286
- }
287
- if (name === "typecheck") {
288
- const projects = readStringArray(value.projects, `${source}: config.${name}.projects`);
289
- if (projects !== undefined) {
290
- if (projects.length === 0) {
291
- throw new Error(`${source}: config.${name}.projects must not be empty`);
292
- }
293
- options.projects = projects;
294
- }
295
- }
296
- return options;
306
+ return { ...options, ...parseEngineExtras(value, source, name) };
297
307
  }
298
308
  function parseEngineConfig(value, source) {
299
309
  if (value === undefined) {
@@ -446,6 +456,9 @@ function buildTypecheckCommand(executable, context, project) {
446
456
  ...options.args ?? []
447
457
  ];
448
458
  }
459
+ function enableArguments(options) {
460
+ return (options?.enable ?? []).flatMap((rule) => ["--enable", rule]);
461
+ }
449
462
  function buildEngineCommand(name, executable, context) {
450
463
  const options = engineConfig(context.config, name) ?? {};
451
464
  const limits = ENGINE_LIMITS[name];
@@ -477,6 +490,7 @@ function buildEngineCommand(name, executable, context) {
477
490
  "--json",
478
491
  "--baseline",
479
492
  context.rawBaseline,
493
+ ...enableArguments(engineConfig(context.config, "comment-check")),
480
494
  ...targets,
481
495
  ...ignoreArguments,
482
496
  ...extra
@@ -487,6 +501,7 @@ function buildEngineCommand(name, executable, context) {
487
501
  executable,
488
502
  "lint",
489
503
  "--json",
504
+ ...enableArguments(engineConfig(context.config, "document-style-check")),
490
505
  ...targets,
491
506
  ...ignoreArguments,
492
507
  ...extra
@@ -843,4 +858,12 @@ async function main(argv) {
843
858
  }
844
859
  return results.some((result) => result.status !== "passed") ? 1 : 0;
845
860
  }
846
- runCli(main);
861
+ function run() {
862
+ runCli(main);
863
+ }
864
+ if (import.meta.main) {
865
+ run();
866
+ }
867
+ export {
868
+ run
869
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuu1111/quality-check",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Integrated quality check runner",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "type": "module",
11
11
  "bin": {
12
- "quality-check": "dist/cli.js"
12
+ "quality-check": "bin/cli.js"
13
13
  },
14
14
  "exports": {
15
15
  ".": "./src/config.ts",
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "files": [
19
19
  "README.ja.md",
20
+ "bin",
20
21
  "src/config.ts",
21
22
  "src/engines.ts",
22
23
  "dist"
package/src/config.ts CHANGED
@@ -31,6 +31,22 @@ export interface EngineOptions {
31
31
  args?: string[];
32
32
  }
33
33
 
34
+ /**
35
+ * comment-checkへ渡す起動条件
36
+ */
37
+ export interface CommentCheckOptions extends EngineOptions {
38
+ /** 既定で無効のopt-in ruleのうち有効にするrule名 */
39
+ enable?: string[];
40
+ }
41
+
42
+ /**
43
+ * document-style-checkへ渡す起動条件
44
+ */
45
+ export interface DocumentStyleCheckOptions extends EngineOptions {
46
+ /** 既定で無効のopt-in ruleのうち有効にするrule名 */
47
+ enable?: string[];
48
+ }
49
+
34
50
  /**
35
51
  * TSDoc検査へ渡す起動条件
36
52
  */
@@ -54,8 +70,8 @@ export interface EngineConfigMap {
54
70
  biome: EngineOptions;
55
71
  typecheck: TypecheckOptions;
56
72
  knip: EngineOptions;
57
- "comment-check": EngineOptions;
58
- "document-style-check": EngineOptions;
73
+ "comment-check": CommentCheckOptions;
74
+ "document-style-check": DocumentStyleCheckOptions;
59
75
  "tsdoc-check": TsdocCheckOptions;
60
76
  }
61
77
 
@@ -107,8 +123,8 @@ const ENGINE_OPTION_KEYS: Record<EngineName, readonly string[]> = {
107
123
  biome: ["args", "ignore", "targets"],
108
124
  typecheck: ["args", "ignore", "projects", "targets"],
109
125
  knip: ["args", "ignore", "targets"],
110
- "comment-check": ["args", "ignore", "targets"],
111
- "document-style-check": ["args", "ignore", "targets"],
126
+ "comment-check": ["args", "enable", "ignore", "targets"],
127
+ "document-style-check": ["args", "enable", "ignore", "targets"],
112
128
  "tsdoc-check": ["args", "error", "ignore", "targets"],
113
129
  };
114
130
 
@@ -164,10 +180,53 @@ function parseEngines(
164
180
  }
165
181
 
166
182
  type ParsedEngineOptions = EngineOptions & {
183
+ enable?: string[];
167
184
  error?: string[];
168
185
  projects?: string[];
169
186
  };
170
187
 
188
+ /**
189
+ * engine名ごとにしか受け取らない起動条件を読み取る
190
+ */
191
+ function parseEngineExtras(
192
+ value: JsonObject,
193
+ source: string,
194
+ name: EngineName,
195
+ ): ParsedEngineOptions {
196
+ const extras: ParsedEngineOptions = {};
197
+ if (name === "comment-check" || name === "document-style-check") {
198
+ const enable = readStringArray(
199
+ value.enable,
200
+ `${source}: config.${name}.enable`,
201
+ );
202
+ if (enable !== undefined) {
203
+ extras.enable = enable;
204
+ }
205
+ }
206
+ if (name === "tsdoc-check") {
207
+ const error = readStringArray(
208
+ value.error,
209
+ `${source}: config.${name}.error`,
210
+ );
211
+ if (error !== undefined) {
212
+ extras.error = error;
213
+ }
214
+ }
215
+ if (name === "typecheck") {
216
+ const projects = readStringArray(
217
+ value.projects,
218
+ `${source}: config.${name}.projects`,
219
+ );
220
+ if (projects !== undefined) {
221
+ if (projects.length === 0) {
222
+ throw new Error(`${source}: config.${name}.projects must not be empty`);
223
+ }
224
+ extras.projects = projects;
225
+ }
226
+ }
227
+ return extras;
228
+ }
229
+
171
230
  function parseEngineOptions(
172
231
  value: JsonObject,
173
232
  source: string,
@@ -200,28 +259,7 @@ function parseEngineOptions(
200
259
  if (args !== undefined) {
201
260
  options.args = args;
202
261
  }
203
- if (name === "tsdoc-check") {
204
- const error = readStringArray(
205
- value.error,
206
- `${source}: config.${name}.error`,
207
- );
208
- if (error !== undefined) {
209
- options.error = error;
210
- }
211
- }
212
- if (name === "typecheck") {
213
- const projects = readStringArray(
214
- value.projects,
215
- `${source}: config.${name}.projects`,
216
- );
217
- if (projects !== undefined) {
218
- if (projects.length === 0) {
219
- throw new Error(`${source}: config.${name}.projects must not be empty`);
220
- }
221
- options.projects = projects;
222
- }
223
- }
224
- return options;
262
+ return { ...options, ...parseEngineExtras(value, source, name) };
225
263
  }
226
264
 
227
265
  function parseEngineConfig(
package/src/engines.ts CHANGED
@@ -179,6 +179,15 @@ function buildTypecheckCommand(
179
179
  ];
180
180
  }
181
181
 
182
+ /**
183
+ * opt-in ruleを有効にするコマンド引数へ展開する
184
+ */
185
+ function enableArguments(
186
+ options: { enable?: string[] } | null | undefined,
187
+ ): string[] {
188
+ return (options?.enable ?? []).flatMap((rule) => ["--enable", rule]);
189
+ }
190
+
182
191
  /**
183
192
  * engineへ渡すコマンドを組み立てる
184
193
  */
@@ -223,6 +232,7 @@ export function buildEngineCommand(
223
232
  "--json",
224
233
  "--baseline",
225
234
  context.rawBaseline,
235
+ ...enableArguments(engineConfig(context.config, "comment-check")),
226
236
  ...targets,
227
237
  ...ignoreArguments,
228
238
  ...extra,
@@ -233,6 +243,7 @@ export function buildEngineCommand(
233
243
  executable,
234
244
  "lint",
235
245
  "--json",
246
+ ...enableArguments(engineConfig(context.config, "document-style-check")),
236
247
  ...targets,
237
248
  ...ignoreArguments,
238
249
  ...extra,