Code Style Guide

This document provides the coding style guidelines for GraphScope’s codebase, which includes C++, Python, Rust, Java, and shell scripts. Adhering to consistent coding standards across the codebase promotes maintainability, readability, and code quality.

C++ Style

We follow the Google C++ Style Guide for coding standards in C++.

Python Style

We follow the black code style for Python coding standards.

Rust Style

We follow the rust-lang code style, with the GraphScope custom configuration for coding standards in Rust.

Java Style

we follow the Google Java Style Guide for coding standards in Java.

Script Style

We follow the Google Shell Style Guide for coding standards in shell script.

Style Linter and Checker

GraphScope uses different linters and checkers for each language to enforce code style rules:

Each linter can be included in the build process to ensure that the code adheres to the style guide. Below are the commands to check the code style in each language:

For C++, format and lint the code by the MakeFile command:

# format
$ make graphscope_clformat
# lint
$ make graphscope_cpplint

For Python:

  • Install dependencies first:

$ pip3 install -r coordinator/requirements-dev.txt
  • Check the style:

$ pushd python
$ python3 -m isort --check --diff .
$ python3 -m black --check --diff .
$ python3 -m flake8 .
$ popd
$ pushd coordinator
$ python3 -m isort --check --diff .
$ python3 -m black --check --diff .
$ python3 -m flake8 .

For Rust, we provide a shell script to do the format check:

$ cd interactive_engine/executor
$ ./check_format.sh

For Java:

  • Download the google-java-format tool:

$ wget https://github.com/google/google-java-format/releases/download/v1.13.0/google-java-format-1.13.0-all-deps.jar
  • Check the style:

$ files_to_format=$(git ls-files *.java)
$ java -jar google-java-format-1.13.0-all-deps.jar --aosp --skip-javadoc-formatting -i $files_to_format