Skip to content

Commit

Permalink
fix(tslint): fixed result from being emitted multiple times
Browse files Browse the repository at this point in the history
also simplified the result to consumer
  • Loading branch information
stephenlautier committed Mar 21, 2017
1 parent a34b623 commit 981589b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ These are all the available tasks within `speedy-build-tools` and can be added t
| `clean [paths..]` | Delete files and directories |
| `lint-html` | Lint Html files |
| `lint-sass` | Lint Sass files |
| `lint-ts` | Lint Typescript files |
| `lint-ts` | Lint TypeScript files |
___
### Clean
Expand Down Expand Up @@ -103,7 +103,7 @@ By default, it will try to locate the `.stylelintrc` file in the root of your pr
___
### Lint Typescript
### Lint TypeScript
```
speedy-build-tools lint-ts
Expand Down
5 changes: 5 additions & 0 deletions src/lint/lint-ts/lint-ts.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export interface LintTsOptions {
fix: boolean;
}

export interface LintTsResult {
failuresCount: number;
fixesCount?: number;
}

export type LintTsFormatters = "vso"
| "verbose"
| "prose"
Expand Down
41 changes: 21 additions & 20 deletions src/lint/lint-ts/lint-ts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Linter, LintResult, Configuration } from "tslint";
import { Linter, Configuration } from "tslint";

import {
Logger,
Expand All @@ -12,18 +12,18 @@ import {
readJsonFileAsync
} from "../../utils";

import { LintTsOptions } from "./lint-ts.model";
import { LintTsOptions, LintTsResult } from "./lint-ts.model";
import { ARGS } from "./lint-ts.args";

const logger = new Logger("Lint TS");

export async function lintTs(options?: Partial<LintTsOptions>): Promise<LintResult[]> {
export async function lintTs(options?: Partial<LintTsOptions>): Promise<LintTsResult> {
const timer = new Timer(logger);

try {
timer.start();
const mergedOptions = Args.mergeWithOptions(ARGS, options);
return await Worker.run<LintResult[]>(__filename, handlelintTs.name, mergedOptions);
return await Worker.run<LintTsResult>(__filename, handleLintTs.name, mergedOptions);
} catch (error) {
logger.error("", error);
throw error;
Expand All @@ -33,9 +33,9 @@ export async function lintTs(options?: Partial<LintTsOptions>): Promise<LintResu
}

/** @internal */
export async function handlelintTs(options: LintTsOptions): Promise<LintResult[]> {
export async function handleLintTs(options: LintTsOptions): Promise<LintTsResult> {
const configFilePath = getConfigFilePath(options.config);
logger.debug(handlelintTs.name, `Config file path: ${configFilePath}`);
logger.debug(handleLintTs.name, `Config file path: ${configFilePath}`);

const configData = await readJsonFileAsync<Configuration.IConfigurationLoadResult>(configFilePath);

Expand All @@ -48,32 +48,33 @@ export async function handlelintTs(options: LintTsOptions): Promise<LintResult[]
formatter: options.formatter
});

const failures = (
await Promise.all(
glob(options.files).map(x => lintFile(x, configData, linter))
)
).filter(x => x.failureCount > 0);
await Promise.all(
glob(options.files).map(x => lintFile(x, configData, linter))
);

failures.forEach(x => logger.info(x.output));

if (failures.length && !options.continueOnError) {
process.exit(1);
const result = linter.getResult();
if (result.failureCount > 0) {
logger.info(result.output);
if (!options.continueOnError) {
process.exit(1);
}
}

return failures;
return {
failuresCount: result.failureCount,
fixesCount: result.fixes ? result.fixes.length : undefined
};
}

async function lintFile(filePath: string, configData: Configuration.IConfigurationLoadResult, linter: Linter): Promise<LintResult> {
async function lintFile(filePath: string, configData: Configuration.IConfigurationLoadResult, linter: Linter): Promise<void> {
logger.debug(lintFile.name, `filePath: ${filePath}`);
linter.lint(filePath, await readFileAsync(filePath), configData);

return linter.getResult();
}

/** @internal */
export const lintTsModule = buildCommandModule({
command: "lint-ts",
description: "Lint Typescript files",
description: "Lint TypeScript files",
handler: lintTs,
args: ARGS
});

0 comments on commit 981589b

Please sign in to comment.