Skip to content

style(clang-tidy): Clean include headers of src/core/jsonschema #1650

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bavulapati
Copy link
Contributor

Reported by clang-tidy check misc-include-cleaner
Refs: sourcemeta/blaze#429

@bavulapati
Copy link
Contributor Author

These changes are getting bigger when I consider one folder at a time

@bavulapati
Copy link
Contributor Author

@jviotti PTAL

bavulapati and others added 3 commits May 23, 2025 19:24
Reported by clang-tidy check misc-include-cleaner
Refs: sourcemeta/blaze#429

Signed-off-by: Balakrishna Avulapati <[email protected]>
Co-authored-by: Juan Cruz Viotti <[email protected]>
Signed-off-by: Balakrishna Avulapati <[email protected]>
Signed-off-by: Balakrishna Avulapati <[email protected]>
@bavulapati bavulapati force-pushed the include-src-core-jsonschema branch from 94df2c3 to c5b3460 Compare May 23, 2025 13:56
Signed-off-by: Balakrishna Avulapati <[email protected]>
Signed-off-by: Balakrishna Avulapati <[email protected]>
Ref: https://github.com/sourcemeta/core/pull/1650/files#r2104799191

"Essentially, for a header X.h, then don't clean its X_<private>.h includes"

Signed-off-by: Balakrishna Avulapati <[email protected]>
@bavulapati
Copy link
Contributor Author

@jviotti addressed it. PTAL
I'll send a separate PR for all the other modules

@bavulapati
Copy link
Contributor Author

@jviotti Consider a public header like json.h, it includes a bunch of private headers like json_error.h, json_value.h.

What do you think about making json.h complete, having all the declarations of it's private headers?
In modules, there is a concept of re-export. If a module B is imported into module A, module A can re export the imported module A.
That would make the consumer(dev) to just have the knowledge of a single header, instead of going through chain of modules?

@bavulapati
Copy link
Contributor Author

In our case of clang-tidy, even though the public header json.h is included, the check misc-include-cleaner expects json_error.h to be included, if using a declaration from json-error.h

@jviotti
Copy link
Member

jviotti commented May 23, 2025

What do you think about making json.h complete, having all the declarations of it's private headers?
In modules, there is a concept of re-export. If a module B is imported into module A, module A can re export the imported module A.

The idea of these private headers was to make things a little bit more maintainable. Otherwise these modules often expose a lot of stuff, and the single header file would get huge

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests look off. The tests should not be including jsonschema_error if they already include jsonschema, as that one includes the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned earlier, clang-tidy expects the includes to be direct not transitive

@@ -1,6 +1,8 @@
#include <gtest/gtest.h>

#include <sourcemeta/core/jsonschema.h>
#include <sourcemeta/core/jsonschema_error.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks off too?

#include <sourcemeta/core/jsonschema.h>
#include <sourcemeta/core/jsonschema_walker.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ones too, as jsonschema.h already includes jsonschema_walker.h

@jviotti
Copy link
Member

jviotti commented May 24, 2025

In our case of clang-tidy, even though the public header json.h is included, the check misc-include-cleaner expects json_error.h to be included, if using a declaration from json-error.h

Hmm, well that will be tricky then. This whole part of ClangTidy looks complicated. Let me do some more digging. Maybe we should start with other warnings first?

@jviotti
Copy link
Member

jviotti commented May 24, 2025

Or maybe we can turn of MissingIncludes: https://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html, as that's the one that forces the direct includes?

A boolean that controls whether the check should report missing includes (header files from which symbols are used but which are not directly included).

jviotti added a commit that referenced this pull request May 24, 2025
@jviotti
Copy link
Member

jviotti commented May 24, 2025

See #1685. I think that is enough for now. Maybe worth trying to re-create that PR given the ClangTidy warnings with that new config?

I'll think more about a better solution long term. Maybe C++ modules fixes all of this.

jviotti added a commit that referenced this pull request May 24, 2025
@bavulapati
Copy link
Contributor Author

Hmm, well that will be tricky then. This whole part of ClangTidy looks complicated. Let me do some more digging. Maybe we should start with other warnings first?

Yes, we can try that too.

@bavulapati
Copy link
Contributor Author

See #1685. I think that is enough for now. Maybe worth trying to re-create that PR given the ClangTidy warnings with that new config?

I'll think more about a better solution long term. Maybe C++ modules fixes all of this.

Yeah, C++ modules definitely makes life easier. I thought of adding an issue or TODO to use modules in the future. But I'm wondering, How do we know that the time is right?

bavulapati added a commit to bavulapati/core that referenced this pull request May 24, 2025
bavulapati added a commit to bavulapati/core that referenced this pull request May 24, 2025
@jviotti
Copy link
Member

jviotti commented May 24, 2025

How do we know that the time is right?

I think we'll know once most popular C++ libraries out there support it. So far I haven't seen even a single one. I think it will be a couple of years at least

jviotti pushed a commit that referenced this pull request May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants