Skip to content

Commit

Permalink
feat: change practice 'Update Dependencies' to 'Update Dependencies w…
Browse files Browse the repository at this point in the history
…ith Major Level'
  • Loading branch information
adelkahomolova committed Nov 18, 2019
1 parent 27ee181 commit 3daf397
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions src/practices/JavaScript/DependenciesVersionPractice.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { PracticeImpact, PracticeEvaluationResult, ProgrammingLanguage } from '../../model';
import { PracticeContext } from '../../contexts/practice/PracticeContext';
import { evaluateBySemverLevel, SemverVersion } from '../../detectors/utils';
import { PracticeEvaluationResult, PracticeImpact, ProgrammingLanguage } from '../../model';
import { DxPractice } from '../DxPracticeDecorator';
import { IPractice } from '../IPractice';
import { PracticeContext } from '../../contexts/practice/PracticeContext';
import _ from 'lodash';
import ncu from 'npm-check-updates';

@DxPractice({
id: 'LanguageIndependent.DependenciesVersion',
name: 'Update Dependencies',
impact: PracticeImpact.high,
id: 'LanguageIndependent.DependenciesVersionMajorLevel',
name: 'Update Dependencies with Major Level',
impact: PracticeImpact.small,
suggestion: 'Keep the dependencies updated to eliminate security concerns and compatibility issues. Use, for example, Renovate Bot.',
reportOnlyOnce: true,
url: 'https://renovatebot.com/',
Expand All @@ -21,26 +20,6 @@ export class DependenciesVersionPractice implements IPractice {
}

async evaluate(ctx: PracticeContext): Promise<PracticeEvaluationResult> {
if (ctx.fileInspector === undefined || ctx.packageInspector === undefined) {
return PracticeEvaluationResult.unknown;
}

const pkgs = ctx.packageInspector.packages;
const fakePkgJson: { dependencies: { [key: string]: string } } = { dependencies: {} };

pkgs &&
pkgs.forEach((p) => {
fakePkgJson.dependencies[p.name] = p.requestedVersion.value;
});

const result = await ncu.run({
packageData: JSON.stringify(fakePkgJson),
});

if (_.keys(result).length === 0) {
return PracticeEvaluationResult.practicing;
}

return PracticeEvaluationResult.notPracticing;
return evaluateBySemverLevel(ctx, SemverVersion.major);
}
}

0 comments on commit 3daf397

Please sign in to comment.