Skip to content

Commit

Permalink
Merge branch 'master' of github.com:xcatliu/cqc into function-based-h…
Browse files Browse the repository at this point in the history
…igh-complexity-rate
  • Loading branch information
xcatliu committed Dec 5, 2017
2 parents 8407ab3 + 693a9fc commit 550a260
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cqc "src/**/*.js" "src/**/*.jsx"
Option | Type | Default | Description
------ | ---- | ------- | -----------
Files options |
`--ext` | string | `.js` | Specify file extensions
`--ext` | string | `.js` | Specify file extensions. `--ext` is only used when the arguments are directories. If you use glob patterns or file names, then `--ext` is ignored.
`--ignore-path` | path | | Specify path of ignore file
`--ignore-pattern` | pattern | | Pattern of files to ignore
`--filter-pattern` | pattern | | Output percentage of all files but only details that related to the filter pattern
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cqc",
"version": "0.5.0",
"version": "0.5.1",
"description": "Code Quality Checker - Check your code quality by running one command.",
"main": "src/CodeQualityChecker/index.js",
"bin": {
Expand Down
5 changes: 4 additions & 1 deletion src/ComplexityChecker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ class ComplexityChecker extends BaseChecker {
return 0;
}
getPercentage(count) {
let result = count / this.fileList.length * 100;
let result = 0;
if (this.fileList.length > 0) {
result = count / this.fileList.length * 100;
}
result = result.toFixed(2);
return result;
}
Expand Down
42 changes: 42 additions & 0 deletions test/integration/checkReportEmptyOutputs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint max-nested-callbacks:0 */

const sinon = require('sinon');

const CodeQualityChecker = require('../../');
const codeQualityChecker = new CodeQualityChecker();

describe('Report with empty outputs', () => {
beforeEach(function () {
this.sinon = sinon.sandbox.create();
});
afterEach(function () {
this.sinon.restore();
});

const cqcResult = codeQualityChecker.check([
'test/sample/not-exist-path.js',
], {
format: 'json'
});
it('Should match provided console.log result', function () {
this.sinon.spy(console, 'log');

cqcResult.report();

this.sinon.assert.calledWith(console.log, `{
"base": {
"numberOfFiles": 0
},
"sloc": {
"source": 0
},
"jscpd": {
"percentage": "0.00"
},
"complexity": {
"percentage": "0.00",
"max": 0
}
}`);
});
});

0 comments on commit 550a260

Please sign in to comment.