Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cqc

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cqc

Code Quality Checker - Check your code quality by running one command.

  • 0.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-36.84%
Maintainers
1
Weekly downloads
 
Created
Source

Code Quality Checker

Build Status npm package npm downloads Coveralls

Check your code quality by running one command.

Supported Languages

  • js, jsx, vue
  • css, less, scss, sass, styl

Quick Start

Install cqc:

npm install -g cqc

Run Code Quality Checker for all JavaScript files in src directory:

cqc src

Output:

Number of files:        12
Source lines of code:   696
Duplicate rate:         3.23%
High complexity rate:   0.00%

Usage

To run cqc, use the following format:

cqc [options] <file|dir|glob>*

For example:

cqc src/file1.js src/file2.js

or

cqc src lib

or

cqc src/**/*.js src/**/*.jsx

Please note that when passing a glob as a parameter, it will be expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node glob syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:

cqc "src/**/*.js" "src/**/*.jsx"

Options

OptionTypeDefaultDescription
Files options
--extstring.jsSpecify file extensions. --ext is only used when the arguments are directories. If you use glob patterns or file names, then --ext is ignored.
--ignore-pathpathSpecify path of ignore file
--ignore-patternpatternPattern of files to ignore
--filter-patternpatternOutput percentage of all files but only details that related to the filter pattern
Script options
--jscpd-min-linesnumber5Set the min size of duplication in code lines
--jscpd-min-tokensnumber70Set the min size of duplication in code tokens
--complexity-maxnumber10Set the allowed max complexity of a function
Disable options
--disable-baseDisable base checker
--disable-slocDisable sloc checker
--disable-jscpdDisable jscpd checker
--disable-complexityDisable complexity checker
Reporter options
-f, --formatstringSpecify an output format. Supported format: json
--verboseVerbose mode. A lot more information output
--threshold-jscpdnumberSet the jscpd threshold, process will exit if duplicate rate is more than threshold
--threshold-complexitynumberSet the complexity threshold, process will exit if complexity rate is more than threshold

Examples:

Set the file extensions
cqc src --ext ".js,.jsx"
Set the ignore file path
cqc src/**/*.js --ignore-path ".gitignore,.eslintignore"
Ignore vendors and third-party libraries
cqc src/**/*.js --ignore-pattern "src/vendor/**/*.js,src/third-party/**/*.js"
Output json format
cqc src/**/*.js --format json

Output:

{
    "base": {
        "numberOfFiles": 12
    },
    "sloc": {
        "source": 696
    },
    "jscpd": {
        "percentage": "3.23"
    },
    "complexity": {
        "percentage": "0.00"
    }
}
Verbose mode
cqc src/**/*.js --verbose

Output:

Number of files: 12
File list:
    - E:\github\xcatliu\cqc\src\BaseChecker\index.js
    - E:\github\xcatliu\cqc\src\CheckerResult\cqcReporter.js
    - E:\github\xcatliu\cqc\src\CheckerResult\index.js
    - E:\github\xcatliu\cqc\src\CheckerResult\logStdout.js
    - E:\github\xcatliu\cqc\src\CodeQualityChecker\index.js
    - E:\github\xcatliu\cqc\src\ComplexityChecker\eslintConfig.js
    - E:\github\xcatliu\cqc\src\ComplexityChecker\getParserFromFilepath.js
    - E:\github\xcatliu\cqc\src\ComplexityChecker\index.js
    - E:\github\xcatliu\cqc\src\JscpdChecker\getLanguageFromFilepath.js
    - E:\github\xcatliu\cqc\src\JscpdChecker\index.js
    - E:\github\xcatliu\cqc\src\JscpdChecker\jscpdReporter.js
    - E:\github\xcatliu\cqc\src\SlocChecker\index.js

Physical lines:             854
Source lines of code:       696
Comments:                   36
Single-line comments:       36
Block comments:             0
Mixed source and comments:  0
Empty lines:                122
TODO's:                     1

Duplicate rate:             3.23%
Files of duplicated code:   3
Count of duplicated code:   2
Lines of duplicated code:   28
Duplication details:
    - E:\github\xcatliu\cqc\src\CheckerResult\logStdout.js: 67-71
      E:\github\xcatliu\cqc\src\CheckerResult\logStdout.js: 73-77
    - E:\github\xcatliu\cqc\src\JscpdChecker\index.js: 42-64
      E:\github\xcatliu\cqc\src\JscpdChecker\jscpdReporter.js: 22-44

High complexity rate:                0.00%
Number of functions:                 58
Number of high complexity functions: 0
Set the jscpd threshold
cqc src --threshold-jscpd 3

Output:

Number of files:        12
Source lines of code:   696
Duplicate rate:         3.23%
High complexity rate:   0.00%

Oops, duplicate rate is MORE than threshold 3%, please check the details by adding --verbose option.

API

It's also able to use cqc as a node module:

const CodeQualityChecker = require('cqc');
const codeQualityChecker = new CodeQualityChecker();

// This will return a checkerResult object which include the check result
const cqcResult = codeQualityChecker.check([
    'src'
], {
    ext: '.js',
    ignorePath: '.gitignore,.eslintignore',
    ignorePattern: 'src/vendor/**/*.js,src/third-party/**/*.js',
    filterPattern: 'src/path/to/filterPattern',

    jscpdMinLines: 5,
    jspcdMinTokens: 70,
    complexityMax: 10,

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

    format: undefined,
    verbose: true,
    thresholdJscpd: 3,
    thresholdComplexity: 10
});

// Calling report function will console.log result like cli did
cqcResult.report({
    format: undefined,
    verbose: true,
    thresholdJscpd: 3,
    thresholdComplexity: 10
});

Concept Definition

ConceptDefinition
Number of filesThe number of input files
Source lines of codeThe lines of code except commants and blank lines
Lines of duplicated codeLines of code (more than 5 lines or more than 70 tokens) which is exactly the same between two files, or in different place of one file
Duplicate rateLines of duplicated code / Source lines of code
Complexityhttps://en.wikipedia.org/wiki/Cyclomatic_complexity
Number of functionsThe number of functions
Number of high complexity functionsThe number of functions which has complexity more than 10
High complexity rateNumber of high complexity functions / Number of functions

Keywords

FAQs

Package last updated on 05 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc