Skip to content

Commit

Permalink
fix(results): exit with status code when lint contains errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Nov 24, 2020
1 parent a51bebe commit a6c7c51
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/file-client/results-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ export function writeResults(results: LintMessage[], repository: string): void {
}

export function getResults(): string[] {
return RESULTS.length > 0 ? RESULTS : ['No errors'];
return RESULTS;
}
7 changes: 6 additions & 1 deletion lib/ui/components/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getResults } from '@file-client';
import { useExitAfterRender } from '../hooks';

const START_MESSAGE = '\nResults:';
const NO_ERRORS = ['No errors'];

/**
* Results of the scan
Expand All @@ -13,7 +14,11 @@ const START_MESSAGE = '\nResults:';
export default function Results(): JSX.Element {
useExitAfterRender();

const items: string[] = [START_MESSAGE, ...getResults()];
const results = getResults();
const items: string[] = [
START_MESSAGE,
...(results.length > 0 ? results : NO_ERRORS),
];

return (
<Static items={items}>
Expand Down
6 changes: 5 additions & 1 deletion lib/ui/hooks/useExitAfterRender.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useLayoutEffect, useState } from 'react';
import { useApp } from 'ink';

import { getResults } from '@file-client';

/**
* Hook for exiting application and process after one final re-render
*/
Expand All @@ -14,8 +16,10 @@ export function useExitAfterRender(): void {

useLayoutEffect(() => {
if (hasRendered) {
const exitCode = getResults().length > 0 ? 1 : undefined;

exit();
process.exit();
process.exit(exitCode);
}
}, [hasRendered, exit]);
}
4 changes: 4 additions & 0 deletions test/integration/integration.ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,8 @@ describe('CI mode', () => {
expect(secondRunWrites.some(call => /PULLING/.test(call))).toBe(true);
expect(fs.existsSync(cachedRepository)).toBe(true);
});

test('exits process with error code', async () => {
expect(process.exit).toHaveBeenCalledWith(1);
});
});

0 comments on commit a6c7c51

Please sign in to comment.