Library to analyze and collect metrics on source code
Перейти к файлу
Luni-4 7ced6d7fe5
misc: Add a guide to update grammars (#1079)
2024-08-06 15:27:32 +02:00
.github dependabot: Do not check for submodules updates anymore (#599) 2021-03-31 09:44:13 +02:00
enums Update grammars (#1086) 2024-08-06 14:30:43 +02:00
generate-grammars Update tree-sitter-mozcpp to 0.20 (#754) 2022-01-12 13:54:04 +01:00
rust-code-analysis-book misc: Add a guide to update grammars (#1079) 2024-08-06 15:27:32 +02:00
rust-code-analysis-cli build(deps): update toml requirement from ^0.7 to ^0.8 (#1068) 2024-08-06 14:40:44 +02:00
rust-code-analysis-web Document web module (#1041) 2023-05-22 18:03:56 +02:00
src Update grammars (#1086) 2024-08-06 14:30:43 +02:00
tests Modify tests for more deterministic behavior (#1081) 2024-01-08 15:16:40 +01:00
tree-sitter-ccomment Update grammars (#1086) 2024-08-06 14:30:43 +02:00
tree-sitter-mozcpp Update grammars (#1086) 2024-08-06 14:30:43 +02:00
tree-sitter-mozjs Update grammars (#1086) 2024-08-06 14:30:43 +02:00
tree-sitter-preproc Update grammars (#1086) 2024-08-06 14:30:43 +02:00
.gitignore Ignore Cargo.lock (#1056) 2023-06-09 14:15:49 +02:00
.gitmodules Update rca-output submodule to point to the new repository in the Mozilla org 2023-11-02 15:40:35 +01:00
.pre-commit-audit-config.yaml Add cargo audit 2021-12-22 18:06:34 +01:00
.pre-commit-config.yaml Update pre-commit repositories 2023-05-22 10:58:05 +02:00
.taskcluster.yml Update workerType name from win2012r2 to win2022 2023-05-25 00:14:05 +02:00
Cargo.toml build(deps): update num-derive requirement from ^0.3 to ^0.4 (#1057) 2024-08-06 14:35:30 +02:00
README.md misc: Add a guide to update grammars (#1079) 2024-08-06 15:27:32 +02:00
check-grammar-crate.py Add Kotlin check to CI 2023-01-16 12:45:37 +01:00
check-grammars-crates.sh Extract grammars to check from Cargo.toml (#974) 2022-12-19 17:54:59 +01:00
recreate-grammars.sh Move c_macros generation into the enums crate (#676) 2021-09-29 13:49:30 +02:00
split-minimal-tests.py Add a script to split minimal tests into distinct directories depending on metrics differences (#623) 2021-05-11 08:57:03 +02:00

README.md

rust-code-analysis

Task Status codecov

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

A command line tool called rust-code-analysis-cli is provided to interact with the API of the library in an easy way.

This tool can be used to:

  • Call rust-code-analysis API
  • Print nodes and metrics information
  • Export metrics in different formats

In addition, we provide a rust-code-analysis-web tool to use the library through a REST API.

Usage

rust-code-analysis supports many types of programming languages and computes a great variety of metrics. You can find up to date documentation at Documentation.

On the Commands page, there is a list of commands that can be run to get information about metrics, nodes, and other general data provided by this software.

Building

To build the rust-code-analysis library, you need to run the following command:

cargo build

If you want to build the cli:

cargo build -p rust-code-analysis-cli

If you want to build the web server:

cargo build -p rust-code-analysis-web

If you want to build everything in one fell swoop:

cargo build --workspace

Testing

To verify whether all tests pass, run the cargo test command.

cargo test --workspace --all-features --verbose

Updating insta tests

We use insta, to update the snapshot tests you should install cargo insta

cargo insta test --review

Will run the tests, generate the new snapshot references and let you review them.

Updating grammars

Have a look at Update grammars guide to learn how to update languages grammars.

Contributing

If you want to contribute to the development of this software, have a look at the guidelines contained in our Developers Guide.

How to cite rust-code-analysis

@article{ARDITO2020100635,
    title = {rust-code-analysis: A Rust library to analyze and extract maintainability information from source codes},
    journal = {SoftwareX},
    volume = {12},
    pages = {100635},
    year = {2020},
    issn = {2352-7110},
    doi = {https://doi.org/10.1016/j.softx.2020.100635},
    url = {https://www.sciencedirect.com/science/article/pii/S2352711020303484},
    author = {Luca Ardito and Luca Barbato and Marco Castelluccio and Riccardo Coppola and Calixte Denizet and Sylvestre Ledru and Michele Valsesia},
    keywords = {Algorithm, Software metrics, Software maintainability, Software quality},
    abstract = {The literature proposes many software metrics for evaluating the source code non-functional properties, such as its complexity and maintainability. The literature also proposes several tools to compute those properties on source codes developed with many different software languages. However, the Rust language emergence has not been paired by the communitys effort in developing parsers and tools able to compute metrics for the Rust source code. Also, metrics tools often fall short in providing immediate means of comparing maintainability metrics between different algorithms or coding languages. We hence introduce rust-code-analysis, a Rust library that allows the extraction of a set of eleven maintainability metrics for ten different languages, including Rust. rust-code-analysis, through the Abstract Syntax Tree (AST) of a source file, allows the inspection of the code structure, analyzing source code metrics at different levels of granularity, and finding code syntax errors before compiling time. The tool also offers a command-line interface that allows exporting the results in different formats. The possibility of analyzing source codes written in different programming languages enables simple and systematic comparisons between the metrics produced from different empirical and large-scale analysis sources.}
}

Licenses

  • Mozilla-defined grammars are released under the MIT license.

  • rust-code-analysis, rust-code-analysis-cli and rust-code-analysis-web are released under the Mozilla Public License v2.0.