Skip to content

Commit f2d1150

Browse files
committed
Add pre-commit configuration file
Add typos checks and corrections Add static check github action
1 parent ac59434 commit f2d1150

38 files changed

+345
-171
lines changed

.clang-tidy

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Checks:
2+
- -*
3+
- cppcoreguidelines-pro-type-member-init
4+
- modernize-redundant-void-arg
5+
- modernize-use-bool-literals
6+
- modernize-use-default-member-init
7+
- modernize-use-nullptr
8+
- readability-braces-around-statements
9+
- readability-redundant-member-init
10+
HeaderFileExtensions: ['', h, hh, hpp, hxx, inc]
11+
ImplementationFileExtensions: [c, cc, cpp, cxx]
12+
HeaderFilterRegex: (extension/src/openvic-extension)/
13+
FormatStyle: file
14+
CheckOptions:
15+
cppcoreguidelines-pro-type-member-init.IgnoreArrays: true
16+
cppcoreguidelines-pro-type-member-init.UseAssignment: true
17+
modernize-use-bool-literals.IgnoreMacros: false
18+
modernize-use-default-member-init.IgnoreMacros: false
19+
modernize-use-default-member-init.UseAssignment: true

.github/workflows/builds.yml

+33
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,42 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13+
static-checks:
14+
name: Code style, file formatting, and docs
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Checkout project
18+
uses: actions/[email protected]
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Install APT dependencies
23+
uses: awalsh128/cache-apt-pkgs-action@latest
24+
with:
25+
packages: libxml2-utils
26+
27+
- name: Get changed files
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
run: |
31+
if [ "${{ github.event_name }}" == "pull_request" ]; then
32+
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
33+
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
34+
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
35+
fi
36+
echo "$files" >> changed.txt
37+
cat changed.txt
38+
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
39+
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
40+
- name: Style checks via pre-commit
41+
uses: pre-commit/[email protected]
42+
with:
43+
extra_args: --files ${{ env.CHANGED_FILES }}
44+
1345
build:
1446
runs-on: ${{matrix.os}}
1547
name: ${{matrix.name}}
48+
needs: static-checks
1649
permissions: write-all
1750
strategy:
1851
fail-fast: false

.pre-commit-config.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
default_language_version:
2+
python: python3
3+
4+
repos:
5+
# Waiting on Hop311 to approve clang-format
6+
# - repo: https://github.com/pre-commit/mirrors-clang-format
7+
# rev: v19.1.3
8+
# hooks:
9+
# - id: clang-format
10+
# files: \.(c|h|cpp|hpp|inc)$
11+
# types_or: [text]
12+
# # exclude: |
13+
# # (?x)^(
14+
# # )
15+
16+
- repo: https://github.com/pocc/pre-commit-hooks
17+
rev: v1.3.5
18+
hooks:
19+
- id: clang-tidy
20+
files: \.(c|h|cpp|hpp)$
21+
args: [--fix, --quiet, --use-color]
22+
types_or: [text]
23+
additional_dependencies: [clang-tidy==19.1.0]
24+
require_serial: true
25+
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`
26+
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.9.10
29+
hooks:
30+
- id: ruff
31+
args: [--fix]
32+
- id: ruff-format
33+
# exclude: |
34+
# (?x)^(
35+
# )
36+
37+
- repo: https://github.com/pre-commit/mirrors-mypy
38+
rev: v1.15.0
39+
hooks:
40+
- id: mypy
41+
files: \.py$
42+
types_or: [text]
43+
44+
- repo: https://github.com/crate-ci/typos
45+
rev: v1.30.2
46+
hooks:
47+
- id: typos
48+
# exclude: |
49+
# (?x)^(
50+
# )
51+
additional_dependencies: [tomli]

pyproject.toml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[tool.mypy]
2+
ignore_missing_imports = true
3+
disallow_any_generics = true
4+
no_implicit_optional = true
5+
pretty = true
6+
show_column_numbers = true
7+
warn_redundant_casts = true
8+
warn_return_any = true
9+
warn_unreachable = true
10+
namespace_packages = true
11+
explicit_package_bases = true
12+
13+
[tool.ruff]
14+
extend-include = ["SConstruct", "SCsub"]
15+
line-length = 120
16+
target-version = "py37"
17+
18+
[tool.ruff.lint]
19+
extend-select = [
20+
"I", # isort
21+
]
22+
23+
[tool.ruff.lint.per-file-ignores]
24+
"{SConstruct,SCsub}" = [
25+
"E402", # Module level import not at top of file
26+
"F821", # Undefined name
27+
]
28+
29+
[tool.typos]
30+
files.extend-exclude = [".mailmap", "*.gitignore", "*.po", "*.pot", "*.rc"]
31+
default.extend-ignore-re = [
32+
"(?Rm)^.*(#|//)\\s*paradox typo$", # Single line check disable (Paradox Typo)
33+
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$", # Single line check disable
34+
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on", # Multiline check disable with // spellchecker:off // spellchecker:on (can also use #)
35+
"(?s)(/\\*)\\s*spellchecker:off.*?\\s*spellchecker:on\\s*(\\*/)", # Multiline check disable with /* spellchecker:off ... spellchecker:on */
36+
]

src/openvic-simulation/GameManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool GameManager::load_definitions(Dataloader::localisation_callback_t localisat
3030
}
3131

3232
if (!dataloader.load_localisation_files(localisation_callback)) {
33-
Logger::error("Failed to load localisation!");
33+
Logger::error("Failed to load localization!");
3434
ret = false;
3535
}
3636

src/openvic-simulation/InstanceManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void InstanceManager::execute_game_actions() {
117117

118118
currently_executing_game_actions = true;
119119

120-
// Temporary gamestate/UI update trigger, to be replaced with a more sophisticated targetted system
120+
// Temporary gamestate/UI update trigger, to be replaced with a more sophisticated targeted system
121121
bool needs_gamestate_update = false;
122122

123123
for (game_action_t const& game_action : game_action_queue) {

src/openvic-simulation/console/ConsoleInstance.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ bool ConsoleInstance::setup_commands() {
362362
};
363363

364364
result &= add_command("showprovinceid", toggle_province_id);
365-
result &= add_command("provid", toggle_province_id);
365+
result &= add_command("provid", toggle_province_id); // spellchecker:disable-line
366366

367367
result &= add_command("date", [](Argument& arg) -> bool {
368368
if (!arg.console.validate_argument_size(arg.arguments, 2)) {

src/openvic-simulation/country/CountryDefinition.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ node_callback_t CountryDefinitionManager::load_country_party(
155155

156156
if (policy != nullptr) {
157157
Logger::error(
158-
"Country party \"", party_name, "\" has duplicate entry for issue gorup \"",
158+
"Country party \"", party_name, "\" has duplicate entry for issue group \"",
159159
issue_group.get_identifier(), "\""
160160
);
161161
return false;

src/openvic-simulation/country/CountryInstance.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ bool CountryInstance::can_research_tech(Technology const& technology, Date today
856856
void CountryInstance::start_research(Technology const& technology, InstanceManager const& instance_manager) {
857857
if (OV_unlikely(!can_research_tech(technology, instance_manager.get_today()))) {
858858
Logger::warning(
859-
"Attemping to start research for country \"", get_identifier(), "\" on technology \"",
859+
"Attempting to start research for country \"", get_identifier(), "\" on technology \"",
860860
technology.get_identifier(), "\" - cannot research this tech!"
861861
);
862862
return;
@@ -1848,7 +1848,7 @@ bool CountryInstanceManager::apply_history_to_countries(
18481848
if (entry_date <= today) {
18491849
ret &= country_instance.apply_history_to_country(*entry, instance_manager);
18501850

1851-
if (entry->get_inital_oob().has_value()) {
1851+
if (entry->get_initial_oob().has_value()) {
18521852
oob_history_entry = entry.get();
18531853
}
18541854
if (entry->get_consciousness().has_value()) {
@@ -1871,7 +1871,7 @@ bool CountryInstanceManager::apply_history_to_countries(
18711871

18721872
if (oob_history_entry != nullptr) {
18731873
ret &= unit_instance_manager.generate_deployment(
1874-
map_instance, country_instance, *oob_history_entry->get_inital_oob()
1874+
map_instance, country_instance, *oob_history_entry->get_initial_oob()
18751875
);
18761876
}
18771877

src/openvic-simulation/dataloader/Dataloader.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ static std::string_view _extract_basic_identifier_prefix_from_path(std::string_v
154154
return extract_basic_identifier_prefix(StringUtils::get_filename(path));
155155
};
156156

157-
Dataloader::path_vector_t Dataloader::lookup_basic_indentifier_prefixed_files_in_dir(
157+
Dataloader::path_vector_t Dataloader::lookup_basic_identifier_prefixed_files_in_dir(
158158
std::string_view path, fs::path const& extension
159159
) const {
160160
return _lookup_files_in_dir<fs::directory_iterator>(path, extension, _extract_basic_identifier_prefix_from_path);
161161
}
162162

163-
Dataloader::path_vector_t Dataloader::lookup_basic_indentifier_prefixed_files_in_dir_recursive(
163+
Dataloader::path_vector_t Dataloader::lookup_basic_identifier_prefixed_files_in_dir_recursive(
164164
std::string_view path, fs::path const& extension
165165
) const {
166166
return _lookup_files_in_dir<fs::recursive_directory_iterator>(path, extension, _extract_basic_identifier_prefix_from_path);
@@ -511,7 +511,7 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
511511

512512
static constexpr std::string_view country_history_directory = "history/countries";
513513
const path_vector_t country_history_files =
514-
lookup_basic_indentifier_prefixed_files_in_dir(country_history_directory, ".txt");
514+
lookup_basic_identifier_prefixed_files_in_dir(country_history_directory, ".txt");
515515

516516
country_history_manager.reserve_more_country_histories(country_history_files.size());
517517
deployment_manager.reserve_more_deployments(country_history_files.size());
@@ -555,7 +555,7 @@ bool Dataloader::_load_history(DefinitionManager& definition_manager, bool unuse
555555

556556
static constexpr std::string_view province_history_directory = "history/provinces";
557557
const path_vector_t province_history_files =
558-
lookup_basic_indentifier_prefixed_files_in_dir_recursive(province_history_directory, ".txt");
558+
lookup_basic_identifier_prefixed_files_in_dir_recursive(province_history_directory, ".txt");
559559

560560
province_history_manager.reserve_more_province_histories(province_history_files.size());
561561

src/openvic-simulation/dataloader/Dataloader.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ namespace OpenVic {
104104
fs::path lookup_image_file(std::string_view path) const;
105105
path_vector_t lookup_files_in_dir(std::string_view path, fs::path const& extension) const;
106106
path_vector_t lookup_files_in_dir_recursive(std::string_view path, fs::path const& extension) const;
107-
path_vector_t lookup_basic_indentifier_prefixed_files_in_dir(std::string_view path, fs::path const& extension) const;
108-
path_vector_t lookup_basic_indentifier_prefixed_files_in_dir_recursive(
107+
path_vector_t lookup_basic_identifier_prefixed_files_in_dir(std::string_view path, fs::path const& extension) const;
108+
path_vector_t lookup_basic_identifier_prefixed_files_in_dir_recursive(
109109
std::string_view path, fs::path const& extension
110110
) const;
111111

@@ -127,7 +127,7 @@ namespace OpenVic {
127127
public:
128128
enum locale_t : size_t {
129129
English, French, German, Polish, Spanish, Italian, Swedish,
130-
Czech, Hungarian, Dutch, Portugese, Russian, Finnish, _LocaleCount
130+
Czech, Hungarian, Dutch, Portuguese, Russian, Finnish, _LocaleCount
131131
};
132132
static constexpr char const* locale_names[_LocaleCount] = {
133133
"en_GB", "fr_FR", "de_DE", "pl_PL", "es_ES", "it_IT", "sv_SE",

src/openvic-simulation/defines/CountryDefines.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ CountryDefines::CountryDefines()
7272
colonization_duration {},
7373
colonization_days_between_investment {},
7474
colonization_days_for_initial_investment {},
75-
colonization_protectorate_province_maintainance {},
76-
colonization_colony_province_maintainance {},
77-
colonization_colony_industry_maintainance {},
78-
colonization_colony_railway_maintainance {},
75+
colonization_protectorate_province_maintenance {},
76+
colonization_colony_province_maintenance {},
77+
colonization_colony_industry_maintenance {},
78+
colonization_colony_railway_maintenance {},
7979
colonization_interest_cost_initial {},
8080
colonization_interest_cost_neighbor_modifier {},
8181
colonization_interest_cost {},
@@ -189,14 +189,14 @@ node_callback_t CountryDefines::expect_defines() {
189189
expect_days(assign_variable_callback(colonization_days_between_investment)),
190190
"COLONIZATION_DAYS_FOR_INITIAL_INVESTMENT", ONE_EXACTLY,
191191
expect_days(assign_variable_callback(colonization_days_for_initial_investment)),
192-
"COLONIZATION_PROTECTORATE_PROVINCE_MAINTAINANCE", ONE_EXACTLY,
193-
expect_fixed_point(assign_variable_callback(colonization_protectorate_province_maintainance)),
194-
"COLONIZATION_COLONY_PROVINCE_MAINTAINANCE", ONE_EXACTLY,
195-
expect_fixed_point(assign_variable_callback(colonization_colony_province_maintainance)),
196-
"COLONIZATION_COLONY_INDUSTRY_MAINTAINANCE", ONE_EXACTLY,
197-
expect_fixed_point(assign_variable_callback(colonization_colony_industry_maintainance)),
198-
"COLONIZATION_COLONY_RAILWAY_MAINTAINANCE", ONE_EXACTLY,
199-
expect_fixed_point(assign_variable_callback(colonization_colony_railway_maintainance)),
192+
"COLONIZATION_PROTECTORATE_PROVINCE_MAINTAINANCE", ONE_EXACTLY, // paradox typo
193+
expect_fixed_point(assign_variable_callback(colonization_protectorate_province_maintenance)),
194+
"COLONIZATION_COLONY_PROVINCE_MAINTAINANCE", ONE_EXACTLY, // paradox typo
195+
expect_fixed_point(assign_variable_callback(colonization_colony_province_maintenance)),
196+
"COLONIZATION_COLONY_INDUSTRY_MAINTAINANCE", ONE_EXACTLY, // paradox typo
197+
expect_fixed_point(assign_variable_callback(colonization_colony_industry_maintenance)),
198+
"COLONIZATION_COLONY_RAILWAY_MAINTAINANCE", ONE_EXACTLY, // paradox typo
199+
expect_fixed_point(assign_variable_callback(colonization_colony_railway_maintenance)),
200200
"COLONIZATION_INTEREST_COST_INITIAL", ONE_EXACTLY,
201201
expect_fixed_point(assign_variable_callback(colonization_interest_cost_initial)),
202202
"COLONIZATION_INTEREST_COST_NEIGHBOR_MODIFIER", ONE_EXACTLY,

src/openvic-simulation/defines/CountryDefines.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ namespace OpenVic {
8181
Timespan PROPERTY(colonization_duration);
8282
Timespan PROPERTY(colonization_days_between_investment);
8383
Timespan PROPERTY(colonization_days_for_initial_investment);
84-
fixed_point_t PROPERTY(colonization_protectorate_province_maintainance);
85-
fixed_point_t PROPERTY(colonization_colony_province_maintainance);
86-
fixed_point_t PROPERTY(colonization_colony_industry_maintainance);
87-
fixed_point_t PROPERTY(colonization_colony_railway_maintainance);
84+
fixed_point_t PROPERTY(colonization_protectorate_province_maintenance);
85+
fixed_point_t PROPERTY(colonization_colony_province_maintenance);
86+
fixed_point_t PROPERTY(colonization_colony_industry_maintenance);
87+
fixed_point_t PROPERTY(colonization_colony_railway_maintenance);
8888
fixed_point_t PROPERTY(colonization_interest_cost_initial);
8989
fixed_point_t PROPERTY(colonization_interest_cost_neighbor_modifier);
9090
fixed_point_t PROPERTY(colonization_interest_cost);

src/openvic-simulation/defines/DiplomacyDefines.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ DiplomacyDefines::DiplomacyDefines()
183183
war_prestige_cost_neg_prestige {},
184184
war_prestige_cost_truce {},
185185
war_prestige_cost_honor_alliance {},
186-
war_prestige_cost_honor_guarnatee {},
186+
war_prestige_cost_honor_guarantee {},
187187
war_prestige_cost_uncivilized {},
188188
war_prestige_cost_core {},
189189
war_failed_goal_militancy {},
@@ -654,8 +654,8 @@ node_callback_t DiplomacyDefines::expect_defines() {
654654
"WAR_PRESTIGE_COST_TRUCE", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(war_prestige_cost_truce)),
655655
"WAR_PRESTIGE_COST_HONOR_ALLIANCE", ONE_EXACTLY,
656656
expect_fixed_point(assign_variable_callback(war_prestige_cost_honor_alliance)),
657-
"WAR_PRESTIGE_COST_HONOR_GUARNATEE", ONE_EXACTLY,
658-
expect_fixed_point(assign_variable_callback(war_prestige_cost_honor_guarnatee)),
657+
"WAR_PRESTIGE_COST_HONOR_GUARNATEE", ONE_EXACTLY, // paradox typo
658+
expect_fixed_point(assign_variable_callback(war_prestige_cost_honor_guarantee)),
659659
"WAR_PRESTIGE_COST_UNCIVILIZED", ONE_EXACTLY,
660660
expect_fixed_point(assign_variable_callback(war_prestige_cost_uncivilized)),
661661
"WAR_PRESTIGE_COST_CORE", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(war_prestige_cost_core)),

src/openvic-simulation/defines/DiplomacyDefines.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ namespace OpenVic {
191191
fixed_point_t PROPERTY(war_prestige_cost_neg_prestige);
192192
fixed_point_t PROPERTY(war_prestige_cost_truce);
193193
fixed_point_t PROPERTY(war_prestige_cost_honor_alliance);
194-
fixed_point_t PROPERTY(war_prestige_cost_honor_guarnatee);
194+
fixed_point_t PROPERTY(war_prestige_cost_honor_guarantee);
195195
fixed_point_t PROPERTY(war_prestige_cost_uncivilized);
196196
fixed_point_t PROPERTY(war_prestige_cost_core);
197197
fixed_point_t PROPERTY(war_failed_goal_militancy);

src/openvic-simulation/defines/EconomyDefines.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ EconomyDefines::EconomyDefines()
1818
goods_focus_swap_chance {},
1919
num_closed_factories_per_state_lassiez_faire {},
2020
min_num_factories_per_state_before_deleting_lassiez_faire {},
21-
bankrupcy_duration {},
21+
bankruptcy_duration {},
2222
second_rank_base_share_factor {},
2323
civ_base_share_factor {},
2424
unciv_base_share_factor {},
@@ -62,7 +62,7 @@ node_callback_t EconomyDefines::expect_defines() {
6262
expect_uint(assign_variable_callback(num_closed_factories_per_state_lassiez_faire)),
6363
"MIN_NUM_FACTORIES_PER_STATE_BEFORE_DELETING_LASSIEZ_FAIRE", ONE_EXACTLY,
6464
expect_uint(assign_variable_callback(min_num_factories_per_state_before_deleting_lassiez_faire)),
65-
"BANKRUPCY_DURATION", ONE_EXACTLY, expect_years(assign_variable_callback(bankrupcy_duration)),
65+
"BANKRUPCY_DURATION", ONE_EXACTLY, expect_years(assign_variable_callback(bankruptcy_duration)), // paradox typo
6666
"SECOND_RANK_BASE_SHARE_FACTOR", ONE_EXACTLY,
6767
expect_fixed_point(assign_variable_callback(second_rank_base_share_factor)),
6868
"CIV_BASE_SHARE_FACTOR", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(civ_base_share_factor)),

src/openvic-simulation/defines/EconomyDefines.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace OpenVic {
2626
fixed_point_t PROPERTY(goods_focus_swap_chance);
2727
size_t PROPERTY(num_closed_factories_per_state_lassiez_faire);
2828
size_t PROPERTY(min_num_factories_per_state_before_deleting_lassiez_faire);
29-
Timespan PROPERTY(bankrupcy_duration);
29+
Timespan PROPERTY(bankruptcy_duration);
3030
fixed_point_t PROPERTY(second_rank_base_share_factor);
3131
fixed_point_t PROPERTY(civ_base_share_factor);
3232
fixed_point_t PROPERTY(unciv_base_share_factor);

0 commit comments

Comments
 (0)