Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加输出json到指定文件 #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

Check your code quality by running one command.

publish npmjs

npm publish --access=public


## Supported Languages

- js, jsx, vue
Expand Down Expand Up @@ -87,6 +92,7 @@ Reporter options |
`--verbose` | | | Verbose mode. A lot more information output
`--threshold-jscpd` | number | | Set the jscpd threshold, process will exit if duplicate rate is more than threshold
`--threshold-complexity` | number | | Set the complexity threshold, process will exit if complexity rate is more than threshold
`--json-path` | string | | output json file,unite ` -f json` format.

Examples:

Expand Down
5 changes: 4 additions & 1 deletion bin/cqc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ program
.option('--verbose', 'Verbose mode. A lot more information output')
.option('--threshold-jscpd <number>', 'Set the jscpd threshold')
.option('--threshold-complexity <number>', 'Set the complexity threshold')
// Output file path
.option('--json-path <string>', 'output json file')
.parse(process.argv);

const patterns = program.args;
Expand All @@ -48,7 +50,8 @@ const checkOptions = _.pick(program, [
'format',
'verbose',
'thresholdJscpd',
'thresholdComplexity'
'thresholdComplexity',
'jsonPath'
]);

const codeQualityChecker = new CodeQualityChecker();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cqc",
"version": "0.5.1",
"name": "@caiwenshu/cqc",
"version": "0.5.3",
"description": "Code Quality Checker - Check your code quality by running one command.",
"main": "src/CodeQualityChecker/index.js",
"bin": {
Expand Down
8 changes: 7 additions & 1 deletion src/CheckerResult/cqcReporter.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
const _ = require('lodash');
const logStdout = require('./logStdout');
const fs = require('fs');

function cqcReporter(resultObject, options = {}) {
const {
format,
thresholdJscpd,
thresholdComplexity
thresholdComplexity,
jsonPath,
} = options;

// Add threshold to JSON, add filter details if necessary
const result = processResult(resultObject, options);

if (format === 'json') {
fs.writeFile(jsonPath, JSON.stringify(result, null, 4), 'utf-8', (err) => {
if (err) throw err;
console.log('save file success');
});
console.log(JSON.stringify(result, null, 4));
} else {
logStdout(result, options);
Expand Down