check-my-toolkit 0.1.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.md +2 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +116 -0
- package/dist/cli.js.map +1 -0
- package/dist/code/audit.d.ts +14 -0
- package/dist/code/audit.d.ts.map +1 -0
- package/dist/code/audit.js +130 -0
- package/dist/code/audit.js.map +1 -0
- package/dist/code/index.d.ts +13 -0
- package/dist/code/index.d.ts.map +1 -0
- package/dist/code/index.js +49 -0
- package/dist/code/index.js.map +1 -0
- package/dist/code/linting.d.ts +10 -0
- package/dist/code/linting.d.ts.map +1 -0
- package/dist/code/linting.js +233 -0
- package/dist/code/linting.js.map +1 -0
- package/dist/code/tools/base.d.ts +52 -0
- package/dist/code/tools/base.d.ts.map +1 -0
- package/dist/code/tools/base.js +83 -0
- package/dist/code/tools/base.js.map +1 -0
- package/dist/code/tools/eslint.d.ts +15 -0
- package/dist/code/tools/eslint.d.ts.map +1 -0
- package/dist/code/tools/eslint.js +79 -0
- package/dist/code/tools/eslint.js.map +1 -0
- package/dist/code/tools/index.d.ts +5 -0
- package/dist/code/tools/index.d.ts.map +1 -0
- package/dist/code/tools/index.js +5 -0
- package/dist/code/tools/index.js.map +1 -0
- package/dist/code/tools/ruff.d.ts +26 -0
- package/dist/code/tools/ruff.d.ts.map +1 -0
- package/dist/code/tools/ruff.js +149 -0
- package/dist/code/tools/ruff.js.map +1 -0
- package/dist/code/tools/tsc.d.ts +20 -0
- package/dist/code/tools/tsc.d.ts.map +1 -0
- package/dist/code/tools/tsc.js +90 -0
- package/dist/code/tools/tsc.js.map +1 -0
- package/dist/code/types.d.ts +6 -0
- package/dist/code/types.d.ts.map +1 -0
- package/dist/code/types.js +132 -0
- package/dist/code/types.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +21 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +118 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +1217 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +190 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/output/index.d.ts +15 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +98 -0
- package/dist/output/index.js.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +116 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/code/index.d.ts +13 -0
- package/dist/src/code/index.d.ts.map +1 -0
- package/dist/src/code/index.js +53 -0
- package/dist/src/code/index.js.map +1 -0
- package/dist/src/code/tools/base.d.ts +52 -0
- package/dist/src/code/tools/base.d.ts.map +1 -0
- package/dist/src/code/tools/base.js +83 -0
- package/dist/src/code/tools/base.js.map +1 -0
- package/dist/src/code/tools/eslint.d.ts +15 -0
- package/dist/src/code/tools/eslint.d.ts.map +1 -0
- package/dist/src/code/tools/eslint.js +79 -0
- package/dist/src/code/tools/eslint.js.map +1 -0
- package/dist/src/code/tools/index.d.ts +5 -0
- package/dist/src/code/tools/index.d.ts.map +1 -0
- package/dist/src/code/tools/index.js +5 -0
- package/dist/src/code/tools/index.js.map +1 -0
- package/dist/src/code/tools/ruff.d.ts +26 -0
- package/dist/src/code/tools/ruff.d.ts.map +1 -0
- package/dist/src/code/tools/ruff.js +149 -0
- package/dist/src/code/tools/ruff.js.map +1 -0
- package/dist/src/code/tools/tsc.d.ts +21 -0
- package/dist/src/code/tools/tsc.d.ts.map +1 -0
- package/dist/src/code/tools/tsc.js +94 -0
- package/dist/src/code/tools/tsc.js.map +1 -0
- package/dist/src/config/index.d.ts +3 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +3 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/loader.d.ts +22 -0
- package/dist/src/config/loader.d.ts.map +1 -0
- package/dist/src/config/loader.js +124 -0
- package/dist/src/config/loader.js.map +1 -0
- package/dist/src/config/schema.d.ts +503 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +190 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +16 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/output/index.d.ts +15 -0
- package/dist/src/output/index.d.ts.map +1 -0
- package/dist/src/output/index.js +96 -0
- package/dist/src/output/index.js.map +1 -0
- package/dist/src/types/index.d.ts +96 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +89 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/tests/e2e/e2e.test.d.ts +2 -0
- package/dist/tests/e2e/e2e.test.d.ts.map +1 -0
- package/dist/tests/e2e/e2e.test.js +398 -0
- package/dist/tests/e2e/e2e.test.js.map +1 -0
- package/dist/types/index.d.ts +96 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +89 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { execa } from "execa";
|
|
4
|
+
/**
|
|
5
|
+
* Parse tsc output into structured diagnostics
|
|
6
|
+
* Format: file(line,col): error TSxxxx: message
|
|
7
|
+
*/
|
|
8
|
+
function parseTscOutput(output, projectRoot) {
|
|
9
|
+
const diagnostics = [];
|
|
10
|
+
const lines = output.split("\n");
|
|
11
|
+
// Regex to match tsc error format: file(line,col): error TSxxxx: message
|
|
12
|
+
const errorRegex = /^(.+?)\((\d+),(\d+)\):\s*error\s+TS(\d+):\s*(.+)$/;
|
|
13
|
+
for (const line of lines) {
|
|
14
|
+
const match = errorRegex.exec(line);
|
|
15
|
+
if (match) {
|
|
16
|
+
const [, filePath, lineNum, colNum, code, message] = match;
|
|
17
|
+
diagnostics.push({
|
|
18
|
+
file: path.relative(projectRoot, filePath),
|
|
19
|
+
line: parseInt(lineNum, 10),
|
|
20
|
+
column: parseInt(colNum, 10),
|
|
21
|
+
code: parseInt(code, 10),
|
|
22
|
+
message: message.trim(),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return diagnostics;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Run TypeScript type checking and return violations
|
|
30
|
+
*/
|
|
31
|
+
export async function runTsc(projectRoot) {
|
|
32
|
+
const startTime = Date.now();
|
|
33
|
+
const violations = [];
|
|
34
|
+
// Check if tsconfig.json exists
|
|
35
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
36
|
+
if (!fs.existsSync(tsconfigPath)) {
|
|
37
|
+
return {
|
|
38
|
+
name: "TypeScript",
|
|
39
|
+
rule: "code.types",
|
|
40
|
+
passed: true,
|
|
41
|
+
violations: [],
|
|
42
|
+
skipped: true,
|
|
43
|
+
skipReason: "No tsconfig.json found",
|
|
44
|
+
duration: Date.now() - startTime,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
// Run tsc with --noEmit to only check types
|
|
49
|
+
const result = await execa("npx", ["tsc", "--noEmit"], {
|
|
50
|
+
cwd: projectRoot,
|
|
51
|
+
reject: false,
|
|
52
|
+
timeout: 5 * 60 * 1000, // 5 minutes
|
|
53
|
+
});
|
|
54
|
+
// tsc exits with 0 if no errors, non-zero if errors
|
|
55
|
+
if (result.exitCode === 0) {
|
|
56
|
+
return {
|
|
57
|
+
name: "TypeScript",
|
|
58
|
+
rule: "code.types",
|
|
59
|
+
passed: true,
|
|
60
|
+
violations: [],
|
|
61
|
+
skipped: false,
|
|
62
|
+
duration: Date.now() - startTime,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Parse the output for errors
|
|
66
|
+
const diagnostics = parseTscOutput(result.stdout, projectRoot);
|
|
67
|
+
// Convert to violations
|
|
68
|
+
for (const diag of diagnostics) {
|
|
69
|
+
violations.push({
|
|
70
|
+
rule: "code.types.tsc",
|
|
71
|
+
tool: "tsc",
|
|
72
|
+
file: diag.file,
|
|
73
|
+
line: diag.line,
|
|
74
|
+
column: diag.column,
|
|
75
|
+
message: diag.message,
|
|
76
|
+
code: `TS${diag.code}`,
|
|
77
|
+
severity: "error",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// If we couldn't parse any diagnostics but tsc failed, report the raw output
|
|
81
|
+
if (violations.length === 0 && result.exitCode !== 0) {
|
|
82
|
+
const errorOutput = result.stdout || result.stderr;
|
|
83
|
+
if (errorOutput) {
|
|
84
|
+
violations.push({
|
|
85
|
+
rule: "code.types.tsc",
|
|
86
|
+
tool: "tsc",
|
|
87
|
+
message: `TypeScript error: ${errorOutput.slice(0, 500)}`,
|
|
88
|
+
severity: "error",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
name: "TypeScript",
|
|
94
|
+
rule: "code.types",
|
|
95
|
+
passed: violations.length === 0,
|
|
96
|
+
violations,
|
|
97
|
+
skipped: false,
|
|
98
|
+
duration: Date.now() - startTime,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
// tsc not installed or other error
|
|
103
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
104
|
+
if (errorMessage.includes("ENOENT") || errorMessage.includes("not found")) {
|
|
105
|
+
return {
|
|
106
|
+
name: "TypeScript",
|
|
107
|
+
rule: "code.types",
|
|
108
|
+
passed: true,
|
|
109
|
+
violations: [],
|
|
110
|
+
skipped: true,
|
|
111
|
+
skipReason: "TypeScript not installed",
|
|
112
|
+
duration: Date.now() - startTime,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
name: "TypeScript",
|
|
117
|
+
rule: "code.types",
|
|
118
|
+
passed: false,
|
|
119
|
+
violations: [
|
|
120
|
+
{
|
|
121
|
+
rule: "code.types.tsc",
|
|
122
|
+
tool: "tsc",
|
|
123
|
+
message: `TypeScript error: ${errorMessage}`,
|
|
124
|
+
severity: "error",
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
skipped: false,
|
|
128
|
+
duration: Date.now() - startTime,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/code/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAY9B;;;GAGG;AACH,SAAS,cAAc,CAAC,MAAc,EAAE,WAAmB;IACzD,MAAM,WAAW,GAAoB,EAAE,CAAC;IACxC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEjC,yEAAyE;IACzE,MAAM,UAAU,GAAG,mDAAmD,CAAC;IAEvE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;YAC3D,WAAW,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC;gBAC1C,I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,GAAG,EAAE,GAAG,SAAS;SACjC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC;QACnC,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QAE9E,IAAI,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1E,OAAO;gBACL,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,YAAY;gBAClB,MAAM,EAAE,IAAI;gBACZ,UAAU,EAAE,EAAE;gBACd,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,0BAA0B;gBACtC,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;aACjC,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,KAAK;YACb,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,gBAAgB;oBACtB,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,qBAAqB,YAAY,EAAE;oBAC5C,QAAQ,EAAE,OAAO;iBAClB;aACF;YACD,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;SACjC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAC,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAC,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAU,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Config } from "./schema.js";
|
|
2
|
+
export interface LoadConfigResult {
|
|
3
|
+
config: Config;
|
|
4
|
+
configPath: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class ConfigError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Find check.toml by walking up the directory tree
|
|
11
|
+
*/
|
|
12
|
+
export declare function findConfigFile(startDir?: string): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Load and parse check.toml configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadConfig(configPath?: string): LoadConfigResult;
|
|
17
|
+
/**
|
|
18
|
+
* Get the project root directory (where check.toml is located)
|
|
19
|
+
*/
|
|
20
|
+
export declare function getProjectRoot(configPath: string): string;
|
|
21
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,MAAM,EAA+B,MAAM,aAAa,CAAC;AAEvE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAmB9E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,gBAAgB,CA2ChE;AA6CD;;GAEG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import TOML from "@iarna/toml";
|
|
4
|
+
import { configSchema, defaultConfig } from "./schema.js";
|
|
5
|
+
export class ConfigError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "ConfigError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Find check.toml by walking up the directory tree
|
|
13
|
+
*/
|
|
14
|
+
export function findConfigFile(startDir = process.cwd()) {
|
|
15
|
+
let currentDir = path.resolve(startDir);
|
|
16
|
+
const root = path.parse(currentDir).root;
|
|
17
|
+
while (currentDir !== root) {
|
|
18
|
+
const configPath = path.join(currentDir, "check.toml");
|
|
19
|
+
if (fs.existsSync(configPath)) {
|
|
20
|
+
return configPath;
|
|
21
|
+
}
|
|
22
|
+
currentDir = path.dirname(currentDir);
|
|
23
|
+
}
|
|
24
|
+
// Check root directory too
|
|
25
|
+
const rootConfig = path.join(root, "check.toml");
|
|
26
|
+
if (fs.existsSync(rootConfig)) {
|
|
27
|
+
return rootConfig;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Load and parse check.toml configuration
|
|
33
|
+
*/
|
|
34
|
+
export function loadConfig(configPath) {
|
|
35
|
+
// Find config file if not specified
|
|
36
|
+
const resolvedPath = configPath ?? findConfigFile();
|
|
37
|
+
if (!resolvedPath) {
|
|
38
|
+
throw new ConfigError("No check.toml found. Run 'cm init' to create one or specify --config path.");
|
|
39
|
+
}
|
|
40
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
41
|
+
throw new ConfigError(`Config file not found: ${resolvedPath}`);
|
|
42
|
+
}
|
|
43
|
+
// Read and parse TOML
|
|
44
|
+
let rawConfig;
|
|
45
|
+
try {
|
|
46
|
+
const content = fs.readFileSync(resolvedPath, "utf-8");
|
|
47
|
+
rawConfig = TOML.parse(content);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error instanceof Error) {
|
|
51
|
+
throw new ConfigError(`Failed to parse check.toml: ${error.message}`);
|
|
52
|
+
}
|
|
53
|
+
throw new ConfigError("Failed to parse check.toml");
|
|
54
|
+
}
|
|
55
|
+
// Validate with Zod
|
|
56
|
+
const result = configSchema.safeParse(rawConfig);
|
|
57
|
+
if (!result.success) {
|
|
58
|
+
const errors = result.error.errors
|
|
59
|
+
.map((e) => ` - ${e.path.join(".")}: ${e.message}`)
|
|
60
|
+
.join("\n");
|
|
61
|
+
throw new ConfigError(`Invalid check.toml configuration:\n${errors}`);
|
|
62
|
+
}
|
|
63
|
+
// Merge with defaults
|
|
64
|
+
const config = mergeWithDefaults(result.data);
|
|
65
|
+
return {
|
|
66
|
+
config,
|
|
67
|
+
configPath: resolvedPath,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Deep merge config with defaults
|
|
72
|
+
*/
|
|
73
|
+
function mergeWithDefaults(config) {
|
|
74
|
+
return {
|
|
75
|
+
code: {
|
|
76
|
+
linting: {
|
|
77
|
+
eslint: {
|
|
78
|
+
enabled: config.code?.linting?.eslint?.enabled ?? defaultConfig.code?.linting?.eslint?.enabled ?? false,
|
|
79
|
+
rules: config.code?.linting?.eslint?.rules,
|
|
80
|
+
},
|
|
81
|
+
ruff: {
|
|
82
|
+
enabled: config.code?.linting?.ruff?.enabled ?? defaultConfig.code?.linting?.ruff?.enabled ?? false,
|
|
83
|
+
"line-length": config.code?.linting?.ruff?.["line-length"],
|
|
84
|
+
lint: config.code?.linting?.ruff?.lint,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
types: {
|
|
88
|
+
tsc: {
|
|
89
|
+
enabled: config.code?.types?.tsc?.enabled ?? defaultConfig.code?.types?.tsc?.enabled ?? false,
|
|
90
|
+
strict: config.code?.types?.tsc?.strict,
|
|
91
|
+
noImplicitAny: config.code?.types?.tsc?.noImplicitAny,
|
|
92
|
+
strictNullChecks: config.code?.types?.tsc?.strictNullChecks,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
complexity: config.code?.complexity ?? defaultConfig.code?.complexity ?? {},
|
|
96
|
+
files: {
|
|
97
|
+
repo: config.code?.files?.repo ?? defaultConfig.code?.files?.repo ?? [],
|
|
98
|
+
tooling: config.code?.files?.tooling ?? defaultConfig.code?.files?.tooling ?? [],
|
|
99
|
+
docs: config.code?.files?.docs ?? defaultConfig.code?.files?.docs ?? [],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
process: {
|
|
103
|
+
pr: config.process?.pr ?? defaultConfig.process?.pr ?? {},
|
|
104
|
+
branches: config.process?.branches ?? defaultConfig.process?.branches ?? {},
|
|
105
|
+
tickets: config.process?.tickets ?? defaultConfig.process?.tickets ?? {},
|
|
106
|
+
},
|
|
107
|
+
stack: {
|
|
108
|
+
tools: config.stack?.tools ?? defaultConfig.stack?.tools ?? {},
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the project root directory (where check.toml is located)
|
|
114
|
+
*/
|
|
115
|
+
export function getProjectRoot(configPath) {
|
|
116
|
+
return path.dirname(configPath);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,IAAI,MAAM,aAAa,CAAC;AAE/B,OAAO,EAAe,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAOvE,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC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