From f6f16ebcf68c55651f17a894a48dd628a45e9f05 Mon Sep 17 00:00:00 2001 From: yisraelx Date: Mon, 3 Apr 2017 21:26:57 +0300 Subject: [PATCH] fix(TslintPreprocessor): update to change of tslint 5.x line 64 - replace LintResult.failureCount with result.failures.length line 81 - set in 'default' mode to 'tslint:recommended' line 86 - use Configuration.parseConfigFile to parse object config (Convert to Map) --- src/tslint.preprocessor.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/tslint.preprocessor.ts b/src/tslint.preprocessor.ts index 3671dc6..67e4e44 100644 --- a/src/tslint.preprocessor.ts +++ b/src/tslint.preprocessor.ts @@ -1,7 +1,17 @@ -import { Linter, LintResult, Configuration } from 'tslint'; +import { Linter, LintResult, Configuration, FormatterFunction } from 'tslint'; import { Logger, Level } from 'log4js'; -export type TFormatter = 'prose' | 'json' | 'stylish' | 'verbose' | 'pmd' | 'msbuild' | 'checkstyle' | 'vso' | 'fileslist' | Function; +export type TFormatter = + 'prose' + | 'json' + | 'stylish' + | 'verbose' + | 'pmd' + | 'msbuild' + | 'checkstyle' + | 'vso' + | 'fileslist' + | FormatterFunction; export interface ITslintPreprocessorConfig { /** @@ -23,7 +33,7 @@ export interface ITslintPreprocessorConfig { stopOnFailure?: boolean; } -export function TslintPreprocessorFactory(loggerFactory: {create: (name: string, level?: string | Level) => Logger}, config: ITslintPreprocessorConfig = {} as any) { +export function TslintPreprocessorFactory(loggerFactory: { create: (name: string, level?: string | Level) => Logger }, config: ITslintPreprocessorConfig = {} as any) { let logger: Logger = loggerFactory.create('preprocessor.tslint'); return new TslintPreprocessor(logger, config).preprocessor; } @@ -51,7 +61,7 @@ export class TslintPreprocessor extends Linter { let result: LintResult = this.getResultAndClean(); let error = null; - if (result.failureCount) { + if (result.failures.length) { this._logger.error(result.output); if (stopOnFailure) error = result.output; } @@ -66,14 +76,18 @@ export class TslintPreprocessor extends Linter { configuration = Linter.findConfigurationPath(null, filePath); } - this._logger.debug(`Using configuration: ${configuration}`); + this._logger.info(`Using Configuration: ${typeof configuration === 'string' ? configuration : 'karma-tslint config object'}`); - if (configuration === 'default') configuration = null; + if (configuration === 'default') configuration = 'tslint:recommended'; - if (typeof configuration === 'string' || configuration === null) { + if (typeof configuration === 'string') { configuration = Configuration.loadConfigurationFromPath(configuration as any); + } else if (typeof configuration === 'object') { + configuration = Configuration.parseConfigFile(configuration); } + this._logger.debug(`Configuration Object:\n${JSON.stringify(configuration)}`); + return configuration; }