From f5c43c4fb4cadc968ea15a2daf00a909868dcf85 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 27 Oct 2023 03:02:07 -0700 Subject: [PATCH] initial setup Buildscripts, nix shell, skeleton project --- .clang-format | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ .clang-tidy | 48 +++++++++++++++++++++++++++++ .editorconfig | 12 ++++++++ .gitignore | 10 ++++++ CMakeLists.txt | 25 +++++++++++++++ Justfile | 31 +++++++++++++++++++ README.md | 28 +++++++++++++++++ default.nix | 1 + package.nix | 18 +++++++++++ shell.nix | 13 ++++++++ src/lib.cpp | 16 ++++++++++ 11 files changed, 284 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Justfile create mode 100644 README.md create mode 100644 default.nix create mode 100644 package.nix create mode 100644 shell.nix create mode 100644 src/lib.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..faedbee --- /dev/null +++ b/.clang-format @@ -0,0 +1,82 @@ +AlignArrayOfStructures: None +AlignAfterOpenBracket: BlockIndent +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +BinPackArguments: false +BinPackParameters: false +Cpp11BracedListStyle: true +LambdaBodyIndentation: Signature +UseCRLF: false +UseTab: ForIndentation +SpacesInSquareBrackets: false +SpacesInParentheses: false +SpacesInCStyleCastParentheses: false +SpacesInAngles: Never +SpaceInEmptyParentheses: false +SpaceInEmptyBlock: false +SpaceBeforeSquareBrackets: false +SpaceBeforeRangeBasedForLoopColon: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: false +SpaceBeforeInheritanceColon: false +SpaceBeforeParens: ControlStatementsExceptControlMacros +SortIncludes: CaseSensitive +PointerAlignment: Left +PackConstructorInitializers: NextLine +LineEnding: LF +InsertBraces: false +BreakConstructorInitializers: AfterColon +BreakBeforeBraces: Custom +BreakInheritanceList: AfterColon +AllowAllParametersOfDeclarationOnNextLine: false +AllowAllArgumentsOnNextLine: false +AlwaysBreakTemplateDeclarations: Yes +BraceWrapping: + AfterClass: false + AfterFunction: false + AfterCaseLabel: false + AfterEnum: false + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: false + SplitEmptyNamespace: false + AfterControlStatement: MultiLine +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeTernaryOperators: true +AlignOperands: AlignAfterOperator +InsertTrailingCommas: Wrapped +MaxEmptyLinesToKeep: 1 +ExperimentalAutoDetectBinPacking: false +ColumnLimit: 100 +IndentWidth: 2 +TabWidth: 2 +AllowAllConstructorInitializersOnNextLine: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +NamespaceIndentation: None +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^<(cassert|cctype|cerrno|cfenv|cfloat|cinttypes|climits|clocale|cmath|csetjmp|csignal|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctime|cuchar|cwchar|cwctype|algorithm|any|array|atomic|bitset|chrono|codecvt|complex|condition_variable|deque|exception|filesystem|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|latch|limits|list|locale|map|memory|mutex|new|numeric|optional|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|string_view|strstream|syncstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|variant|vector|version|assert.h|ctype.h|errno.h|fenv.h|float.h|inttypes.h|limits.h|locale.h|math.h|setjmp.h|signal.h|stdarg.h|stddef.h|stdint.h|stdio.h|stdlib.h|string.h|time.h|uchar.h|wchar.h|wctype.h)>$' + Priority: 0 + - Regex: '^<.*>$' + Priority: 1 + - Regex: '^".*"$' + Priority: 2 + - Regex: '.+' + Priority: 3 diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..1e7511c --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,48 @@ +WarningsAsErrors: '*' +HeaderFilterRegex: '.*\.hpp' +FormatStyle: file +Checks: > + -*, + bugprone-*, + concurrency-*, + cppcoreguidelines-*, + -cppcoreguidelines-owning-memory, + google-build-using-namespace. + google-explicit-constructor, + google-global-names-in-headers, + google-readability-casting, + google-runtime-int, + google-runtime-operator, + misc-*, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + modernize-*, + -modernize-return-braced-init-list, + -modernize-use-trailing-return-type, + performance-*, + portability-std-allocator-const, + readability-*, + -readability-function-cognitive-complexity, + -readability-function-size, + -readability-identifier-length, + -readability-magic-numbers, + -readability-uppercase-literal-suffix, + tidyfox-*, +CheckOptions: + performance-for-range-copy.WarnOnAllAutoCopies: true + performance-inefficient-string-concatenation.StrictMode: true + readability-braces-around-statements.ShortStatementLines: 1 + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.ConstantCase: UPPER_CASE + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.FunctionCase: lower_case + readability-identifier-naming.MemberCase: lower_case + readability-identifier-naming.NamespaceCase: lower_case + readability-identifier-naming.LocalConstantCase: lower_case + readability-identifier-naming.MethodCase: lower_case + readability-identifier-naming.ParameterCase: lower_case + readability-identifier-naming.VariableCase: lower_case + + # does not appear to work + readability-operators-representation.BinaryOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^=' + readability-operators-representation.OverloadedOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^=' diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..aac55d0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab + +[{*.nix,.clang-format,.clang-tidy}] +indent_style = space +indent_size = 2 + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..933f686 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# build files +/build +/compile_commands.json + +# clangd +/.cache/ + +# direnv +/.envrc +/.direnv/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0ba271b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.20) +project(tidyfox VERSION "0.0.1") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED YES) + +add_compile_options(-Wall -Wextra) + +# nix workaround +if (CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() + +find_package(Clang REQUIRED) + +add_library(tidyfox MODULE + src/lib.cpp + src/explicit_thisptr.cpp +) + +target_link_libraries(tidyfox PRIVATE clang-tidy) + +if (NOT STREQUAL ${CMAKE_INSTALL_LIBDIR} "") + install(TARGETS tidyfox LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..313dedb --- /dev/null +++ b/Justfile @@ -0,0 +1,31 @@ +fmt: + clang-format -i src/** + +check-format: + clang-format -i src/** --dry-run + +# the lint ends up running over a large amount of llvm surface area and it takes considerably +# longer than the extra build time from using release mode +lint: release + clang-tidy src/** --load=build/release/libtidyfox.so + +build: + cmake -GNinja -B build/debug \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + ln -sf build/debug/compile_commands.json compile_commands.json + cmake --build build/debug + +release: + cmake -GNinja -B build/release \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + cmake --build build/release + +clean: + rm -rf build + rm -f compile_commands.json + +pre-commit: check-format lint diff --git a/README.md b/README.md new file mode 100644 index 0000000..708f985 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# tidyfox +outfoxxed's clang-tidy lint collection. Lints I end up needing will go here. + +# Installation +There is a nix package in `default.nix` which can be used to install tidyfox in `lib/libtidyfox.so`. + +If you aren't running nix, use the provided Justfile. +Run `just release` to make a release build. You must have llvm and clang 16 dev packages in $PATH. (`FindClang.cmake` must exist) + +# Usage +Tidyfox lints are supplied under the `tidyfox-` namespace. Currently there are no lints. +The plugin can be loaded via `clang-tidy -load=/path/to/libtidyfox.so` + +# Contributing +There is a `shell.nix` file which will load all the necessary dependencies. +If not using nix the requirements are the same as in [Installation](#installation) above. + +Run `just build` to create a debug build and a clang compilation database. + +Run `just fmt` to format the sources. + +Run `just lint` to run clang-tidy on tidyfox, with tidyfox itself as a plugin. + +Run `just release` to create a release build. + +Run `just pre-commit` before committing to catch anything. + +When committing, follow [conventional commits](https://www.conventionalcommits.org). diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..717c4ca --- /dev/null +++ b/default.nix @@ -0,0 +1 @@ +{ pkgs ? import {} }: pkgs.callPackage ./package.nix {} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..a7db752 --- /dev/null +++ b/package.nix @@ -0,0 +1,18 @@ +{ cmake, ninja, llvmPackages_16, clang16Stdenv }: +clang16Stdenv.mkDerivation { + pname = "tidyfox"; + version = "0.1.0"; + src = ./.; + + nativeBuildInputs = [ + cmake + ninja + ]; + + buildInputs = with llvmPackages_16; [ + llvm.dev + clang-unwrapped.dev + ]; + + buildPhase = "ninjaBuildPhase"; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..2ef53ed --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +{ pkgs ? import {} }: let + tidyfox = import ./default.nix { inherit pkgs; }; +in pkgs.mkShell.override { + stdenv = tidyfox.stdenv; +} { + name = "tidyfox"; + + nativeBuildInputs = with pkgs; [ + just + ]; + + inputsFrom = [ tidyfox ]; +} diff --git a/src/lib.cpp b/src/lib.cpp new file mode 100644 index 0000000..bba5432 --- /dev/null +++ b/src/lib.cpp @@ -0,0 +1,16 @@ +#include + +#include +#include + +namespace clang::tidy::tidyfox { + +class TidyfoxClangTidyModule: public ClangTidyModule { +public: + void addCheckFactories([[maybe_unused]] ClangTidyCheckFactories& check_factories) override {} +}; + +static const ClangTidyModuleRegistry::Add + X("tidyfox", "outfoxxed's lint collection"); + +} // namespace clang::tidy::tidyfox