Skip to content

Commit

Permalink
feat: implement fix for EsLintWithoutErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
vlasy committed Jan 24, 2020
1 parent 7340d8e commit 6b0d5c8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/practices/JavaScript/ESLintWithoutErrorsPractice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PracticeEvaluationResult, PracticeImpact, ProgrammingLanguage } from '.
import { DxPractice } from '../DxPracticeDecorator';
import { IPractice } from '../IPractice';
import * as nodePath from 'path';
import { FixerContext } from '../../contexts/fixer/FixerContext';

@DxPractice({
id: 'JavaScript.ESLintWithoutErrorsPractice',
Expand All @@ -24,13 +25,12 @@ export class ESLintWithoutErrorsPractice implements IPractice {
);
}

async evaluate(ctx: PracticeContext): Promise<PracticeEvaluationResult> {
private async runEslint(ctx: PracticeContext, { fix } = { fix: false }) {
if (!ctx.fileInspector) {
return PracticeEvaluationResult.unknown;
return;
}

let options: CLIEngine.Options = {
fix: false, // Use auto-fixer.
fix, // Use auto-fixer.
useEslintrc: false, // Set to false so the project doesn't take the eslint config from home folder.
rules: {
semi: 2,
Expand Down Expand Up @@ -78,12 +78,23 @@ export class ESLintWithoutErrorsPractice implements IPractice {
}

const cli = new CLIEngine(options);
const report = cli.executeOnFiles([ctx.projectComponent.path]);
return cli.executeOnFiles([ctx.projectComponent.path]);
}

async evaluate(ctx: PracticeContext): Promise<PracticeEvaluationResult> {
const report = await this.runEslint(ctx);
if (!report) {
return PracticeEvaluationResult.unknown;
}

if (report['errorCount'] === 0) {
return PracticeEvaluationResult.practicing;
}

return PracticeEvaluationResult.notPracticing;
}

async fix(ctx: FixerContext) {
await this.runEslint(ctx, { fix: true });
}
}

0 comments on commit 6b0d5c8

Please sign in to comment.