Skip to content

Feature/full clang tidy #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Sep 27, 2024
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
6 changes: 5 additions & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ on:
options:
- all
- power_grid_model_c
- power_grid_model_api_tests
- all power_grid_model_benchmark_cpp
- power_grid_model_unit_tests
- power_grid_model_api_tests
- power_grid_model_validation_tests
- power_grid_model_benchmark_cpp
- power_grid_model_c_example
required: true

concurrency:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ jobs:
clang-tidy:
uses: "./.github/workflows/clang-tidy.yml"
with:
target: power_grid_model_c
# target: "all power_grid_model_benchmark_cpp" # TODO(mgovers): re-enable when more clang-tidy stuff is fixed
target: "all power_grid_model_benchmark_cpp"
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ SPDX-License-Identifier: MPL-2.0
[![PyPI version](https://badge.fury.io/py/power-grid-model.svg?no-cache)](https://badge.fury.io/py/power-grid-model)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/power-grid-model/badges/version.svg?no-cache)](https://anaconda.org/conda-forge/power-grid-model)
[![License: MPL2.0](https://img.shields.io/badge/License-MPL2.0-informational.svg)](https://github.com/PowerGridModel/power-grid-model/blob/main/LICENSE)
[![Downloads](https://static.pepy.tech/badge/power-grid-model)](https://pepy.tech/project/power-grid-model)
[![Downloads](https://static.pepy.tech/badge/power-grid-model/month)](https://pepy.tech/project/power-grid-model)

[![Build and Test C++ and Python](https://github.com/PowerGridModel/power-grid-model/actions/workflows/main.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model/actions/workflows/main.yml)
[![Check Code Quality](https://github.com/PowerGridModel/power-grid-model/actions/workflows/check-code-quality.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model/actions/workflows/check-code-quality.yml)
[![Clang Tidy](https://github.com/PowerGridModel/power-grid-model/actions/workflows/clang-tidy.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model/actions/workflows/clang-tidy.yml)
[![REUSE Compliance Check](https://github.com/PowerGridModel/power-grid-model/actions/workflows/reuse-compliance.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model/actions/workflows/reuse-compliance.yml)
[![docs](https://readthedocs.org/projects/power-grid-model/badge/)](https://power-grid-model.readthedocs.io/en/stable/)
[![Downloads](https://static.pepy.tech/badge/power-grid-model)](https://pepy.tech/project/power-grid-model)
[![Downloads](https://static.pepy.tech/badge/power-grid-model/month)](https://pepy.tech/project/power-grid-model)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=PowerGridModel_power-grid-model&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=PowerGridModel_power-grid-model)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=PowerGridModel_power-grid-model&metric=coverage)](https://sonarcloud.io/summary/new_code?id=PowerGridModel_power-grid-model)
Expand All @@ -22,6 +23,8 @@ SPDX-License-Identifier: MPL-2.0
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=PowerGridModel_power-grid-model&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=PowerGridModel_power-grid-model)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=PowerGridModel_power-grid-model&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=PowerGridModel_power-grid-model)

[![Nightly build](https://github.com/PowerGridModel/power-grid-model/actions/workflows/nightly.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model/actions/workflows/nightly.yml)

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8054429.svg)](https://zenodo.org/record/8054429)

[![](https://github.com/PowerGridModel/.github/blob/main/artwork/svg/color.svg)](#)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ template <dataset_type_tag dataset_type_> class Dataset {
for (Idx i{}; i != n_components(); ++i) {
auto const& buffer = get_buffer(i);
auto const& component_info = get_component_info(i);
Idx size = component_info.elements_per_scenario >= 0
? component_info.elements_per_scenario
: buffer.indptr[scenario + 1] - buffer.indptr[scenario];
Idx offset = component_info.elements_per_scenario >= 0 ? size * scenario : buffer.indptr[scenario];
Idx const size = component_info.elements_per_scenario >= 0
? component_info.elements_per_scenario
: buffer.indptr[scenario + 1] - buffer.indptr[scenario];
Idx const offset = component_info.elements_per_scenario >= 0 ? size * scenario : buffer.indptr[scenario];
if (is_columnar(buffer)) {
result.add_buffer(component_info.component->name, size, size, nullptr, nullptr);
for (auto const& attribute_buffer : buffer.attributes) {
Expand Down
8 changes: 4 additions & 4 deletions tests/cpp_integration_tests/test_main_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ TEST_CASE("Test main model - incomplete input") {

SUBCASE("Symmetrical - Incomplete") {
MutableDataset test_result_data{true, 1, "sym_output", meta_data::meta_data_gen::meta_data};
MutableDataset ref_result_data{true, 1, "sym_output", meta_data::meta_data_gen::meta_data};
MutableDataset const ref_result_data{true, 1, "sym_output", meta_data::meta_data_gen::meta_data};

std::vector<NodeOutput<symmetric_t>> test_sym_node(state.sym_node.size());
test_result_data.add_buffer("node", test_sym_node.size(), test_sym_node.size(), nullptr, test_sym_node.data());
Expand All @@ -1565,7 +1565,7 @@ TEST_CASE("Test main model - incomplete input") {
SparseMatrixError);
}
SUBCASE("Empty update dataset") {
ConstDataset update_data{false, 1, "update", meta_data::meta_data_gen::meta_data};
ConstDataset const update_data{false, 1, "update", meta_data::meta_data_gen::meta_data};

CHECK_THROWS_AS(test_model.calculate({.calculation_type = power_flow,
.calculation_symmetry = symmetric,
Expand All @@ -1588,7 +1588,7 @@ TEST_CASE("Test main model - incomplete input") {

SUBCASE("Asymmetrical - Incomplete") {
MutableDataset test_result_data{true, 1, "asym_output", meta_data::meta_data_gen::meta_data};
MutableDataset ref_result_data{true, 1, "asym_output", meta_data::meta_data_gen::meta_data};
MutableDataset const ref_result_data{true, 1, "asym_output", meta_data::meta_data_gen::meta_data};

std::vector<NodeOutput<asymmetric_t>> test_sym_node(state.sym_node.size());
test_result_data.add_buffer("node", test_sym_node.size(), test_sym_node.size(), nullptr, test_sym_node.data());
Expand All @@ -1603,7 +1603,7 @@ TEST_CASE("Test main model - incomplete input") {
SparseMatrixError);
}
SUBCASE("Empty update dataset") {
ConstDataset update_data{false, 1, "update", meta_data::meta_data_gen::meta_data};
ConstDataset const update_data{false, 1, "update", meta_data::meta_data_gen::meta_data};

CHECK_THROWS_AS(test_model.calculate({.calculation_type = power_flow,
.calculation_symmetry = asymmetric,
Expand Down
12 changes: 6 additions & 6 deletions tests/cpp_unit_tests/test_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace test {
namespace {
template <typename DatasetType>
DatasetType create_dataset(bool const is_batch, Idx const batch_size, MetaDataset const& dataset_type) {
auto const dataset = DatasetType{is_batch, batch_size, dataset_type.name, test_meta_data_all};
auto dataset = DatasetType{is_batch, batch_size, dataset_type.name, test_meta_data_all};
CHECK(&dataset.meta_data() == static_cast<MetaData const*>(&test_meta_data_all));
CHECK(dataset.empty());
CHECK(dataset.is_batch() == is_batch);
Expand Down Expand Up @@ -247,7 +247,7 @@ TEST_CASE_TEMPLATE("Test range object", RangeObjectType, const_range_object<A::I
SUBCASE("Write access") {
A::InputType const new_values{.id = 20, .a0 = -10.0, .a1 = nan};
A::InputType const expected{.id = new_values.id, .a0 = nan, .a1 = new_values.a1};
Idx size = range_object.size();
Idx const size = range_object.size();
for (Idx idx = 0; idx < size; ++idx) {
check_buffer(range_object);
range_object[idx] = new_values;
Expand Down Expand Up @@ -773,7 +773,7 @@ TEST_CASE_TEMPLATE("Test dataset (common)", DatasetType, ConstDataset, MutableDa
if constexpr (!std::same_as<DatasetType, ConstDataset>) {
auto buffer_span =
dataset.template get_columnar_buffer_span<input_getter_s, A>(scenario);
Idx size = buffer_span.size();
Idx const size = buffer_span.size();
for (Idx idx = 0; idx < size; ++idx) {
buffer_span[idx] = A::InputType{.id = -10, .a0 = -1.0, .a1 = -2.0};
CHECK(id_buffer[idx + (scenario * elements_per_scenario)] == -10);
Expand Down Expand Up @@ -930,7 +930,7 @@ TEST_CASE_TEMPLATE("Test dataset (common)", DatasetType, ConstDataset, MutableDa
if constexpr (!std::same_as<DatasetType, ConstDataset>) {
auto buffer_span =
dataset.template get_columnar_buffer_span<input_getter_s, A>(scenario);
Idx size = buffer_span.size();
Idx const size = buffer_span.size();
for (Idx idx = 0; idx < size; ++idx) {
buffer_span[idx] = A::InputType{.id = -10, .a0 = -1.0, .a1 = -2.0};
CHECK(id_buffer[idx + (a_indptr[scenario])] == -10);
Expand Down Expand Up @@ -976,8 +976,8 @@ TEST_CASE_TEMPLATE("Test dataset (common)", DatasetType, ConstDataset, MutableDa
auto const& dataset_type = test_meta_data_all.datasets.front();
CAPTURE(std::string_view{dataset_type.name});

auto const batch_size = 2;
auto const a_elements_per_scenario = 3;
Idx const batch_size{2};
Idx const a_elements_per_scenario{3};

auto dataset = create_dataset(true, batch_size, dataset_type);

Expand Down
4 changes: 2 additions & 2 deletions tests/cpp_unit_tests/test_index_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_CASE("Test dense mapping - comparison sort") {
constexpr Idx count{10};
constexpr Idx n_B = 100000;

double decrement = static_cast<double>(n_B) / count;
double const decrement = static_cast<double>(n_B) / count;

IdxVector idx_B_in_A(count);
for (Idx i = 0; i < count; ++i) {
Expand Down Expand Up @@ -51,7 +51,7 @@ TEST_CASE("Test dense mapping - counting sort") {
constexpr Idx count{1000000};
constexpr Idx n_B = 10;

double decrement = static_cast<double>(n_B) / count;
double const decrement = static_cast<double>(n_B) / count;

IdxVector idx_B_in_A(count);
for (Idx i = 0; i < count; ++i) {
Expand Down
1 change: 0 additions & 1 deletion tests/cpp_unit_tests/test_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace power_grid_model::optimizer::test {
namespace {
namespace meta_gen = meta_data::meta_data_gen;
constexpr auto meta_data = meta_data::meta_data_gen::get_meta_data<
ComponentList<Line, Link, Node, Transformer, ThreeWindingTransformer, TransformerTapRegulator, Source>,
meta_data::update_getter_s>::value;
Expand Down
3 changes: 3 additions & 0 deletions tests/cpp_unit_tests/test_optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ struct StubTransformer {
using SideType = StubTransformerSideType;

static constexpr auto name = "StubTransformer";

// NOLINTBEGIN(readability-convert-member-functions-to-static) // because it stubs non-static member functions
constexpr auto math_model_type() const { return ComponentType::test; }

constexpr auto id() const { return ID{}; }
Expand All @@ -41,6 +43,7 @@ struct StubTransformer {

constexpr auto update(UpdateType const& /* update */) const { return UpdateChange{}; }
constexpr auto inverse(UpdateType /* update */) const { return UpdateType{}; }
// NOLINTEND(readability-convert-member-functions-to-static)
};
struct StubTransformerA : public StubTransformer {};
struct StubTransformerB : public StubTransformer {};
Expand Down
Loading
Loading