Skip to content

Commit

Permalink
Merge pull request #381 from DXHeroes/fix/dont-run-remote-fix
Browse files Browse the repository at this point in the history
Don't run fix command for remote repos
  • Loading branch information
vlasy authored Sep 3, 2020
2 parents d7360d9 + 1baa2dc commit 91e15c3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
11 changes: 8 additions & 3 deletions src/contexts/scanner/scannerContextBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const createScanningContainer = (scanningStrategy: ScanningStrategy, discoveryCo
bindLanguageContext(container);
bindFileAccess(scanningStrategy, container);

bindReporters(container, args, scanningStrategy.accessType);
bindReporters(container, args, scanningStrategy);
bindCollectors(container, args, scanningStrategy.accessType);
container.bind(ScannerContext).toSelf();
return container;
Expand Down Expand Up @@ -71,12 +71,17 @@ const bindCollectors = (container: Container, args: ArgumentsProvider, accessTyp
}
};

const bindReporters = (container: Container, args: ArgumentsProvider, accessType: AccessType | undefined) => {
const bindReporters = (
container: Container,
args: ArgumentsProvider,
{ accessType, localPath }: Pick<ScanningStrategy, 'accessType' | 'localPath'>,
) => {
if (args.json) {
container.bind<IReporter>(Types.IReporter).to(JSONReporter);
} else if (args.html) {
container.bind<IReporter>(Types.IReporter).to(HTMLReporter);
} else if (args.fix) {
} else if (args.fix && !localPath) {
// fix only local runs
container.bind<IReporter>(Types.IReporter).to(FixReporter);
} else {
container.bind<IReporter>(Types.IReporter).to(CLIReporter);
Expand Down
10 changes: 9 additions & 1 deletion src/reporters/CLIReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ export class CLIReporter implements IReporter {
p.practice.fix && p.evaluation === PracticeEvaluationResult.notPracticing;
const fixablePractices = cwp.practicesAndComponents.filter(fixablePractice);
if (fixablePractices.length) {
lines.push(bold(yellow(`These practices might be automatically fixed (re-run the command with ${italic('--fix')} option):`)));
lines.push(
bold(
yellow(
`These practices might be automatically fixed (re-run the command with ${italic('--fix')} option and on a ${bold(
'local',
)} folder):`,
),
),
);
lines.push('');

for (const p of fixablePractices) {
Expand Down
19 changes: 10 additions & 9 deletions src/scanner/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class Scanner {
isOnline: scanStrategy.isOnline,
};
}
const isLocal = !scanStrategy.localPath;
scanStrategy = await this.preprocessData(scanStrategy);
this.d(`Scan strategy (after preprocessing): ${inspect(scanStrategy)}`);
const scannerContext = discoveryContext.getScanningContext(scanStrategy);
Expand All @@ -89,8 +90,12 @@ export class Scanner {
this.d(`Practices (${practicesWithContext.length}):`, inspect(practicesWithContext));
let practicesAfterFix: PracticeWithContext[] | undefined;
if (this.argumentsProvider.fix) {
await this.fix(practicesWithContext);
practicesAfterFix = await this.detectPractices(projectComponents);
if (isLocal) {
cli.warn('`fix` command only works for local folder, not for online repositories');
} else {
await this.fix(practicesWithContext);
practicesAfterFix = await this.detectPractices(projectComponents);
}
}
await this.report(scannerContext.reporters, practicesWithContext, practicesAfterFix);
this.d(
Expand Down Expand Up @@ -272,13 +277,9 @@ export class Scanner {
const relevantPractices: PracticeWithContextForReporter[] = practicesWithContext.map(pwcForReporter);

this.d(`Reporters length: ${reporters.length}`);
if (this.argumentsProvider.fix) {
const relevantPracticesAfterFix: PracticeWithContextForReporter[] = practicesWithContextAfterFix!.map(pwcForReporter);
await Promise.all(
reporters.map(async (r) => {
this.argumentsProvider.fix ? await r.report(relevantPractices, relevantPracticesAfterFix) : await r.report(relevantPractices);
}),
);
if (practicesWithContextAfterFix) {
const relevantPracticesAfterFix: PracticeWithContextForReporter[] = practicesWithContextAfterFix.map(pwcForReporter);
await Promise.all(reporters.map((r) => r.report(relevantPractices, relevantPracticesAfterFix)));
} else {
await Promise.all(reporters.map(async (r) => await r.report(relevantPractices)));
}
Expand Down

0 comments on commit 91e15c3

Please sign in to comment.