Skip to content

Commit

Permalink
feat(cli): remove --max-results flag
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Jul 8, 2019
1 parent 57eccf1 commit 633567b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ Other options include:
-e, --encoding=encoding text encoding to use
-f, --format=json|stylish formatter to use for outputting results
-h, --help show CLI help
-m, --maxResults=maxResults deprecated: use --max-results instead
-o, --output=output output to a file instead of stdout
-q, --quiet no logging - output only
-r, --ruleset=ruleset path to a ruleset file (supports remote files)
-s, --skip-rule=skip-rule ignore certain rules if they are causing trouble
-v, --verbose increase verbosity
--max-results=max-results [default: all] maximum results to show
```
> Note: The Spectral CLI supports both YAML and JSON.
Expand Down
27 changes: 14 additions & 13 deletions src/cli/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ linting ./openapi.yaml
char: 'o',
description: 'output to a file instead of stdout',
}),
'max-results': flagHelpers.integer({
description: '[default: all] maximum results to show',
}),
ruleset: flagHelpers.string({
char: 'r',
description: 'path to a ruleset file (supports remote files)',
Expand Down Expand Up @@ -137,7 +134,7 @@ async function tryReadOrLog(command: Lint, reader: Function) {
}
}

async function lint(name: string, flags: any, command: Lint, rules?: RuleCollection) {
async function lint(name: string, flags: ILintConfig, command: Lint, rules?: RuleCollection) {
if (flags.verbose) {
command.log(`Linting ${name}`);
}
Expand Down Expand Up @@ -217,24 +214,29 @@ async function lint(name: string, flags: any, command: Lint, rules?: RuleCollect
}
}

const skipRules = (rules: any, flags: any, command: Lint): any => {
const skipRules = (rules: RuleCollection, flags: ILintConfig, command: Lint): RuleCollection => {
const skippedRules: string[] = [];
const invalidRules: string[] = [];

for (const rule of flags.skipRule) {
if (rule in rules) {
delete rules[rule];
skippedRules.push(rule);
} else {
invalidRules.push(rule);
if (flags.skipRule !== undefined) {
for (const rule of flags.skipRule) {
if (rule in rules) {
delete rules[rule];
skippedRules.push(rule);
} else {
invalidRules.push(rule);
}
}
}

if (invalidRules.length !== 0) {
command.warn(`ignoring invalid ${invalidRules.length > 1 ? 'rules' : 'rule'} "${invalidRules.join(', ')}"`);
}

if (skippedRules.length !== 0 && flags.verbose) {
command.log(`INFO: skipping ${skippedRules.length > 1 ? 'rules' : 'rule'} "${skippedRules.join(', ')}"`);
}

return rules;
};

Expand All @@ -248,7 +250,7 @@ async function formatOutput(results: IRuleResult[], flags: any): Promise<string>
}[flags.format]();
}

export async function writeOutput(outputStr: string, flags: any, command: Lint) {
export async function writeOutput(outputStr: string, flags: ILintConfig, command: Lint) {
if (flags.output) {
return writeFileAsync(flags.output, outputStr);
}
Expand All @@ -264,7 +266,6 @@ function mergeConfig(config: ILintConfig, flags: Partial<ILintConfig>): ILintCon
encoding: flags.encoding,
format: flags.format,
output: flags.output,
maxResults: flags['max-results'],
verbose: flags.verbose,
ruleset: flags.ruleset,
quiet: flags.quiet,
Expand Down
1 change: 0 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export enum OutputFormat {
export interface ILintConfig {
encoding: string;
format: OutputFormat;
maxResults?: number;
output?: string;
ruleset?: string[];
skipRule?: string[];
Expand Down

0 comments on commit 633567b

Please sign in to comment.