Skip to content
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

Introduce basic linting infrastructure #34

Merged
merged 29 commits into from
Oct 15, 2024

Conversation

wusatosi
Copy link
Contributor

@wusatosi wusatosi commented Sep 27, 2024

Introduce pre-commit based linting infrastructure:

  • pre-commit formats extra white space, extra line at end-of-file, C++ files, and CMake files. It flags linting error for Markdown.
  • CI does not push formatted change to pr/ main branch.
  • Pre-commit is portable (even with clang-format) and does not pollute global scope, thus no virtual environment facing files (like requirements.txt) is included. This is tested with an empty GitHub Codespace.

Action Items:

Reference implementation: beman-project/optional26#52

  • Note that this PR diverges with reference implementation greatly:
  • There's less "hooks" (linting rules)
  • Uses different & updated tool chains
  • The .clang-format is copied from Optional 26 & net29 with no modification.

Closes: #29 .

@@ -27,16 +27,14 @@ namespace beman::exemplar {
struct __is_transparent; // not defined

// A function object that returns its argument unchanged.
struct identity
{
struct identity {
// Returns `t`.
template <class T>
#if defined(__cpp_constexpr)

Choose a reason for hiding this comment

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

I realize this is just a formatting PR, but I'm wondering if we actually need this macro for Beman? This would imply support for something prior to c++11 which really isn't our aim here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is a formatting pr! I am just presenting a preview of the formatting that is going to be adopted.

This is a good point! There's also a macro test for __cpp_lib_transparent_operators at testing implying C++14.

Choose a reason for hiding this comment

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

yes, well I guess I could see some library want c++14 support, but 98 -- not really. I suggest we move the macro at 33 as a drive by fix on this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair! After the weekly sync yesterday I think I will expand the scope of this pr out to be "Introduce general pre-commit + linting", haven't got around to updating the title and description, so I will need to work on this for a bit, I will open a separate pr specifically deleting this line.

Choose a reason for hiding this comment

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

Ok I'm good with that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this implies C++14 as std::forward is constexpr after C++14 and (I don't think) constexpr can call non-constexpr function in 11.

Choose a reason for hiding this comment

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

As another note you'll see in optional26 PR the unadorned use of constexpr https://github.com/beman-project/optional26/pull/64/files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unadorned, cool new vocab for me!

I think I will actually hold creating a pr regarding this in hope of clang-tidy flagging it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May be bundled into #38

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix in #55

@wusatosi wusatosi changed the title Introduce clang-format Introduce basic linting infrastructure Oct 1, 2024
.cmake-format.json Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@wusatosi
Copy link
Contributor Author

wusatosi commented Oct 2, 2024

For CI I have a strong preference for not having the linter make changes. Most of them make mistakes. clang-format is a rare exception, and even it can produce nonsense on language forms it doesn't understand yet.

Current CI does not push format changes to pr/ main branch, I would be interested in putting auto clang-format in but that's out of the scope of this PR.

@wusatosi
Copy link
Contributor Author

wusatosi commented Oct 2, 2024

Besides updating README, all configuration should be done. Opening for comments and reviews.

@wusatosi wusatosi marked this pull request as ready for review October 2, 2024 18:50
Copy link
Contributor

@camio camio left a comment

Choose a reason for hiding this comment

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

This PR looks great to me.

I've used markdownlint-cli in the past and it worked well. It's the first time I've used gersemi to format CMake and while the output was surprising in a couple instances, the fact it is automated overshadows this.

I think this should be merged and our style czar @JeffGarland can provide an improved .clang-format later.

Our README.md should include instructions on pre-commit, but it should be clear that this is only for developers intending to make changes to this repository (those building for use elsewhere don't need it). The Carbon pre-commit instructions are fairly decent.

@wusatosi, let me know if you want me to merge this now (and leave documentation to another PR) or if I should hold off.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
@wusatosi

This comment has been minimized.

Copy link
Member

@steve-downey steve-downey left a comment

Choose a reason for hiding this comment

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

👍

And I'd like to apply some of this to optional26 as well, soon.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
@wusatosi
Copy link
Contributor Author

wusatosi commented Oct 14, 2024

Weird, pr actions are not triggered anymore. GitHub must be down or smt

GitHub was being GitHub...

@wusatosi
Copy link
Contributor Author

I don't think pre-commit's action's caching is working.
I have never seen it reuse the previous environment (always cache-miss).
I will keep an eye on this after the pr is merged and file an issue upstream later if needed.

@wusatosi
Copy link
Contributor Author

@camio This pr is ready to merge now, I don't want to block progress of #46 as we have overlapping config file.

I can file a separate pr to add documentation.

Copy link
Member

@steve-downey steve-downey left a comment

Choose a reason for hiding this comment

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

+1

@camio camio merged commit bd7ad35 into beman-project:main Oct 15, 2024
15 checks passed
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.

Define .clang-format or equivalent
5 participants