From 1703b43ff0d13cf907964cfda801c5cb6e505cc6 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Wed, 6 May 2026 15:50:49 -0700 Subject: [PATCH] Apply new consolidated code standard --- .config/clang-format | 68 ---------------------- .config/copyright.txt | 13 ----- .cpplint.cfg | 19 ------ .github/workflows/build.yml | 2 +- .github/workflows/pre-commit.yml | 4 +- .gitignore | 2 + .pre-commit-config.yaml | 99 +++++++------------------------- .ruff.toml | 18 ------ 8 files changed, 25 insertions(+), 200 deletions(-) delete mode 100644 .config/clang-format delete mode 100644 .config/copyright.txt delete mode 100644 .cpplint.cfg delete mode 100644 .ruff.toml diff --git a/.config/clang-format b/.config/clang-format deleted file mode 100644 index 587bc1b..0000000 --- a/.config/clang-format +++ /dev/null @@ -1,68 +0,0 @@ ---- - -# See https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormatStyleOptions.html for documentation of these options -BasedOnStyle: Google -IndentWidth: 2 -ColumnLimit: 120 - -AccessModifierOffset: -2 -AlignAfterOpenBracket: AlwaysBreak -AlignConsecutiveAssignments: None -AlignConsecutiveDeclarations: None -AlignEscapedNewlines: Left -AlignTrailingComments: false -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: Empty -AllowShortFunctionsOnASingleLine: false -BinPackArguments: false -BinPackParameters: false -BraceWrapping: - AfterClass: true - AfterControlStatement: MultiLine - AfterEnum: true - AfterFunction: true - AfterNamespace: true - AfterStruct: true - AfterUnion: true - AfterExternBlock: true - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: false -BreakBeforeBraces: Custom -BreakConstructorInitializers: BeforeComma -CompactNamespaces: false -ContinuationIndentWidth: 2 -ConstructorInitializerIndentWidth: 0 -DerivePointerAlignment: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -FixNamespaceComments: true -IncludeBlocks: Regroup -IncludeCategories: - # Headers in <> with .h extension (best guess at C system headers) - - Regex: '<([A-Za-z0-9\Q/-_\E])+\.h>' - Priority: 1 - # Headers in <> without extension (C++ system headers) - - Regex: '<([A-Za-z0-9\Q/-_\E])+>' - Priority: 2 - # Headers in <> with other extensions. - - Regex: '<([A-Za-z0-9.\Q/-_\E])+>' - Priority: 3 - # Headers in "" - - Regex: '"([A-Za-z0-9.\Q/-_\E])+"' - Priority: 4 -IndentAccessModifiers: false -IndentPPDirectives: BeforeHash -PackConstructorInitializers: Never -PointerAlignment: Middle -ReferenceAlignment: Middle -ReflowComments: false -SeparateDefinitionBlocks: Always -SortIncludes: CaseInsensitive -SpacesBeforeTrailingComments: 2 diff --git a/.config/copyright.txt b/.config/copyright.txt deleted file mode 100644 index a617e4a..0000000 --- a/.config/copyright.txt +++ /dev/null @@ -1,13 +0,0 @@ -Copyright (c) 2025-present Polymath Robotics, Inc. All rights reserved - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/.cpplint.cfg b/.cpplint.cfg deleted file mode 100644 index 8f355ec..0000000 --- a/.cpplint.cfg +++ /dev/null @@ -1,19 +0,0 @@ -# Because of cpplint's config file assumptions, this can't be contained in .config/ directory -linelength=256 - -# TODO(emerson) we need to apply a copyright check, maybe not via this tool though -filter=-legal/copyright -# TODO(emerson) we want these, but the style as enforced here is probably not quite right for us -filter=-build/header_guard -filter=-build/c++17 - -# Per our style guide, we want to allow the use of non-const reference passing for output parameters -filter=-runtime/references - -# Disable all formatting checks, this is handled by clang-format -filter=-readability/braces -filter=-whitespace/braces -filter=-whitespace/indent -filter=-whitespace/newline -filter=-whitespace/parens -filter=-whitespace/semicolon diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17aa5af..9c646f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ --- name: Build and test -"on": +on: pull_request: push: branches: diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 093bf31..7756265 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,7 +1,7 @@ --- name: pre-commit -"on": +on: pull_request: push: branches: [main] @@ -13,6 +13,6 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: '3.10' - run: sudo apt-get update && sudo apt-get install libxml2-utils - uses: pre-commit/action@v3.0.1 diff --git a/.gitignore b/.gitignore index ce0d030..b1c4a98 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /build/ /install/ /log/ + +/.ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 267768c..822911e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,81 +1,22 @@ --- -# See https://pre-commit.com for more information on these settings + repos: - # Generally useful checks provided by pre-commit - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - - id: check-added-large-files - - id: check-ast - - id: check-case-conflict - - id: check-merge-conflict - - id: check-shebang-scripts-are-executable - - id: check-symlinks - - id: check-toml - - id: check-xml - - id: end-of-file-fixer - - id: forbid-submodules - - id: mixed-line-ending - - id: trailing-whitespace - # Python - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.5 - hooks: - - id: ruff-format - - id: ruff - args: [--fix] - # C++ formatting - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v19.1.7 - hooks: - - id: clang-format - args: ["--style=file:.config/clang-format"] - # C++ linting - - repo: https://github.com/cpplint/cpplint - rev: 2.0.0 - hooks: - - id: cpplint - args: ["--config=.cpplint.cfg", --quiet, --output=sed] - # Markdown - - repo: https://github.com/jackdewinter/pymarkdown - rev: v0.9.28 - hooks: - - id: pymarkdown - args: [-d, MD013, fix] - # XML - - repo: https://github.com/emersonknapp/ament_xmllint - rev: v0.1 - hooks: - - id: ament_xmllint - # YAML - - repo: https://github.com/adrienverge/yamllint.git - rev: v1.29.0 - hooks: - - id: yamllint - args: [-d, "{extends: default, rules: {line-length: {max: 256}, commas: false}}"] - # CMake - - repo: https://github.com/cmake-lint/cmake-lint - rev: 1.4.3 - hooks: - - id: cmakelint - args: [--linelength=140] - - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.5 - hooks: - - id: insert-license - types_or: [python, cmake, shell] - name: Copyright headers for Python/CMake - args: [ - --license-filepath, .config/copyright.txt, - --comment-style, '#', - --allow-past-years, - --no-extra-eol, - ] - - id: insert-license - types_or: [c++, c] - name: Copyright headers for C/C++ - args: [ - --license-filepath, .config/copyright.txt, - --comment-style, '//', - --allow-past-years, - ] + - repo: https://github.com/polymathrobotics/polymath_code_standard + rev: v2.1.2 + hooks: + # Basic checks and fixes that apply to any text file and the git repository itself + - id: polymath-general + # Enforce and insert copyright headers in source code for the project's license + - id: polymath-copyright + args: [--license, Apache-2.0, --wildcard-copyright-org] + # Specific languages + - id: polymath-python + - id: polymath-cpp + - id: polymath-shell + - id: polymath-cmake + - id: polymath-docker + - id: polymath-markdown + - id: polymath-xml + - id: polymath-yaml + - id: polymath-toml + - id: polymath-json diff --git a/.ruff.toml b/.ruff.toml deleted file mode 100644 index c39e694..0000000 --- a/.ruff.toml +++ /dev/null @@ -1,18 +0,0 @@ -line-length = 120 -indent-width = 4 - -[format] -preview = true -quote-style = "single" -indent-style = "space" -skip-magic-trailing-comma = false -line-ending = "lf" - -[lint] -select = ["E4", "E7", "E9", "F", "I"] -# Rules intended for future application -# select = ["N", "D", "C90", "PTH", "UP", "PERF", "RUF"] -ignore = [] -fixable = ["ALL"] -unfixable = [] -dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"