Skip to content

Commit

Permalink
Add pre-commit configuration file
Browse files Browse the repository at this point in the history
Add typos checks and corrections
Add static check github action
Add clang-tidy corrections
Use optional initialization for PROPERTY macros
  • Loading branch information
Spartan322 committed Jan 22, 2025
1 parent 730fcdb commit 7b000d1
Show file tree
Hide file tree
Showing 56 changed files with 614 additions and 148 deletions.
19 changes: 19 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Checks:
- -*
- cppcoreguidelines-pro-type-member-init
- modernize-redundant-void-arg
- modernize-use-bool-literals
- modernize-use-default-member-init
- modernize-use-nullptr
- readability-braces-around-statements
- readability-redundant-member-init
HeaderFileExtensions: ['', h, hh, hpp, hxx, inc]
ImplementationFileExtensions: [c, cc, cpp, cxx]
HeaderFilterRegex: (extension/src/openvic-extension)/
FormatStyle: file
CheckOptions:
cppcoreguidelines-pro-type-member-init.IgnoreArrays: true
cppcoreguidelines-pro-type-member-init.UseAssignment: true
modernize-use-bool-literals.IgnoreMacros: false
modernize-use-default-member-init.IgnoreMacros: false
modernize-use-default-member-init.UseAssignment: true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ body:
Thank you for filling out this bug report!
When reporting a bug, please follow the guidelines in this template. This helps us quickly identify the problem you're having.
- If this report is about a feature or behavior in Victoria II that is missing or working incorrectly in OpenVic, please report a [Victoria II discrepency](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=2-victoria-2-discrepency.yml) instead.
- If this report is about a feature or behavior in Victoria II that is missing or working incorrectly in OpenVic, please report a [Victoria II discrepancy](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=2-victoria-2-discrepancy.yml) instead.
- Write a descriptive issue title above.
- **Always open *one* issue for *one* bug**. If you notice several bugs, make sure to create one new issue for each of them.
- Verify that you are using either the latest release or the latest commit. It is preferred that you check if your issue is reproducible in the latest commit - it may already have been fixed!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
name: Victoria II Discrepency
description: "Report a discrepency from Victoria II. NOTE: Not for reporting bugs in OpenVic."
labels: ["bug", "victoria 2 discrepency", "needs triage"]
name: Victoria II Discrepancy
description: "Report a discrepancy from Victoria II. NOTE: Not for reporting bugs in OpenVic."
labels: ["bug", "victoria 2 discrepancy", "needs triage"]
body:
- type: markdown
attributes:
value: |
Thank you for filling out this discrepency report!
Thank you for filling out this discrepancy report!
When reporting a bug, please follow the guidelines in this template. This helps us quickly identify the discrepency and get to work on a solution.
When reporting a bug, please follow the guidelines in this template. This helps us quickly identify the discrepancy and get to work on a solution.
- Only open this issue if you have noticed a difference between OpenVic and Victoria II.
- **DO NOT FILE CRASHES HERE!** Please use the [bug report](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=1-bug-report.yml) template instead.
- Write a descriptive issue title above.
- **Always open *one* issue for *one* discrepency**. If you notice several discrepencies, make sure to create one new issue for each of them.
- **Always open *one* issue for *one* discrepancy**. If you notice several discrepancies, make sure to create one new issue for each of them.
- Verify that you are using either the latest release or the latest commit. It is preferred that you check if your issue is reproducible in the latest commit - it may already have been fixed!
- If you're playing with custom source modifications, please test if this discrepency is reproducible in the latest official build of OpenVic before opening an issue here.
- If you're playing with custom source modifications, please test if this discrepancy is reproducible in the latest official build of OpenVic before opening an issue here.
- type: checkboxes
attributes:
label: Duplicate Issue?
description: "Search [open](https://github.com/OpenVicProject/OpenVic/issues) and [closed](https://github.com/OpenVicProject/OpenVic/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported. If you don't find a relevant match or if you're not sure, don't hesitate to **open a new issue**. Contributors will handle it from there if it's a duplicate."
options:
- label: I have checked for an existing discrepency report.
- label: I have checked for an existing discrepancy report.
required: true

- type: textarea
id: game-versions
attributes:
label: Game & Version Info
description: |
Enter the OpenVic version and commit you found this discrepency on in this box. You can find and copy this by clicking on the "Game Info" button in the bottom left corner of the OpenVic main menu. If you've found this discrepency to be reproducible on multiple versions, list all of those versions here.
Enter the OpenVic version and commit you found this discrepancy on in this box. You can find and copy this by clicking on the "Game Info" button in the bottom left corner of the OpenVic main menu. If you've found this discrepancy to be reproducible on multiple versions, list all of those versions here.
placeholder: |
- Found in: <v0.02_Mappa_Mundi> (c65b2a795fd35e81f7a1906d07d15c47cd94cf9c).
- Not reproducible in: <v0.01_Primum_Mobile> (1980012045ea4c6b314d6d12a796eda23ae8d7fa).
Expand All @@ -43,11 +43,11 @@ body:
If you used any mods or extensions, please list them here with the version and a link to each mod/extension.
- type: textarea
id: discrepency-description
id: discrepancy-description
attributes:
label: Issue Description
description: |
Describe the discrepency briefly. What happens in OpenVic, and how does it work in Victoria II?
Describe the discrepancy briefly. What happens in OpenVic, and how does it work in Victoria II?
You can include images or videos with drag and drop.
validations:
required: true
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/3-gameplay-feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ body:
- type: markdown
attributes:
value: |
- If this feature was in Victoria II, please report a [Victoria II Discrepency](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=2-victoria-2-discrepency.yml) instead.
- If this feature was in Victoria II, please report a [Victoria II Discrepancy](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=2-victoria-2-discrepency.yml) instead.
- If this feature only applies to mods and contains no mechanical additions to the vanilla experience, please report it as a [mod feature request](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=4-mod-feature-request.yml).
- Write a descriptive proposal title above.
Expand All @@ -22,6 +22,6 @@ body:
attributes:
label: Feature Description
description: An in-depth description of what feature you want added to OpenVic, and **why** its important to have.
placeholder: Example - "Add a macro builder - a menu that allows you to contruct armies or navies from templates. Think of the macro builder menu from EUIV perhaps. This will improve the game experience by allowing people to build whole armies at once rather than counting out brigades in the army build menu."
placeholder: Example - "Add a macro builder - a menu that allows you to construct armies or navies from templates. Think of the macro builder menu from EUIV perhaps. This will improve the game experience by allowing people to build whole armies at once rather than counting out brigades in the army build menu."
validations:
required: true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/4-mod-feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ body:
- type: markdown
attributes:
value: |
- If this feature was in Victoria II, please report a [Victoria II discrepency](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=2-victoria-2-discrepency.yml) instead.
- If this feature was in Victoria II, please report a [Victoria II discrepancy](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=2-victoria-2-discrepancy.yml) instead.
- If this feature only intends to include mechanical additions to the vanilla experience, please report it as a [gameplay feature request](https://github.com/OpenVicProject/OpenVic/issues/new?assignees=&labels=&projects=&template=3-gameplay-feature-request.yml).
- Write a descriptive proposal title above.
Expand Down
40 changes: 39 additions & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,47 @@ concurrency:
cancel-in-progress: true

jobs:
static-checks:
name: Code style, file formatting, and docs
runs-on: ubuntu-24.04
steps:
- name: Checkout project
uses: actions/[email protected]
with:
fetch-depth: 2

- name: Install APT dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libxml2-utils

- name: Get changed files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
fi
echo "$files" >> changed.txt
cat changed.txt
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
- name: Style checks via pre-commit
uses: pre-commit/[email protected]
with:
extra_args: --files ${{ env.CHANGED_FILES }}

- name: Class reference schema checks
run: |
xmllint --noout --schema extension/doc_tools/class.xsd extension/doc_classes/*.xml
build:
runs-on: ${{matrix.os}}
name: ${{matrix.name}}
needs: static-checks
permissions: write-all
strategy:
fail-fast: false
Expand Down Expand Up @@ -140,7 +178,7 @@ jobs:
runs-on: ubuntu-latest
needs: [build]

name: Peform Godot Debug Checks
name: Perform Godot Debug Checks
steps:
- name: Checkout project
uses: actions/[email protected]
Expand Down
73 changes: 73 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
default_language_version:
python: python3

repos:
# Waiting on Hop311 to approve clang-format
# - repo: https://github.com/pre-commit/mirrors-clang-format
# rev: v19.1.3
# hooks:
# - id: clang-format
# files: \.(c|h|cpp|hpp|inc)$
# types_or: [text]
# # exclude: |
# # (?x)^(
# # )

- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-tidy
files: \.(c|h|cpp|hpp|inc)$
args: [--fix, --quiet, --use-color]
types_or: [text]
additional_dependencies: [clang-tidy==19.1.0]
require_serial: true
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
exclude: |
(?x)^(
extension/doc_tools/make_rst.py|
extension/doc_tools/doc_status.py
)
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
files: \.py$
types_or: [text]

- repo: https://github.com/crate-ci/typos
rev: v1.29.4
hooks:
- id: typos
exclude: |
(?x)^(
game/assets/localisation/locales/.*|
game/addons/.*
)
- repo: local
hooks:
- id: make-rst
name: make-rst
language: python
entry: python extension/doc_tools/make_rst.py
args: [extension, --dry-run, --color]
pass_filenames: false
files: ^(extension/doc_classes)/.*\.xml$

- id: doc-status
name: doc-status
language: python
entry: python extension/doc_tools/doc_status.py
args: [extension/doc_classes]
pass_filenames: false
files: ^(extension/doc_classes)/.*\.xml$
2 changes: 1 addition & 1 deletion docs/contribution/cloning.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ After cloning you must initialize and update the submodules:
cd OpenVic
git submodule update --init --recursive
```
Updating the submodules is neccessary every time the dependencies are updated, if you're unsure, on every `git pull` you should also call `git submodule update --init --recursive`
Updating the submodules is necessary every time the dependencies are updated, if you're unsure, on every `git pull` you should also call `git submodule update --init --recursive`

To update the repo you must pull the repo:
```sh
Expand Down
2 changes: 1 addition & 1 deletion docs/contribution/rebasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ Read the comments following the `#` and it'll tell you what to do, generally we
pick 24a0751 Update README.md for Archlinux users
s 0e408c8 Add Window Override
```
The top value is the first commit you referred to, this list is organized according to a seqeunce of the commit history, (this specific one was made via `HEAD~2`) you will always want the first one to be pick here, generally everything else is squash/s so it merges the commit into the previous commit while still giving you control over the commit messages. After this it will rebase the commits and then ask you about the commit message you wish to create, this will have to be up to you, you can always change it later, if there is a problem with it we will mention it. Now that you've done that however, the last step is to force push it, to do so you can use `git gui` and push then click the force option or you can call `git push -f`. Now your squash is complete. Be careful rebasing or squash when someone else is working on your branchs at the same time, a force push can hurt them, you should wait until they tell you that they're done and merge their changes to your branch before you rebase/squash. Rebasing/squashing commits that others rely upon is a one-way ticket to Git nigthmares.
The top value is the first commit you referred to, this list is organized according to a sequence of the commit history, (this specific one was made via `HEAD~2`) you will always want the first one to be pick here, generally everything else is squash/s so it merges the commit into the previous commit while still giving you control over the commit messages. After this it will rebase the commits and then ask you about the commit message you wish to create, this will have to be up to you, you can always change it later, if there is a problem with it we will mention it. Now that you've done that however, the last step is to force push it, to do so you can use `git gui` and push then click the force option or you can call `git push -f`. Now your squash is complete. Be careful rebasing or squash when someone else is working on your branches at the same time, a force push can hurt them, you should wait until they tell you that they're done and merge their changes to your branch before you rebase/squash. Rebasing/squashing commits that others rely upon is a one-way ticket to Git nightmares.
2 changes: 1 addition & 1 deletion docs/dataloading-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ First, let's look at the function's arguments:
- `CountryManager const& country_manager` - an object which loads and stores countries, in the same way as `CultureManager` loads and stores cultures and culture groups; here, this is used to parse the culture group's `union` country.
- `size_t& total_expected_cultures` - a reference to an unsigned integer, used to count the number of cultures in this culture group.
- `GraphicalCultureType const* default_unit_graphical_culture_type` - a pointer to a graphical culture type, representing the default `Generic` graphical culture.
- `std::string_view culture_group_key` - a string (or rather an object referencing a string, but not holding the memory itself), representing the idenfifier of the culture group being loaded (for example `"north_german"`).
- `std::string_view culture_group_key` - a string (or rather an object referencing a string, but not holding the memory itself), representing the identifier of the culture group being loaded (for example `"north_german"`).
- `ast::NodeCPtr culture_group_node` - a node representing the culture group's text defines, which is used as input to data parsing functions.

```
Expand Down
2 changes: 1 addition & 1 deletion docs/simulation/calculations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Economy:
/30: Hardcoded value to represent days in a month.
Gold income daily:
formula: MGQ * GOLD_TO_CASH_RATE
MGQ: Money good quanity = total production of goods with money = yes
MGQ: Money good quantity = total production of goods with money = yes
GOLD_TO_CASH_RATE: defines.country.GOLD_TO_CASH_RATE
Overseas maintenance:
See: https://github.com/schombert/Project-Alice/blob/b7889a9c302feed851c039f1a98d73b75be3215a/docs/rules.md#overseas-penalty
Expand Down
6 changes: 3 additions & 3 deletions docs/styleguide-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
>“Programs are meant to be read by humans and only incidentally for computers to execute.”
> - H. Abelson and G. Sussman in [*Structure and Interpretation of Computer Programs*](https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs)
The purpose of this styleguide is to give a clear framework for other contributors, to minimize ambiguity, and to have a consistant way to convey the intent of code.
The purpose of this styleguide is to give a clear framework for other contributors, to minimize ambiguity, and to have a consistent way to convey the intent of code.

### 1.1. General Principles
- Prefer clarity over brevity
Expand Down Expand Up @@ -91,7 +91,7 @@ Source code files should adhere to the following:
```
- The content of classes should appear in the following order:
- Type Aliases
- Static (class-wide) atributes
- Static (class-wide) attributes
- Attributes
- Constructors and Destructors
- Static (class-wide) methods
Expand Down Expand Up @@ -272,7 +272,7 @@ Source code files should adhere to the following:
return num % 2 == 0;
}
```
- When a function parameter is being passed by const referance, put one space between the type and `const&`. If a parameter is passed by mutable reference do not put a space between the type and the `&`
- When a function parameter is being passed by const reference, put one space between the type and `const&`. If a parameter is passed by mutable reference do not put a space between the type and the `&`
```c++
//Correct for a const reference
bool hasLargeNumber(std::vector<int> const& numbers) {
Expand Down
Loading

0 comments on commit 7b000d1

Please sign in to comment.