Skip to content

Commit

Permalink
fix(practices): unify impact and defaultImpact to impact and override…
Browse files Browse the repository at this point in the history
…nImpact
  • Loading branch information
prokopsimek committed Nov 28, 2019
1 parent 40e3fe2 commit 55ae3f8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export interface DeprecatedProjectComponent {
}

export interface PracticeMetadata {
defaultImpact?: PracticeImpact;
id: string;
name: string;
suggestion: string;
Expand Down
10 changes: 5 additions & 5 deletions src/reporters/CLIReporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ describe('CLIReporter', () => {
practicingHighImpactPracticeWithCtx,
notPracticingHighImpactPracticeWithCtx,
practiceWithContextFactory({
impact: PracticeImpact.medium,
overridenImpact: PracticeImpact.medium,
evaluation: PracticeEvaluationResult.notPracticing,
}),
practiceWithContextFactory({
impact: PracticeImpact.small,
overridenImpact: PracticeImpact.small,
evaluation: PracticeEvaluationResult.notPracticing,
}),
practiceWithContextFactory({
impact: PracticeImpact.hint,
overridenImpact: PracticeImpact.hint,
evaluation: PracticeEvaluationResult.notPracticing,
}),
practiceWithContextFactory({
impact: PracticeImpact.off,
overridenImpact: PracticeImpact.off,
evaluation: PracticeEvaluationResult.notPracticing,
isOn: false,
}),
practiceWithContextFactory({ impact: PracticeImpact.high, evaluation: PracticeEvaluationResult.unknown }),
practiceWithContextFactory({ overridenImpact: PracticeImpact.high, evaluation: PracticeEvaluationResult.unknown }),
]);

expect(result).toContain('Improvements with highest impact');
Expand Down
12 changes: 7 additions & 5 deletions src/reporters/CLIReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class CLIReporter implements IReporter {
const lines: string[] = [];

const practices = practicesAndComponents.filter(
(p) => p.impact === impact && p.isOn === true && p.evaluation === PracticeEvaluationResult.notPracticing,
(p) => p.overridenImpact === impact && p.isOn === true && p.evaluation === PracticeEvaluationResult.notPracticing,
);

if (practices.length === 0) return undefined;
Expand All @@ -108,8 +108,8 @@ export class CLIReporter implements IReporter {
for (const practiceWithContext of practices) {
lines.push(this.linesForPractice(practiceWithContext.practice, color));

if (practiceWithContext.practice.defaultImpact !== practiceWithContext.practice.impact) {
lines.push(bold(this.changedImpact(practiceWithContext.practice, (color = grey))));
if (practiceWithContext.practice.impact !== practiceWithContext.overridenImpact) {
lines.push(bold(this.changedImpact(practiceWithContext, (color = grey))));
}
}

Expand All @@ -127,11 +127,13 @@ export class CLIReporter implements IReporter {
return practiceLineTexts.join(' ');
}

private changedImpact(practice: PracticeMetadata, color: Color) {
private changedImpact(practiceWithContext: PracticeWithContextForReporter, color: Color) {
const practiceLineTexts = [
reset(
color(
`You changed impact of ${bold(practice.name)} from ${underline(<string>practice.defaultImpact)} to ${underline(practice.impact)}`,
` You changed impact of ${bold(practiceWithContext.practice.name)} from ${underline(
practiceWithContext.practice.impact,
)} to ${underline(practiceWithContext.overridenImpact)}.`,
),
),
];
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/IReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface ComponentReport extends ProjectComponent {
export interface PracticeWithContextForReporter {
component: ProjectComponent;
practice: PracticeMetadata;
impact: PracticeImpact;
overridenImpact: PracticeImpact;
evaluation: PracticeEvaluationResult;
isOn: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/ReporterUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ReporterUtils', () => {
});

it('one practicing practice and one skipped practicing', () => {
notPracticingHighImpactPracticeWithCtx.impact = PracticeImpact.off;
notPracticingHighImpactPracticeWithCtx.overridenImpact = PracticeImpact.off;
notPracticingHighImpactPracticeWithCtx.isOn = false;

const result = ReporterUtils.computeDXScore([practicingHighImpactPracticeWithCtx, notPracticingHighImpactPracticeWithCtx]);
Expand Down
2 changes: 1 addition & 1 deletion src/scanner/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class Scanner {
component: p.componentContext.projectComponent,
practice: p.practice.getMetadata(),
evaluation: p.evaluation,
impact: <PracticeImpact>(overridenImpact ? overridenImpact : p.practice.getMetadata().impact),
overridenImpact: <PracticeImpact>(overridenImpact ? overridenImpact : p.practice.getMetadata().impact),
isOn: p.isOn,
};
});
Expand Down
6 changes: 3 additions & 3 deletions src/scanner/ScannerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export class ScannerUtils {
argumentsProvider: ArgumentsProvider,
) => {
return relevantPractices.filter(
(practice) =>
practice.evaluation === PracticeEvaluationResult.notPracticing &&
(_.includes(ScannerUtils.getImpactFailureLevels(argumentsProvider.fail), practice.impact) || argumentsProvider.fail === 'all'),
(pctx) =>
pctx.evaluation === PracticeEvaluationResult.notPracticing &&
(_.includes(ScannerUtils.getImpactFailureLevels(argumentsProvider.fail), pctx.overridenImpact) || argumentsProvider.fail === 'all'),
);
};
}
2 changes: 1 addition & 1 deletion test/factories/PracticeWithContextFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const practiceWithContextFactory = (
impact: PracticeImpact.high,
url: '.',
},
impact: PracticeImpact.high,
overridenImpact: PracticeImpact.high,
evaluation: PracticeEvaluationResult.practicing,
isOn: true,
},
Expand Down

0 comments on commit 55ae3f8

Please sign in to comment.