Skip to content

Commit 1ca4d2c

Browse files
authored
feat: improve linter (#154)
1 parent 9515c46 commit 1ca4d2c

File tree

5 files changed

+978
-229
lines changed

5 files changed

+978
-229
lines changed

apps/cli/src/command/lint.command.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import pluralize from 'pluralize';
44
import { ZodError } from 'zod';
55

66
import { check } from '../linter';
7+
import { SignaleRenderer } from '../utils/listr';
78
import { LoadLocalConfigurationTask } from './diff.command';
89
import { BaseCommand } from './helper';
910

@@ -28,7 +29,15 @@ export const LintTask = (): ListrTask<{ local: ADCSDK.Configuration }> => ({
2829

2930
// normal case
3031
const resourceType = pluralize.singular(error.path[0] as string);
31-
const resourceName = ctx.local[error.path[0]][error.path[1]].name;
32+
const resource = ctx.local[error.path[0]][error.path[1]];
33+
const resourceName =
34+
resourceType === 'global_rule' || resourceType === 'plugin_metadata'
35+
? error.path[1]
36+
: resourceType === 'ssl'
37+
? resource.snis
38+
: resourceType === 'consumer'
39+
? resource.username
40+
: resource.name;
3241
err += `#${idx + 1} ${
3342
error.message
3443
} at ${resourceType}: "${resourceName}", field: "${(
@@ -59,10 +68,13 @@ export const LintCommand = new BaseCommand('lint')
5968
.action(async () => {
6069
const opts = LintCommand.optsWithGlobals();
6170

62-
const tasks = new Listr([
63-
LoadLocalConfigurationTask(opts.file, {}),
64-
LintTask(),
65-
]);
71+
const tasks = new Listr(
72+
[LoadLocalConfigurationTask(opts.file, {}), LintTask()],
73+
{
74+
renderer: SignaleRenderer,
75+
rendererOptions: { verbose: opts.verbose },
76+
},
77+
);
6678

6779
try {
6880
await tasks.run();

apps/cli/src/linter/exporter.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Export jsonschema file by:
3+
*
4+
* $ ts-node apps/cli/src/linter/exporter.ts
5+
*
6+
*/
7+
import { writeFileSync } from 'fs';
8+
import zodToJsonSchema from 'zod-to-json-schema';
9+
10+
import { ConfigurationSchema } from './schema';
11+
12+
writeFileSync(
13+
'schema.json',
14+
JSON.stringify(zodToJsonSchema(ConfigurationSchema), null, 2),
15+
);

0 commit comments

Comments
 (0)