• Stars
    star
    323
  • Rank 130,051 (Top 3 %)
  • Language
    JavaScript
  • Created about 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

typescript-tutorial

TypeScript 入门教程
TypeScript
10,357
star
2

pagic

A static site generator powered by Deno + React
JavaScript
1,637
star
3

react-ie8

Make your React app work in IE8
999
star
4

chatgpt-next

微信风格的 ChatGPT,使用 Next.js 构建,私有化部署的最佳选择!
TypeScript
761
star
5

jekyllcn

Jekyll 的中文翻译网站
Ruby
470
star
6

leetcode

My LeetCode Solutions
JavaScript
315
star
7

mazimd

码字 md • 干净精致的 Markdown 编辑器
JavaScript
120
star
8

123

The personal front page
CSS
72
star
9

blog

流浪小猫的博客
TypeScript
72
star
10

awesome-json2json

An awesome json to json data mapper
JavaScript
67
star
11

V2HOT

V2HOT is an iOS App made by @xcatliu, powered by React Native.
JavaScript
55
star
12

xcatliu

About me
TypeScript
54
star
13

react-select-pinyin

React 选择控件(支持拼音搜索)
JavaScript
31
star
14

buy-me-a-coffee

☕ Buy me a coffee
29
star
15

awesome-aigc

29
star
16

hexo-theme-wiki-i18n

A hexo theme for i18n wiki site
HTML
28
star
17

xzoo

可爱的动物头像,为你设计。 Lovely animal avatars, designed for you.
26
star
18

js-index

🔠 The index of everything about JavaScript
HTML
24
star
19

simplemde-theme-base

The base theme for SimpleMDE, you can easily build your custom theme based on this.
CSS
22
star
20

full-color-screen

Display a solid color across the entire display.
22
star
21

hexo-filter-date-from-git

Read git log and overwrite the front-matter properties `date` and `updated` for each posts
JavaScript
13
star
22

goodbye-ie8

Goodbye IE8
HTML
13
star
23

simplemde-theme-dark

The dark theme of SimpleMDE
CSS
12
star
24

pagic_template_docs

Use this template to create a Pagic site with the docs theme
TypeScript
12
star
25

etype

Extra types for TypeScript
JavaScript
11
star
26

grubbs

Online Grubbs' test for outliers
JavaScript
11
star
27

add-eslint-comment

Add ESLint comment per file according to the ESLint result.
JavaScript
9
star
28

mangastream

A wordpress theme for mangastream
PHP
7
star
29

spells

360 Spells of 360 Colors
JavaScript
7
star
30

react-errors

Show errors on the top-right
JavaScript
6
star
31

the-war-of-colors

JavaScript
6
star
32

ts-react

TypeScript React Boilerplate
TypeScript
6
star
33

hexo-generator-index-i18n

I18n index generator plugin for Hexo
JavaScript
5
star
34

insert-tag

Insert tag to the specific position of a html string
TypeScript
5
star
35

Thinking-in-React

An implement for Thinking in React
JavaScript
5
star
36

the-secret-of-maintaining-100000-lines-of-javascript-code

维护十万行 JavaScript 代码的秘诀
5
star
37

rose

Give your love a rose
HTML
4
star
38

light-stick

拍一个创意炫彩照,俘获妹子芳心
CSS
4
star
39

mazimd-api

The api server for mazimd
JavaScript
3
star
40

geocn

中国最完整最精确的行政区划数据与应用平台
2
star
41

smart-serialize

Serialize any object, stringify, print to console, and write to clipboard
JavaScript
2
star
42

hexo-filter-author-from-git

Read git log and add the properties `author` and `contributors` for each posts
JavaScript
2
star
43

typescript-travis-ci

JavaScript
2
star
44

fe-dotfiles

dotfiles for my front-end projects
JavaScript
2
star
45

codeeval

My codeeval solutions
JavaScript
2
star
46

removethem

RemoveThem 一款有趣的Web游戏
JavaScript
1
star
47

github2p

Generate any github repo to web pages in one second.
1
star
48

learning-react

The way I learning react.
JavaScript
1
star
49

rematch-typescript

1
star
50

react-gmap

Google Maps component for React
JavaScript
1
star
51

xcombo

A NodeJS combo server
1
star
52

xcatblog

Xcatblog is a blog system, isomorphic application, the React way.
JavaScript
1
star
53

C

Learning C
1
star
54

react-boilerplate

1
star
55

v2hot.trash

JavaScript
1
star
56

xduck

JavaScript
1
star
57

timeout

1
star
58

require-uncache

Remove all cached files associated with the module.
JavaScript
1
star
59

LICENSES

1
star
60

react-input-file

An `<input type="file"/>` implement which support dragging files from desktop
1
star
61

hexo-theme-xcatliu

CSS
1
star
62

xImage

A html5 canvas image editor.
1
star
63

Todo-Hodgepodge

Todo Apps collections wrote with different program languages and different database systems.
1
star
64

react-github-buttons

1
star
65

xtree

A skill tree system.
JavaScript
1
star
66

react-select2

1
star
67

react-webpack-redux-react-router

1
star
68

fepost

JavaScript
1
star
69

6rainbow

TypeScript
1
star