Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/cli/src/commands/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,15 @@ describe('lint', () => {

expect(process.stderr.write).nthCalledWith(6, `Error #3: ${chalk.red('original exception')}\n`);
});

it('writes output for dashed formats via --output.<format> (#2926)', async () => {
(formatOutput as jest.Mock).mockReturnValue('<formatted output>');

await run(
`lint --format github-actions --format code-climate --output.github-actions ga.txt --output.code-climate cc.json ./__fixtures__/empty-oas2-document.json`,
);
expect(writeOutput).toBeCalledTimes(2);
expect(writeOutput).toHaveBeenCalledWith('<formatted output>', 'ga.txt');
expect(writeOutput).toHaveBeenCalledWith('<formatted output>', 'cc.json');
});
});
18 changes: 17 additions & 1 deletion packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DiagnosticSeverity, Dictionary } from '@stoplight/types';
import { isPlainObject } from '@stoplight/json';
import { getDiagnosticSeverity, IRuleResult } from '@stoplight/spectral-core';
import { difference, isError, pick } from 'lodash';
import { camelCase, difference, isError, pick } from 'lodash';
import type { ReadStream } from 'tty';
import type { CommandModule } from 'yargs';
import * as process from 'process';
Expand Down Expand Up @@ -114,6 +114,22 @@ const lintCommand: CommandModule = {
alias: 'o',
description: `where to output results, can be a single file name, multiple "output.<format>" or missing to print to stdout`,
type: 'string',
// yargs camel-cases dotted keys, so `--output.github-actions` becomes
// `githubActions` (and may duplicate the original). Re-key the object by
// the canonical format names so dashed formats line up with `--format`.
coerce(value: unknown): unknown {
if (!isPlainObject(value)) return value;
const raw = value as Dictionary<unknown>;
const normalized: Dictionary<unknown> = {};
for (const format of formatOptions) {
if (format in raw) {
normalized[format] = raw[format];
} else if (camelCase(format) in raw) {
normalized[format] = raw[camelCase(format)];
}
}
return normalized;
},
},
'stdin-filepath': {
description: 'path to a file to pretend that stdin comes from',
Expand Down