xcatliu / cqc

Code Quality Checker - Check your code quality by running one command.
323 stars 18 forks source link

Errored file stops execution of cqc completely. #16

Open nithinkashyapn opened 6 years ago

nithinkashyapn commented 6 years ago

I regularly keep getting the following error when running cqc

C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babel-eslint\lib\parse.js:81
    throw err;
    ^

SyntaxError: Line 282: yield is a reserved word in strict mode

  280 |  */
  281 | function* genFunc() {
> 282 |   ['a', 'b'].forEach(x => yield x); // SyntaxError
      |                           ^
  283 | }
  284 |
  285 | // Refactored
    at _class.raise (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:772:15)
    at _class.checkReservedWord (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:3804:12)
    at _class.parseIdentifierName (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:3781:12)
    at _class.parseIdentifier (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:3773:21)
    at _class.parseExprAtom (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:2984:25)
    at _class.parseExprAtom (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:5394:54)
    at _class.parseExprAtom (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:8029:52)
    at _class.parseExprSubscripts (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:2705:21)
    at _class.parseMaybeUnary (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:2684:21)
    at _class.parseExprOps (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:2596:21)
    at _class.parseMaybeConditional (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:2568:21)
    at _class.parseMaybeAssign (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:2526:21)
    at _class.parseMaybeAssign (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:7189:53)
    at _class.parseFunctionBody (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:3683:24)
    at _class.parseFunctionBody (C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:5407:47)
    at C:\Users\Nithin\AppData\Roaming\npm\node_modules\cqc\node_modules\babylon\lib\index.js:6493:58

Tried figuring it out, but couldn't wrap my head around.

Why is it so and what is the fix?

nithinkashyapn commented 6 years ago

Found it.

cqc stops executing when the source code it's checking has some errors; but it does not seem to show the file where the error occurred.

Can there be an enhancement feature where it'll still compile the remaining files when error occurs?

xcatliu commented 6 years ago

cqc use babel-eslint to parse the code, so it will abort the progress when the parse program get errors. However only complexity checker triggers the parse program. So it's possible to add a try catch for this then we can have other checker result even if complexity checker get errors

nithinkashyapn commented 6 years ago

Oh ya, we can do that. btw, cqc is a neat npm module.

A star beckons.

nithinkashyapn commented 6 years ago

Hey, One more thing. The cqc API with format as JSON is resulting in a non JSON output. Should i create a new issue or have i been wrong somewhere?

My config is like

{
            ext: '.js',
            ignorePath: '.gitignore',
            ignorePattern: 'src/vendor/**/*.js,src/third-party/**/*.js,node_modules/**/*.js',
            filterPattern: 'src/path/to/filterPattern',

            jscpdMinLines: 5,
            jspcdMinTokens: 70,

            disableBase: false,
            disableSloc: false,
            disableJscpd: false,
            disableComplexity: false,

            format: "JSON",
            verbose: false
}

Output is like

CheckerResult {
     base: { numberOfFiles: 6, fileList: [Array], filterFileList: [] },
     sloc:
      { total: 1257,
        source: 618,
        comment: 510,
        single: 180,
        block: 330,
        mixed: 36,
        empty: 165,
        todo: 0 },
     jscpd: { percentage: '67.22', report: [Object], map: [Map] },
     complexity:
      { percentage: '0.00',
        details: [],
        numberOfFunctions: 258,
        numberOfHighComplexityFunctions: 0,
        filterDetails: [] },
     [Symbol(baseOptions)]:
      { ext: '.js',
        jscpdMinLines: 5,
        jscpdMinTokens: 70,
        complexityMax: 10,
        ignorePath: '.gitignore',
        ignorePattern: 'src/vendor/**/*.js,src/third-party/**/*.js,node_modules/**/*.js',
        filterPattern: 'src/path/to/filterPattern',
        jspcdMinTokens: 70,
        disableBase: false,
        disableSloc: false,
        disableJscpd: false,
        disableComplexity: false,
        format: 'JSON',
        verbose: false } }

Work around i'm using

        cqc = JSON.stringify(cqcResult);
        cqc = cqc.replace("CheckerResult", "CheckerResult:");
        cqc = JSON.parse(cqc);
xcatliu commented 6 years ago

@nithinkashyapn I checked the source code and the test. The format option only accepts lowercase json, not JSON Please try to use json and tell me if there are any other issues.