Repository navigation
Conversation
Enforces the parts of the Google C++ Style Guide (https://google.github.io/styleguide/cppguide.html) that GTSAM's own stated convention builds on (.github/copilot-instructions.md: "Classes and types are UpperCamelCase; methods and functions are lowerCamelCase. [...] Apart from those naming conventions, follow Google C++ style."), on top of the existing clang-tidy-diff.py-based PR gating. .clang-tidy: adds the google-* check family and readability-identifier-naming, scoped to what was empirically validated against a broad sample of real GTSAM files (Pose2, NoiseModel, HessianFactor, LevenbergMarquardtParams/Optimizer, Values, FactorGraph, Key) before committing to it -- several naming categories that looked safe from a quick grep turned out to have pervasive, deliberate real exceptions once checked more broadly, and are intentionally left unenforced rather than fought with suppressions: - function/method/static-method casing: a genuine mix (named- constructor factories are deliberately UpperCamelCase; other methods are a real mix of UpperCamelCase and lowerCamelCase with no mechanical way to tell exception from debt) - parameter/variable casing: short mathematical notation (H, A, R, M, G11-G33) is load-bearing, confirmed in 40+ headers - typedefs/aliases: the nested "typedef shared_ptr<X> shared_ptr;" idiom appears in 140+ headers - template parameters: predominantly UPPER_CASE, not CamelCase - members: private/protected are usually lowerCamelCase_, but real snake_case counter-examples exist in core files - constants: the kCamelCase convention is real, but constant detection also false-positived on non-constant lambda captures Kept: class/struct/enum/union type names (CamelCase), namespaces (lower_case), enum constants (CamelCase, matching current code), and macros (UPPER_CASE) -- the categories with no counter-examples found. google-runtime-references and google-default-arguments are disabled for the same reason (non-const Jacobian out-params and print()'s default argument are pervasive, intentional GTSAM idioms, not oversights). CPPLINT.cfg + scripts/cpplint_diff.py: adds cpplint (Google's own reference linter for the style guide) as a second check, since it catches things clang-tidy's config above doesn't attempt (explicit single-arg constructors, redundant virtual+override, include-what-you- use, namespace-closing comments). cpplint_diff.py mirrors the existing clang-tidy-diff.py-based gating: it filters cpplint's output down to diagnostics on lines actually added in the diff, so this doesn't surface GTSAM's pre-existing style backlog on every PR that happens to touch an old file. Covered by scripts/test_cpplint_diff.py. .github/workflows/code-quality.yml: wires cpplint_diff.py in as a new job alongside the existing clang-tidy one, and widens the existing "Test quality checker" step's discovery pattern from the single hardcoded test_code_quality.py to test_*.py so new test files (like test_cpplint_diff.py) are picked up automatically. The cpplint job's diff-identification step mirrors clang-tidy's push/PR/nightly-aware base resolution (rebased on top of "Gate PR and nightly CI on both code-quality checks", which turned this workflow into a workflow_call callee and replaced clang-tidy's old "HEAD^1 HEAD" PR-only diffing with logic that also handles develop pushes and nightly runs correctly); cpplint now gets the same treatment instead of keeping the old PR-only assumption. All of the above was validated against this repo before committing: ran the real pinned clang-tidy (23.1.4) and cpplint (2.0.2) versions against real compile_commands.json output and real files, including an end-to-end smoke test of the diff-filtering pipeline with a synthetic violation, and the full existing + new Python test suite. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
PR CI's new cpplint job (code-quality.yml) had no local-terminal equivalent, unlike the existing "Opt-in local Clang-Tidy" section -- a developer had to either wait for CI or manually re-derive the cpplint_diff.py invocation. Adds a matching "Opt-in local cpplint" section with the same structure: install the pinned tool version, then run scripts/cpplint_diff.py against the merge-base diff with origin/develop, exactly like CI does. Unlike Clang-Tidy this needs no compilation database, so setup is just a pip install. Verified end-to-end with a synthetic violation (single-arg constructor not marked explicit): the documented command found exactly that one finding, confirming the diff-scoping stays correct outside of CI too. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Per explicit direction: enforce naming uniformly going forward rather than carving out permanent exceptions for every category that doesn't fully conform yet. This WILL surface real failures once a future PR touches a non-conforming line (expected -- this check is diff-scoped, so nothing about the existing codebase fails until it's touched again, and the backlog gets fixed incrementally rather than needing one big retroactive rename pass). Re-enables, with GTSAM's stated conventions as the target: Function/ Method/ClassMethodCase (camelBack), Parameter/VariableCase (camelBack), Typedef/TypeAliasCase (CamelCase), TemplateParameterCase (CamelCase), Private/Protected/PublicMemberCase (camelBack, trailing underscore for private/protected), and Constant/GlobalConstant/StaticConstantCase (kCamelCase). The known, confirmed conflicts documented in the previous commit (named-constructor factories, math-notation parameters, the nested shared_ptr typedef idiom, UPPER_CASE template parameters, snake_case member counter-examples, and constant-detection false positives on lambda captures) are kept as inline documentation -- now framed as an expected follow-up punch list instead of a justification for leaving them off. Verified this PR's own diff (config/docs/scripts only, no C++ source) stays clean under clang-tidy-diff.py and cpplint_diff.py, and confirmed end to end that touching a real pre-existing non-conforming line (e.g. NoiseModel::sqrt_information_) does get flagged as expected through the actual CI mechanism, not just a bare clang-tidy invocation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Member
|
Please add a section in pr description written entirely by you |
Contributor
Author
|
Done |
Three more copilot-instructions.md rules, implemented to the letter regardless of current conformance -- existing violations are either grandfathered nowhere (the full-repo check) or will surface the next time a touched line triggers them (the diff-scoped checks), per explicit direction rather than watered down to match current practice. .clang-tidy: adds readability-function-cognitive-complexity at its default threshold (25), implementing "flag overly complex or long functions and recommend breaking them into smaller functions." Validated against real files before enabling (e.g. flagged LevenbergMarquardtOptimizer::tryLambda at complexity 77) without being so sensitive it flags ordinary functions. scripts/check_code_quality.py (+ its test): adds detection of bare [[deprecated]] attributes, implementing "Use GTSAM's versioned deprecation mechanism rather than adding a standalone [[deprecated]] attribute." This check runs unconditionally over the whole repo (like the rest of this script, unlike the diff-scoped clang-tidy/cpplint jobs), and there currently are 3 real violations across gtsam/base/MatrixLieGroup.h and gtsam/navigation/AttitudeFactor.h -- left as real, unlisted failures (no exception list, unlike this script's existing grandfathered violations) for a follow-up to fix, since this one wasn't carved out. scripts/cpplint_diff.py (+ its test): adds two more GTSAM-specific diff-scoped checks neither clang-tidy nor cpplint cover, implementing "Use /// for single-line documentation comments rather than /** */" (477 existing files don't conform) and "Put at least one short // comment immediately above every TEST() explaining the behavior being verified" (1885 of 3977 existing TEST()s don't). Both are diff-scoped rather than added to check_code_quality.py given that volume -- the full-repo mechanism is reserved for rules with few enough pre-existing violations that failing immediately and unconditionally is reasonable (like the deprecated-attribute rule above); these follow the same incremental-enforcement model as the identifier-naming checks already in .clang-tidy. Also simplified cpplint_diff.py's diff parsing while extending it: instead of hand-walking +/-/context markers to track exact added-line numbers, it now extracts each hunk's (start, end) range straight from the "@@ ... +start,count @@" header, the same way clang-tidy-diff.py (already a dependency) does it. Since this project's documented commands always use "--unified=0" (zero context lines), a hunk's range *is* exactly its added lines here, so this loses no precision while removing the need to classify each line in the diff body. No new CI job, no new local command: everything above runs through the exact same two jobs (clang-tidy, cpplint) and the exact same three documented command lines (clang-tidy-diff.py, cpplint_diff.py, check_code_quality.py) as before. Verified before committing: the full 21-test suite passes; this PR's own diff (still config/scripts only) stays clean under all three mechanisms; deliberately touching real pre-existing violations (a missing-explicit constructor, a single-line Doxygen comment, a TEST() without a comment, in one synthetic file) surfaces findings from all three new checks correctly through the diff-scoped pipeline; and running check_code_quality.py against the real repo surfaces exactly the 3 known [[deprecated]] violations, nothing else. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
copilot-instructions.md, which follows Google's C++ standards, with some additions.You can run the CI checker locally from the command line with:
This is intended to be the first in a set of 3 PRs, which includes linting for
.hand.pyfiles