npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cqc

v0.6.0

Published

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

Downloads

76

Readme

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

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:

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

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