From 66db28d1d0daa17965434d287ee578051b499b39 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:22:29 -0400 Subject: [PATCH] Update to the latest C++ linting configs and process from yscope-dev-utils; Forcibly enable CMAKE_EXPORT_COMPILE_COMMANDs. --- .gitignore | 4 + CMakeLists.txt | 22 +++-- README.md | 9 ++- lint-tasks.yml | 3 + src/clp_ffi_js/.clang-format | 151 +---------------------------------- src/clp_ffi_js/.clang-tidy | 133 ------------------------------ tools/yscope-dev-utils | 2 +- 7 files changed, 27 insertions(+), 297 deletions(-) delete mode 100644 src/clp_ffi_js/.clang-tidy diff --git a/.gitignore b/.gitignore index 87a7be42..43f8250f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ build cmake-build-* dist +# Generated lint configs +.clang-format +.clang-tidy + # IDEs .idea .vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index a4b55372..f394d9c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,19 +26,15 @@ if(NOT CMAKE_GENERATOR MATCHES "Unix Makefiles") ) endif() -# Enable compile commands by default if the generator supports it. -if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) - set(CMAKE_EXPORT_COMPILE_COMMANDS - ON - CACHE BOOL - "Enable/Disable output of compile commands during generation." - FORCE - ) -endif() -if(CMAKE_EXPORT_COMPILE_COMMANDS) - # Disable response files since `clang-tidy` doesn't seem to be able to use them - set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF) -endif() +# Enable compile commands +set(CMAKE_EXPORT_COMPILE_COMMANDS + ON + CACHE BOOL + "Enable/Disable output of compile commands during generation." + FORCE +) +# Disable response files since `clang-tidy` doesn't seem to be able to use them +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF) # Set the default build type to Release if not specified if(NOT CMAKE_BUILD_TYPE) diff --git a/README.md b/README.md index 40e7dbfa..173d157d 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,18 @@ task clean Follow the steps below to develop and contribute to the project. ## Set up -Before opening the project in an IDE, you'll first need to download and install [emscripten]: +Before opening the project in an IDE, run the commands below. + +Download and install [emscripten]: ```shell task emscripten ``` +Set up the config files for our C++ linting tools: +```shell +task lint:cpp-configs +``` + ## Linting Before submitting a pull request, ensure you’ve run the linting commands below and either fixed any violations or suppressed the warning. diff --git a/lint-tasks.yml b/lint-tasks.yml index 57e1392c..e5ef8100 100644 --- a/lint-tasks.yml +++ b/lint-tasks.yml @@ -12,6 +12,9 @@ tasks: cmds: - task: "yml-fix" + cpp-configs: + cmd: "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/symlink-cpp-lint-configs.sh" + yml: aliases: - "yml-check" diff --git a/src/clp_ffi_js/.clang-format b/src/clp_ffi_js/.clang-format index f494be90..00a39854 100644 --- a/src/clp_ffi_js/.clang-format +++ b/src/clp_ffi_js/.clang-format @@ -1,75 +1,5 @@ -# yamllint disable-line rule:document-start ---- -ColumnLimit: 100 -IndentWidth: 4 -# yamllint disable-line rule:document-start ---- -Language: "Cpp" -AccessModifierOffset: -4 -AlignAfterOpenBracket: "BlockIndent" -AlignArrayOfStructures: "None" -AlignConsecutiveAssignments: "None" -AlignConsecutiveBitFields: "None" -AlignConsecutiveDeclarations: "None" -AlignConsecutiveMacros: "None" -AlignEscapedNewlines: "DontAlign" -AlignOperands: "Align" -AlignTrailingComments: - Kind: "Never" -AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowBreakBeforeNoexceptSpecifier: "OnlyWithParen" -AllowShortBlocksOnASingleLine: "Always" -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: "Inline" -AllowShortIfStatementsOnASingleLine: "Never" -AllowShortLambdasOnASingleLine: "All" -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: "None" -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: "Yes" -BinPackArguments: false -BinPackParameters: false -BitFieldColonSpacing: "Both" -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: "MultiLine" - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterExternBlock: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyNamespace: false - SplitEmptyRecord: false -BreakAfterAttributes: "Never" -BreakBeforeBinaryOperators: "All" -BreakBeforeBraces: "Custom" -BreakBeforeConceptDeclarations: "Always" -BreakBeforeInlineASMColon: "OnlyMultiline" -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: "BeforeColon" -BreakInheritanceList: "BeforeColon" -BreakStringLiterals: true -CompactNamespaces: true -ConstructorInitializerIndentWidth: 8 -ContinuationIndentWidth: 8 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: "Never" -EmptyLineBeforeAccessModifier: "LogicalBlock" -FixNamespaceComments: true -IncludeBlocks: "Regroup" +BasedOnStyle: "InheritParentConfig" + IncludeCategories: # NOTE: A header is grouped by first matching regex # Project headers @@ -87,80 +17,3 @@ IncludeCategories: # C++ standard libraries - Regex: "^<.+>" Priority: 2 -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: true -IndentExternBlock: "Indent" -IndentGotoLabels: false -IndentPPDirectives: "BeforeHash" -IndentRequiresClause: false -IndentWrappedFunctionNames: false -InsertBraces: true -InsertNewlineAtEOF: true -IntegerLiteralSeparator: - Binary: 4 - BinaryMinDigits: 4 - Decimal: 3 - DecimalMinDigits: 5 - Hex: 4 - HexMinDigits: 4 -KeepEmptyLinesAtTheStartOfBlocks: false -LambdaBodyIndentation: "Signature" -LineEnding: "LF" -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: "None" -PPIndentWidth: -1 -PackConstructorInitializers: "CurrentLine" -PenaltyBreakOpenParenthesis: 25 -PenaltyBreakBeforeFirstCallParameter: 25 -PenaltyReturnTypeOnItsOwnLine: 100 -PointerAlignment: "Left" -QualifierAlignment: "Custom" -QualifierOrder: - - "static" - - "friend" - - "inline" - # constexpr west as explained in https://www.youtube.com/watch?v=z6s6bacI424 - - "constexpr" - - "type" - - "const" - - "volatile" -ReferenceAlignment: "Pointer" -ReflowComments: true -RemoveBracesLLVM: false -RemoveSemicolon: true -RequiresClausePosition: "OwnLine" -RequiresExpressionIndentation: "OuterScope" -SeparateDefinitionBlocks: "Always" -ShortNamespaceLines: 0 -SortIncludes: "CaseInsensitive" -SortUsingDeclarations: "Lexicographic" -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: "Default" -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: "ControlStatements" -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInContainerLiterals: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: "Custom" -SpacesInParensOptions: - InConditionalStatements: false - InCStyleCasts: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: "Latest" -TabWidth: 4 -UseTab: "Never" diff --git a/src/clp_ffi_js/.clang-tidy b/src/clp_ffi_js/.clang-tidy deleted file mode 100644 index 7dc56833..00000000 --- a/src/clp_ffi_js/.clang-tidy +++ /dev/null @@ -1,133 +0,0 @@ -FormatStyle: "file" -WarningsAsErrors: "*" - -# Disabled checks: -# - `bugprone-easily-swappable-parameters` because it's difficult to mitigate. -# - `readability-identifier-length` because it's case-dependent. -# - `readability-named-parameter` because we don't want to enforce that all parameters have a name. -# - `readability-simplify-boolean-expr` because changing `false == x` to `!x` violates our style -# guide. -Checks: >- - bugprone-*, - -bugprone-easily-swappable-parameters, - cert-*, - clang-analyzer-*, - clang-diagnostic-*, - concurrency-*, - cppcoreguidelines-*, - misc-*, - modernize-*, - performance-*, - portability-*, - readability-*, - -readability-identifier-length, - -readability-named-parameter, - -readability-simplify-boolean-expr, - -CheckOptions: - # This is necessary to allow simple classes (with all members being public) that have a - # constructor - misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true - - # NOTE: In the naming rules below, a rule may imply another (e.g., `ClassCase` seems to imply - # `AbstractClassCase`), so ideally we'd only specify the parent rule if we didn't need to - # customize the child rules. However, these relationships aren't documented, so we can't rely on - # them. Instead, we explicitly specify all rules (except those that should have reasonable - # defaults, e.g., `""` for `ClassPrefix`). - - # Macro naming rules - readability-identifier-naming.MacroDefinitionCase: "UPPER_CASE" - - # Namespace naming rules - readability-identifier-naming.NamespaceCase: "lower_case" - readability-identifier-naming.InlineNamespaceCase: "lower_case" - - # Type naming rules - readability-identifier-naming.TypeAliasCase: "CamelCase" - readability-identifier-naming.TypeAliasIgnoredRegexp: "[0-9a-z_]+_t" - readability-identifier-naming.TypedefCase: "CamelCase" - readability-identifier-naming.TypedefIgnoredRegexp: "[0-9a-z_]+_t" - readability-identifier-naming.TypeTemplateParameterCase: "CamelCase" - readability-identifier-naming.TypeTemplateParameterIgnoredRegexp: "[0-9a-z_]+_t" - - # Concept naming rules - readability-identifier-naming.ConceptCase: "CamelCase" - - # Union naming rules - readability-identifier-naming.UnionCase: "CamelCase" - - # Enum naming rules - readability-identifier-naming.EnumCase: "CamelCase" - readability-identifier-naming.EnumConstantCase: "CamelCase" - readability-identifier-naming.ScopedEnumConstantCase: "CamelCase" - - # Class naming rules - readability-identifier-naming.AbstractClassCase: "CamelCase" - readability-identifier-naming.ClassCase: "CamelCase" - readability-identifier-naming.StructCase: "CamelCase" - - # Function naming rules - readability-identifier-naming.ClassMethodCase: "lower_case" - readability-identifier-naming.ConstexprFunctionCase: "lower_case" - readability-identifier-naming.ConstexprMethodCase: "lower_case" - readability-identifier-naming.FunctionCase: "lower_case" - readability-identifier-naming.GlobalFunctionCase: "lower_case" - readability-identifier-naming.MethodCase: "lower_case" - readability-identifier-naming.PrivateMethodCase: "lower_case" - readability-identifier-naming.ProtectedMethodCase: "lower_case" - readability-identifier-naming.PublicMethodCase: "lower_case" - readability-identifier-naming.VirtualMethodCase: "lower_case" - - # Parameter naming rules - readability-identifier-naming.ParameterCase: "lower_case" - readability-identifier-naming.ParameterPackCase: "lower_case" - readability-identifier-naming.PointerParameterCase: "lower_case" - readability-identifier-naming.TemplateParameterCase: "lower_case" - readability-identifier-naming.TemplateTemplateParameterCase: "lower_case" - readability-identifier-naming.ValueTemplateParameterCase: "lower_case" - - # Constexpr naming rules - readability-identifier-naming.ConstexprVariableCase: "CamelCase" - readability-identifier-naming.ConstexprVariablePrefix: "c" - - # Constant naming rules - readability-identifier-naming.ClassConstantCase: "CamelCase" - readability-identifier-naming.ClassConstantPrefix: "c" - readability-identifier-naming.ConstantCase: "CamelCase" - readability-identifier-naming.ConstantPrefix: "c" - readability-identifier-naming.GlobalConstantCase: "CamelCase" - readability-identifier-naming.GlobalConstantPrefix: "c" - readability-identifier-naming.GlobalConstantPointerCase: "CamelCase" - readability-identifier-naming.GlobalConstantPointerPrefix: "c" - readability-identifier-naming.StaticConstantCase: "CamelCase" - readability-identifier-naming.StaticConstantPrefix: "c" - - # Naming rules for constants that can be determined at runtime - readability-identifier-naming.ConstantMemberCase: "lower_case" - # NOTE: We set this to ensure it doesn't default to `MemberPrefix` - readability-identifier-naming.ConstantMemberPrefix: "" - readability-identifier-naming.ConstantParameterCase: "lower_case" - readability-identifier-naming.ConstantPointerParameterCase: "lower_case" - readability-identifier-naming.LocalConstantCase: "lower_case" - readability-identifier-naming.LocalConstantPointerCase: "lower_case" - - # Class member naming rules - readability-identifier-naming.ClassMemberCase: "lower_case" - # NOTE: We set this in case it doesn't default to `MemberPrefix` - readability-identifier-naming.ClassMemberPrefix: "m_" - readability-identifier-naming.MemberCase: "lower_case" - readability-identifier-naming.MemberPrefix: "m_" - readability-identifier-naming.PrivateMemberCase: "lower_case" - readability-identifier-naming.PrivateMemberPrefix: "m_" - readability-identifier-naming.ProtectedMemberCase: "lower_case" - readability-identifier-naming.ProtectedMemberPrefix: "m_" - readability-identifier-naming.PublicMemberCase: "lower_case" - readability-identifier-naming.PublicMemberPrefix: "" - - # Variable naming rules - readability-identifier-naming.GlobalPointerCase: "lower_case" - readability-identifier-naming.GlobalVariableCase: "lower_case" - readability-identifier-naming.LocalPointerCase: "lower_case" - readability-identifier-naming.LocalVariableCase: "lower_case" - readability-identifier-naming.StaticVariableCase: "lower_case" - readability-identifier-naming.VariableCase: "lower_case" diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index 92cd10da..159768c7 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit 92cd10da59a6c2fa5c5182ff7ca0c3d7862a7113 +Subproject commit 159768c7d171595ed2cba17b758c10043a2efe96