Skip to content

Commit 54ecc45

Browse files
authored
Format .json files and add formatting workflow (#204)
1 parent 8f71fd7 commit 54ecc45

File tree

86 files changed

+365004
-247750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+365004
-247750
lines changed

.github/workflows/codechecks.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
# This workflow checks for compliance with the Google C++ style guide.
1+
# This workflow checks for compliance with:
2+
# - *.cpp/*.h files (clang-format, .clang-format)
3+
# - *.json (Prettier, .prettierrc)
24
name: Codechecks
35
on: [push, pull_request]
46
jobs:
5-
clang-format:
7+
code-format:
68
runs-on: macos-latest
79
steps:
810
- uses: actions/checkout@v3
911
- name: Install dependencies
1012
run: |
1113
brew install clang-format
14+
brew install npm
15+
npm init -y
16+
npm install prettier
1217
- name: Run clang-format
1318
run: |
1419
mkdir Release

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,3 @@ build*/
3838

3939
# Node modules (for directed graph visualization)
4040
node_modules/
41-
42-
.github
43-

.licenserc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"SPDX-License-Identifier: BSD-3-Clause"
55
],
66
"ignore": []
7-
}
7+
}

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"printWidth": 80,
5+
"singleQuote": false
6+
}

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ set(SDIR ${PROJECT_SOURCE_DIR}/src/**/)
256256

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

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

265267
set_target_properties(pysvzerod PROPERTIES

cypress/downloads/graph_data.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@
2525
],
2626
"junctions": [
2727
{
28-
"inlet_vessels": [
29-
0
30-
],
28+
"inlet_vessels": [0],
3129
"junction_name": "J0",
32-
"outlet_vessels": [
33-
1
34-
]
30+
"outlet_vessels": [1]
3531
}
3632
],
3733
"vessels": [
@@ -68,4 +64,4 @@
6864
],
6965
"valves": [],
7066
"chambers": []
71-
}
67+
}

docs/pages/developer_guide.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,13 @@ Steps required to visualize a new block with svZeroDSolver Visualization applica
7272

7373
# Code Style
7474

75-
We follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
76-
77-
## Formatting {#formatting}
78-
79-
We use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to automatically
80-
format our code accoring to the [Google Style](https://google.github.io/styleguide/cppguide.html),
81-
as specified in the `.clang-format` file. This increases readability and maintainability of the code
75+
We use automatic code formatting for certain files to increase readability and maintainability of the code
8276
while enabling you to focus on coding.
8377

84-
There are tools for your favorite IDE to automatically format your code. Examples are:
85-
- [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format)
86-
- [vim](https://github.com/rhysd/vim-clang-format)
87-
- [and many more](https://clang.llvm.org/docs/ClangFormat.html)
78+
## Formatting {#formatting}
79+
The following files are automatically formatted:
80+
- 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))
81+
- Test cases and results (`.json`): [Prettier](https://prettier.io/) as specified in `.prettierrc`
8882

8983
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
9084
* on MacOS: `brew upgrade clang-format`
@@ -117,6 +111,27 @@ requirements.
117111

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

114+
## Visual Studio Code
115+
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)")
116+
```json
117+
"editor.formatOnSave": true,
118+
"[cpp]": {
119+
"editor.defaultFormatter": "xaver.clang-format"
120+
},
121+
"[json]": {
122+
"editor.defaultFormatter": "esbenp.prettier-vscode",
123+
},
124+
"[jsonc]": {
125+
"editor.defaultFormatter": "esbenp.prettier-vscode",
126+
},
127+
```
128+
129+
## Vim
130+
Install the [clang-format](https://github.com/rhysd/vim-clang-format) and [Prettier](https://github.com/prettier/vim-prettier) plugins.
131+
132+
## Other editors
133+
See [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and [Prettier](https://prettier.io/docs/editors.html).
134+
120135
# Documentation {#documentation}
121136

122137
We use [Doxygen](https://doxygen.nl) to automatically build an html documentation

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"devDependencies": {
3+
"prettier": "^3.6.2"
4+
},
5+
"scripts": {
6+
"format": "prettier --write \"**/*.json\"",
7+
"check": "prettier --check \"**/*.json\""
8+
}
9+
}

0 commit comments

Comments
 (0)