Library to analyze and collect metrics on source code
Перейти к файлу
Luni-4 fb8d4818ed
Use vswhere to find the lib.exe path (#170)
2020-05-06 12:51:19 +02:00
data Init repo 2019-07-16 16:07:02 +02:00
enums Update dependencies 2020-05-05 10:58:14 +02:00
rust-code-analysis-cli Update dependencies 2020-04-28 14:59:59 +02:00
src Clean up src (#164) 2020-05-05 14:52:42 +02:00
tests Remove c parser and use the c++ one instead 2019-12-17 16:19:29 +01:00
tree-sitter-c-sharp@df20955232 Update various ts parsers 2019-12-18 11:30:52 +01:00
tree-sitter-ccomments Updates parsers 2019-12-17 12:35:27 +01:00
tree-sitter-cpp@72348197be Update cpp language 2020-04-02 11:03:31 +02:00
tree-sitter-css@c822c9cba5 Update various ts parsers 2019-12-18 11:30:52 +01:00
tree-sitter-go@d6b33068ac Update language dependencies 2020-03-03 11:44:24 +01:00
tree-sitter-html@2147dd298a Update languages 2020-02-24 11:20:44 +01:00
tree-sitter-java@dfbc554808 Update languages 2020-05-05 14:37:07 +02:00
tree-sitter-javascript@cef83f4520 Update languages 2020-04-01 09:58:15 +02:00
tree-sitter-mozcpp Add macro_statement in mozcpp grammar 2020-04-09 16:48:57 +02:00
tree-sitter-mozjs Update languages 2020-02-24 11:20:44 +01:00
tree-sitter-preproc Updates parsers 2019-12-17 12:35:27 +01:00
tree-sitter-python@0603b5e978 Update languages 2020-05-05 14:37:07 +02:00
tree-sitter-rust@37adf5450f Update languages 2020-05-05 14:37:07 +02:00
tree-sitter-typescript@a80ef55580 Update languages 2020-04-01 09:58:15 +02:00
.gitignore Init repo 2019-07-16 16:07:02 +02:00
.gitmodules Remove c parser and use the c++ one instead 2019-12-17 16:19:29 +01:00
.pre-commit-config.yaml Bump taskcluster_yml_validator in pre-commit configuration to v0.0.4 2020-03-19 15:29:10 +01:00
.taskcluster.yml Use vswhere to find the lib.exe path (#170) 2020-05-06 12:51:19 +02:00
Cargo.lock Update dependencies 2020-05-05 10:58:14 +02:00
Cargo.toml Update dependencies 2020-04-28 14:59:59 +02:00
README.md Fix metrics explanation in README (#162) 2020-04-28 16:26:24 +02:00
build.rs Prepare to build on Windows (#123) 2020-03-19 16:55:16 +01:00

README.md

rust-code-analysis

Task Status codecov

rust-code-analysis is a Rust library to analyze the source code of many different programming languages. It is based on a parser generator tool and an incremental parsing library called Tree Sitter.

Supported Languages

  • C++
  • C#
  • CSS
  • Go
  • HTML
  • Java
  • JavaScript
  • The JavaScript used in Firefox internal
  • Python
  • Rust
  • Typescript

Supported Metrics

  • CC: it calculates the code complexity examining the control flow of a program.
  • SLOC: it counts the number of lines in a source file.
  • PLOC: it counts the number of physical lines (instructions) contained in a source file.
  • LLOC: it counts the number of logical lines (statements) contained in a source file.
  • CLOC: it counts the number of comments in a source file.
  • BLANK: it counts the number of blank lines in a source file.
  • HALSTEAD: it is a suite that provides a series of information, such as the effort required to maintain the analyzed code, the size in bits to store the program, the difficulty to understand the code, an estimate of the number of bugs present in the codebase, and an estimate of the time needed to implement the software.
  • MI: it is a suite that allows to evaluate the maintainability of a software.
  • NOM: it counts the number of functions and closures in a file/trait/class.
  • NEXITS: it counts the number of possible exit points from a method/function.
  • NARGS: it counts the number of arguments of a function/method.

rust-code-analysis-cli

rust-code-analysis-cli is a command line tool thought to interact with the functions available in the library. It can print a series of information on your shell such as nodes and metrics. It can also export metrics as a json file. Below you can find a series of commands to use the software at best.

How to get metrics

You can get metrics in your shell in this way

rust-code-analysis-cli --metrics --paths /your/path/to/a/file

or as a json file

rust-code-analysis-cli --metrics --output your/path/to/the/output/directory --paths /your/path/to/a/file

or you can run it as a HTTP service and use its REST API

rust-code-analysis --serve --port 9090

How to build the software

Clone the repository and its submodules through HTTPS

git clone --recurse-submodules -j8 https://github.com/mozilla/rust-code-analysis.git

or through SSH

git clone --recurse-submodules -j8 git@github.com:mozilla/rust-code-analysis.git

Build and run the software

# Build rust-code-analysis with cargo
cargo build

# Build rust-code-analysis-cli with cargo
cargo build --all

# Run through cargo
cargo run -- -h
cargo run -- --serve --port 8000

How to run tests

After the build step, run the following command to verify if all tests pass

cargo test --verbose