diff --git a/src/practices/JavaScript/ESLintWithoutErrorsPractice.ts b/src/practices/JavaScript/ESLintWithoutErrorsPractice.ts index 10bdada35..3e98fbcb6 100644 --- a/src/practices/JavaScript/ESLintWithoutErrorsPractice.ts +++ b/src/practices/JavaScript/ESLintWithoutErrorsPractice.ts @@ -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', @@ -24,13 +25,12 @@ export class ESLintWithoutErrorsPractice implements IPractice { ); } - async evaluate(ctx: PracticeContext): Promise { + 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, @@ -78,7 +78,14 @@ 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 { + const report = await this.runEslint(ctx); + if (!report) { + return PracticeEvaluationResult.unknown; + } if (report['errorCount'] === 0) { return PracticeEvaluationResult.practicing; @@ -86,4 +93,8 @@ export class ESLintWithoutErrorsPractice implements IPractice { return PracticeEvaluationResult.notPracticing; } + + async fix(ctx: FixerContext) { + await this.runEslint(ctx, { fix: true }); + } }