Skip to content

Commit

Permalink
fix: set default fail argument to high;
Browse files Browse the repository at this point in the history
fix: set defaultly notPracticingPracticesToFail to empty array so it is possible to call .length always
  • Loading branch information
adelkahomolova committed Oct 30, 2019
1 parent a93336e commit 7e27427
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cli from 'cli-ux';
import { ServiceError } from './lib/errors';
import updateNotifier from 'update-notifier';
import { ScanningStrategyDetectorUtils } from './detectors/utils/ScanningStrategyDetectorUtils';
import { PracticeImpact } from './model';
// import { ScanningStrategyDetectorUtils } from './utils/ScanningStrategyDetectorUtils';

class DXScannerCommand extends Command {
Expand All @@ -30,7 +31,7 @@ class DXScannerCommand extends Command {
const { args, flags } = this.parse(DXScannerCommand);
let authorization = flags.authorization ? flags.authorization : undefined;
const json = flags.json ? flags.json : undefined;
const fail = flags.fail ? flags.fail : undefined;
const fail = flags.fail ? flags.fail : PracticeImpact.high;

const notifier = updateNotifier({ pkg: this.config.pjson });

Expand All @@ -45,7 +46,7 @@ class DXScannerCommand extends Command {
const scanPath = args.path || process.cwd();
cli.action.start(`Scanning URI: ${scanPath}`);

const container = createRootContainer({ uri: scanPath, auth: authorization, json: json, fail: fail });
const container = createRootContainer({ uri: scanPath, auth: authorization, json: json, fail: <PracticeImpact>fail });
const scanner = container.get(Scanner);

try {
Expand Down
11 changes: 9 additions & 2 deletions src/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import { IFileInspector } from './inspectors/IFileInspector';
import { IPackageInspector } from './inspectors/IPackageInspector';
import { IssueTrackingInspector } from './inspectors/IssueTrackingInspector';
import { JavaScriptPackageInspector } from './inspectors/package/JavaScriptPackageInspector';
import { ProgrammingLanguage, ProjectComponent, ProjectComponentFramework, ProjectComponentPlatform, ProjectComponentType } from './model';
import {
ProgrammingLanguage,
ProjectComponent,
ProjectComponentFramework,
ProjectComponentPlatform,
ProjectComponentType,
PracticeImpact,
} from './model';
import { practices } from './practices';
import { IPracticeWithMetadata } from './practices/DxPracticeDecorator';
import { CLIReporter } from './reporters/CLIReporter';
Expand Down Expand Up @@ -127,5 +134,5 @@ export interface ArgumentsProvider {
uri: string;
auth?: string;
json?: boolean;
fail?: PracticeImpact | "all";
fail?: PracticeImpact | 'all';
}
14 changes: 9 additions & 5 deletions src/scanner/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,22 @@ export class Scanner {
isOn: p.isOn,
};
});
console.log(reportArguments, 'reportArg');

const reportString = this.reporter.report(reportArguments);

typeof reportString === 'string'
? console.log(reportString)
: console.log(util.inspect(reportString, { showHidden: false, depth: null }));

const notPracticingPracticesToFail = reportArguments.filter(
(practice) =>
practice.evaluation === PracticeEvaluationResult.notPracticing &&
(practice.impact === this.argumentsProvider.fail || this.argumentsProvider.fail === 'all'),
);
let notPracticingPracticesToFail = [];
if (this.argumentsProvider.fail !== 'off') {
notPracticingPracticesToFail = reportArguments.filter(
(practice) =>
practice.evaluation === PracticeEvaluationResult.notPracticing &&
(practice.impact === this.argumentsProvider.fail || this.argumentsProvider.fail === 'all'),
);
}

if (notPracticingPracticesToFail.length > 0) {
process.exit(1);
Expand Down

0 comments on commit 7e27427

Please sign in to comment.