Code Monkey home page Code Monkey logo

janus's Introduction

Janus

Build Status

An analyzer of code cyclomatic complexity, which only works with Python 3.

A list of supported languages:

  • Python
  • Golang

Installation

pip3 install git+https://github.com/usharerose/janus.git

Usage

Command Line

Usage: janus [OPTIONS] [PATHS]...

  Args:     paths (tuple): the paths of files or directories

Options:
  --help  Show this message and exit.

You can input a file as target

janus foo.py

You can input directory, and analyze the files under it recursively

janus directory/

You can also input multiple paths

janus directory/ foo.py

Python Module

>>> from janus.app import Janus
>>> app = Janus()
>>> result = app.process(('/foo.py',))
>>> print(result)
{"data": [{"file": "/foo.py", "cyclomatic_complexity": 27}]}

Theory

According to the definition of cyclomatic complexity in Wikipedia

Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. It was developed by Thomas J. McCabe, Sr. in 1976.

The library is based on the following formula

V(G) = P + 1

* P is the number of decision points in the program

Development

Support New Language

  1. Add the language-specific tree-sitter as submodule
[submodule "vendor/tree-sitter-go"]
	path = vendor/tree-sitter-go
	url = https://github.com/tree-sitter/tree-sitter-go
  1. Execute the script to store the multiple tree-sitter into the library for local dev
python build_tree_sitter_lang_lib.py
  1. Register the mapping of language's file extension to name in the file janus/settings.py
EXTENSION_LANG_NAME_MAPPING = {
    '.py': 'python',
    '.go': 'go',
    # please add it here
}
  1. Add the language-specific analyzer into the file janus/analyzer.py inherited from BaseComplexityAnalyzer. Commonly you only need to overwrite the following configurations
class FooAnalyzer(BaseComplexityAnalyzer):

    EXTENSION = '.foo'

    # refer to the value in https://github.com/tree-sitter/tree-sitter-foo/blob/master/src/grammar.json
    DECISION_TYPES = [
        'if', ...
    ]
  1. Add test cases under the directory tests/

janus's People

Contributors

usharerose avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.