Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/codechecks.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# This workflow checks for compliance with the Google C++ style guide.
# This workflow checks for compliance with:
# - *.cpp/*.h files (clang-format, .clang-format)
# - *.json (Prettier, .prettierrc)
name: Codechecks
on: [push, pull_request]
jobs:
clang-format:
code-format:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
brew install clang-format
brew install npm
npm init -y
npm install prettier
- name: Run clang-format
run: |
mkdir Release
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,3 @@ build*/

# Node modules (for directed graph visualization)
node_modules/

.github

2 changes: 1 addition & 1 deletion .licenserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"SPDX-License-Identifier: BSD-3-Clause"
],
"ignore": []
}
}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"printWidth": 80,
"singleQuote": false
}
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,12 @@ set(SDIR ${PROJECT_SOURCE_DIR}/src/**/)

# format the code
add_custom_target(codeformat
COMMAND npm run format
COMMAND find ${SDIR}/*.h ${SDIR}/*.cpp | xargs clang-format -style=file:${PROJECT_SOURCE_DIR}/.clang-format -i)

# check code format
add_custom_target(codecheck
COMMAND npm run check
COMMAND find ${SDIR}/*.h ${SDIR}/*.cpp | xargs clang-format -style=file:${PROJECT_SOURCE_DIR}/.clang-format --dry-run --Werror)

set_target_properties(pysvzerod PROPERTIES
Expand Down
10 changes: 3 additions & 7 deletions cypress/downloads/graph_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
],
"junctions": [
{
"inlet_vessels": [
0
],
"inlet_vessels": [0],
"junction_name": "J0",
"outlet_vessels": [
1
]
"outlet_vessels": [1]
}
],
"vessels": [
Expand Down Expand Up @@ -68,4 +64,4 @@
],
"valves": [],
"chambers": []
}
}
37 changes: 26 additions & 11 deletions docs/pages/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,13 @@ Steps required to visualize a new block with svZeroDSolver Visualization applica

# Code Style

We follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).

## Formatting {#formatting}

We use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to automatically
format our code accoring to the [Google Style](https://google.github.io/styleguide/cppguide.html),
as specified in the `.clang-format` file. This increases readability and maintainability of the code
We use automatic code formatting for certain files to increase readability and maintainability of the code
while enabling you to focus on coding.

There are tools for your favorite IDE to automatically format your code. Examples are:
- [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format)
- [vim](https://github.com/rhysd/vim-clang-format)
- [and many more](https://clang.llvm.org/docs/ClangFormat.html)
## Formatting {#formatting}
The following files are automatically formatted:
- Source code (`.cpp, .h`): [clang-format](https://clang.llvm.org/docs/ClangFormat.html) as specified in `.clang-format` (defaults to [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html))
- Test cases and results (`.json`): [Prettier](https://prettier.io/) as specified in `.prettierrc`

Before formatting the code with clang-format, ensure that you have latest clang-format version by running `clang-format --version`. To upgrade `clang-format` use the following commands
* on MacOS: `brew upgrade clang-format`
Expand Down Expand Up @@ -117,6 +111,27 @@ requirements.

On Sherlock at Stanford, clang-format is included in the `llvm` module.

## Visual Studio Code
Install the [clang-format](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format) and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugins. To automatically format your files on save, add to your user settings (on macOS, press `Cmd+Shift+P`, type "Preferences: Open User Settings (JSON)")
```json
"editor.formatOnSave": true,
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
```

## Vim
Install the [clang-format](https://github.com/rhysd/vim-clang-format) and [Prettier](https://github.com/prettier/vim-prettier) plugins.

## Other editors
See [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and [Prettier](https://prettier.io/docs/editors.html).

# Documentation {#documentation}

We use [Doxygen](https://doxygen.nl) to automatically build an html documentation
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"devDependencies": {
"prettier": "^3.6.2"
},
"scripts": {
"format": "prettier --write \"**/*.json\"",
"check": "prettier --check \"**/*.json\""
}
}
Loading
Loading