Skip to content

Commit

Permalink
feat: split rule and helpers, test rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Nov 3, 2019
1 parent f805945 commit b3dc864
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 237 deletions.
1 change: 1 addition & 0 deletions config/rollup.js
Expand Up @@ -85,6 +85,7 @@ const bundle = {
'BaseError',
'ConsoleLogger',
'logWithLevel',
'NullLogger',
],
'node_modules/js-yaml/index.js': [
'DEFAULT_SAFE_SCHEMA',
Expand Down
3 changes: 3 additions & 0 deletions examples/kubernetes-resources-some.yml
Expand Up @@ -31,13 +31,16 @@ spec:
resources:
limits:
cpu: 200m
# missing memory
requests:
cpu: 100m
# same rule

---

metadata:
name: example
# missing labels
spec:
template:
spec:
Expand Down
19 changes: 10 additions & 9 deletions src/index.ts
Expand Up @@ -3,7 +3,8 @@ import { createLogger } from 'bunyan';
import { loadConfig } from './config';
import { CONFIG_ARGS_NAME, CONFIG_ARGS_PATH, parseArgs } from './config/args';
import { YamlParser } from './parser/YamlParser';
import { loadRules, resolveRules, visitRules } from './rule';
import { loadRules, resolveRules } from './rule';
import { visitRules } from './rule/SchemaRule';
import { loadSource, writeSource } from './source';
import { VERSION_INFO } from './version';
import { VisitorContext } from './visitor/VisitorContext';
Expand Down Expand Up @@ -59,19 +60,19 @@ export async function main(argv: Array<string>): Promise<number> {
await visitRules(ctx, activeRules, data);
}

if (ctx.errors.length > 0) {
logger.error({ count: ctx.errors.length, errors: ctx.errors }, 'some rules failed');
if (args.count) {
return Math.min(ctx.errors.length, STATUS_MAX);
} else {
return STATUS_ERROR;
}
} else {
if (ctx.errors.length === 0) {
logger.info('all rules passed');
const output = parser.dump(...docs);
await writeSource(args.dest, output);
return STATUS_SUCCESS;
}

logger.error({ count: ctx.errors.length, errors: ctx.errors }, 'some rules failed');
if (args.count) {
return Math.min(ctx.errors.length, STATUS_MAX);
}

return STATUS_ERROR;
}

main(process.argv).then((status) => process.exit(status)).catch((err) => {
Expand Down
218 changes: 0 additions & 218 deletions src/rule.ts

This file was deleted.

0 comments on commit b3dc864

Please sign in to comment.