From 81e00cda9e484034aba1e7b53a9e64abfd9513fb Mon Sep 17 00:00:00 2001 From: Adela Homolova Date: Thu, 3 Oct 2019 14:42:59 +0200 Subject: [PATCH] fix: rename EslintConfig to PracticeConfig; return always PracticeConfig in getOverridenPractice() --- package.json | 2 +- src/contexts/ConfigProvider.ts | 11 ++++++++--- src/contexts/IConfigProvider.ts | 6 +++--- src/contexts/practice/PracticeContext.ts | 4 ++-- src/scanner/Scanner.ts | 7 +------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index acfcd14b5..4a5956c9e 100644 --- a/package.json +++ b/package.json @@ -66,9 +66,9 @@ "@types/rimraf": "^2.0.2", "@types/semver": "^6.0.1", "@types/toposort": "^2.0.3", + "@types/update-notifier": "^2.5.0", "@typescript-eslint/eslint-plugin": "^2.2.0", "@typescript-eslint/parser": "^2.2.0", - "@types/update-notifier": "^2.5.0", "codecov": "^3.5.0", "eslint-config-prettier": "^6.3.0", "eslint-plugin-prettier": "^3.1.0", diff --git a/src/contexts/ConfigProvider.ts b/src/contexts/ConfigProvider.ts index 2747e88df..c078bb463 100644 --- a/src/contexts/ConfigProvider.ts +++ b/src/contexts/ConfigProvider.ts @@ -3,7 +3,7 @@ import yaml from 'js-yaml'; import _ from 'lodash'; import { IFileInspector } from '../inspectors/IFileInspector'; import { Types } from '../types'; -import { IConfigProvider, Config, EslintConfig } from './IConfigProvider'; +import { IConfigProvider, Config, PracticeConfig } from './IConfigProvider'; import { PracticeImpact } from '../model'; @injectable() @@ -39,11 +39,16 @@ export class ConfigProvider implements IConfigProvider { this.config = parsedContent; } - getOverridenPractice(practiceId: string): PracticeImpact | EslintConfig { + getOverridenPractice(practiceId: string): PracticeConfig { const practiceConfig = _.get(this.config, ['practices', practiceId]); if (typeof practiceConfig !== 'string' && practiceConfig !== undefined) { return practiceConfig.impact; } - return practiceConfig; + + const impactInConfig = { + impact: practiceConfig, + }; + + return impactInConfig; } } diff --git a/src/contexts/IConfigProvider.ts b/src/contexts/IConfigProvider.ts index 5cc99d0ec..6343aef35 100644 --- a/src/contexts/IConfigProvider.ts +++ b/src/contexts/IConfigProvider.ts @@ -2,19 +2,19 @@ import { PracticeImpact } from '../model'; export interface IConfigProvider { init(): Promise; - getOverridenPractice(practiceId: string): PracticeImpact | EslintConfig; + getOverridenPractice(practiceId: string): PracticeConfig; } export interface Config { practices?: { - [key in Practices]?: PracticeImpact | EslintConfig; + [key in Practices]?: PracticeImpact | PracticeConfig; }; tokens?: { [key in Service]: string; }; } -export interface EslintConfig { +export interface PracticeConfig { eslintIgnore?: string[]; useEslintrc?: boolean; impact?: string; diff --git a/src/contexts/practice/PracticeContext.ts b/src/contexts/practice/PracticeContext.ts index 5134c07d7..84b7c8381 100644 --- a/src/contexts/practice/PracticeContext.ts +++ b/src/contexts/practice/PracticeContext.ts @@ -4,7 +4,7 @@ import { IGitInspector } from '../../inspectors/IGitInspector'; import { IIssueTrackingInspector } from '../../inspectors/IIssueTrackingInspector'; import { IPackageInspector } from '../../inspectors/IPackageInspector'; import { PracticeImpact, ProjectComponent } from '../../model'; -import { EslintConfig } from '../IConfigProvider'; +import { PracticeConfig } from '../IConfigProvider'; export interface PracticeContext { projectComponent: ProjectComponent; @@ -13,5 +13,5 @@ export interface PracticeContext { issueTrackingInspector: IIssueTrackingInspector | undefined; collaborationInspector: ICollaborationInspector | undefined; fileInspector: IFileInspector | undefined; - config?: EslintConfig | PracticeImpact; + config?: PracticeConfig | PracticeImpact; } diff --git a/src/scanner/Scanner.ts b/src/scanner/Scanner.ts index 859c4bde7..40daa6a39 100644 --- a/src/scanner/Scanner.ts +++ b/src/scanner/Scanner.ts @@ -178,12 +178,7 @@ export class Scanner { const reportString = this.reporter.report( relevantPractices.map((p) => { const config = p.componentContext.configProvider.getOverridenPractice(p.practice.getMetadata().id); - - if (typeof config === 'string') { - impact = config; - } else if (config && 'impact' in config) { - impact = config.impact; - } + impact = config.impact; return { practice: {