Skip to content

Precommit#52

Merged
steve-downey merged 15 commits intobemanproject:mainfrom
steve-downey:precommit
Sep 3, 2024
Merged

Precommit#52
steve-downey merged 15 commits intobemanproject:mainfrom
steve-downey:precommit

Conversation

@steve-downey
Copy link
Member

Add the pre-commit and configurations to run lint checks via the framework, add a GH action for the lint checks, and since most of the infrastructure was now there, add a coverage report to the system. Not hooked to CI, as I couldn't figure out how to grab the resulting report usefully yet.

steve-downey and others added 10 commits August 11, 2024 14:55
Use the pre-commit framework to check cmake, clang-format, spellcheck, git, and
shell scripts.
Also the default install dir.
Spelling, formating, caps, etc.
add the commit that was just lint fixes.
Add gcovr pip install and cmake targets and configurations for running
coverage and collecting and processing the results.
The lint target excludes, e.g. clang-format-fix and clang-tidy.
Make lint, lint-manual, and coverage as not producing a file. Remove targets.mk
as a source for help messages in help target.
No tests were found!!!
```

#### Pre-Commit for Linting
Copy link
Member

Choose a reason for hiding this comment

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

Would you like to move this section outside the root README? It's useful for Beman devs, but not for users.

I would move it into a file docs/dev-lint.md (or whatever).

@@ -0,0 +1,32 @@
cfgv==3.4.0
Copy link
Member

Choose a reason for hiding this comment

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

Is it required to have these files in the repo root? If no, I would create a dev/ directory.

Run a script to install and run pre-commit in a python3 virtual environment and
tweak shellcheckrc to allow the venv activation source as part of the script.

shellcheck...............................................................Passed
Format errors and such,
Suggests that some refactoring is in order, but since this is also testing
shellcheck itself, it's an OK exercise. Since there isn't a venv created in the
CI action that runs shellcheck, it can't read the script to check for issues.
set(CMAKE_CXX_FLAGS_ASAN
"-O3 -g -DNDEBUG -fsanitize=undefined"
CACHE STRING "C++ ASAN Flags" FORCE)

Copy link
Member

@JeffGarland JeffGarland Aug 26, 2024

Choose a reason for hiding this comment

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

I think we should consider having CXX_FLAGS_HARDENED -- have a look at the recommendations here: https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html

Specifically I think these:

-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS

would be relevant. The GLIBCXX one links a version of the standard library that asserts on all preconditions -- I've found bugs in our code base using that one.

@neatudarius
Copy link
Member

@steve-downey , does precommit tool can be used for also applying the linter fixes?

e.g. run precommit args... do detect errors and precommit args... --fix to automatically apply (some) changes.

CC: @camio suggested that we should be able to achieve this behaviour with pre-commit, as per my understanding.

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# shellcheck disable=SC1091
Copy link
Member

Choose a reason for hiding this comment

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

Should we move it in .shellcheck rc?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm undecided. I thought about it, but it would also allow a class of real errors to slip by?

#!/usr/bin/env bash
# shellcheck disable=SC1091

python3 -m venv .venv
Copy link
Member

Choose a reason for hiding this comment

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

Should we add small doc in docs/?

Copy link
Member Author

Choose a reason for hiding this comment

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

Writing is hard. I put it off until we'd agreed this was a promising direction. I'll add a doc now.

@steve-downey
Copy link
Member Author

@steve-downey , does precommit tool can be used for also applying the linter fixes?

e.g. run precommit args... do detect errors and precommit args... --fix to automatically apply (some) changes.

CC: @camio suggested that we should be able to achieve this behaviour with pre-commit, as per my understanding.

Applying fix-ups is a dependent on the tool being applied and usually the arguments to the tool. I've started with just checks by default and no automatic fixes. There is configured a clang-format fix that will apply changes, in addition to the check of changes, and that can be run to make changes, although it's not that much simpler than a find and xargs or -exec clang-format -i {} \;
I've heard that it's also possible for some fixes to be applied in the PR itself, but I haven't sorted how to do that, or if it's a different tool.

`nd`` was flagged as a possible typo, change it as it's not really significant.
Copy link
Member

@neatudarius neatudarius left a comment

Choose a reason for hiding this comment

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

LGTM 👍

What's the plan with this PR? Will you merge it soon?

@steve-downey
Copy link
Member Author

steve-downey commented Sep 3, 2024 via email

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.

3 participants