Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Check your code quality by running one command.
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%
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"
Option | Type | Default | Description |
---|---|---|---|
Files options | |||
--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 | |
Script options | |||
--jscpd-min-lines | number | 5 | Set the min size of duplication in code lines |
--jscpd-min-tokens | number | 70 | Set the min size of duplication in code tokens |
--complexity-max | number | 10 | Set the allowed max complexity of a function |
Disable options | |||
--disable-base | Disable base checker | ||
--disable-sloc | Disable sloc checker | ||
--disable-jscpd | Disable jscpd checker | ||
--disable-complexity | Disable complexity checker | ||
Reporter options | |||
-f , --format | string | Specify an output format. Supported format: json | |
--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 |
Examples:
cqc src --ext ".js,.jsx"
cqc src/**/*.js --ignore-path ".gitignore,.eslintignore"
cqc src/**/*.js --ignore-pattern "src/vendor/**/*.js,src/third-party/**/*.js"
cqc src/**/*.js --format json
Output:
{
"base": {
"numberOfFiles": 12
},
"sloc": {
"source": 696
},
"jscpd": {
"percentage": "3.23"
},
"complexity": {
"percentage": "0.00"
}
}
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
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.
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 |
---|---|
Number of files | The number of input files |
Source lines of code | The lines of code except commants and blank lines |
Lines of duplicated code | Lines 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 rate | Lines of duplicated code / Source lines of code |
Complexity | https://en.wikipedia.org/wiki/Cyclomatic_complexity |
Number of functions | The number of functions |
Number of high complexity functions | The number of functions which has complexity more than 10 |
High complexity rate | Number of high complexity functions / Number of functions |
FAQs
Code Quality Checker - Check your code quality by running one command.
The npm package cqc receives a total of 11 weekly downloads. As such, cqc popularity was classified as not popular.
We found that cqc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.