Skip to content

Commit

Permalink
fix(TslintPreprocessor): update to change of tslint 5.x
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
yisraelx committed Apr 3, 2017
1 parent 06757b3 commit f6f16eb
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/tslint.preprocessor.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit f6f16eb

Please sign in to comment.